--- miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/MyApplication.java 2015/04/27 15:41:43 2516 +++ miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/MyApplication.java 2015/04/28 05:54:46 2517 @@ -1,14 +1,78 @@ package dk.thoerup.webservice; -import javax.ws.rs.*; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; -import org.glassfish.jersey.server.*; +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; -@ApplicationPath("resources") -public class MyApplication extends ResourceConfig { +@ApplicationPath("rest") +public class MyApplication extends Application { + + @Override + public Set> getClasses() { + + Set> resources = new java.util.HashSet<>(); + + System.out.println("REST configuration starting: getClasses()"); + + //features + //this will register MOXy JSON providers + resources.add(org.glassfish.jersey.moxy.json.MoxyJsonFeature.class); + //we could also use this + resources.add(org.glassfish.jersey.moxy.xml.MoxyXmlFeature.class); + + //instead let's do it manually: + resources.add(JsonMoxyConfigurationContextResolver.class); + + resources.add(ExceptionListener.class); + + + resources.add(RestSimpleJerseyTest.class); + //==> we could also choose packages, see below getProperties() + + System.out.println("REST configuration ended successfully."); + + return resources; + } + + @Override + public Set getSingletons() { + return Collections.emptySet(); + } + + @Override + public Map getProperties() { + System.out.println("Application->properties"); + Map properties = new HashMap<>(); + + //in Jersey WADL generation is enabled by default, but we don't + //want to expose too much information about our apis. + //therefore we want to disable wadl (http://localhost:8080/service/application.wadl should return http 404) + //see https://jersey.java.net/nonav/documentation/latest/user-guide.html#d0e9020 for details + properties.put("jersey.config.server.wadl.disableWadl", true); + + //we could also use something like this instead of adding each of our resources + //explicitely in getClasses(): + //properties.put("jersey.config.server.provider.packages", "com.nabisoft.tutorials.mavenstruts.service"); + + + return properties; + } +} + +/*public class MyApplication extends ResourceConfig { public MyApplication() { System.out.println("Loading MyApplication class"); + + //register(ApplicationEventListener.class); packages("dk.thoerup.webservice"); + //register(RestSimpleJerseyTest.class); + register(JsonMoxyConfigurationContextResolver.class); } -} + + +}*/