/[projects]/miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/MyApplication.java
ViewVC logotype

Contents of /miscJava/Test4Simple/src/main/java/dk/thoerup/webservice/MyApplication.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2521 - (show annotations) (download)
Wed Apr 29 09:32:47 2015 UTC (9 years ago) by torben
File size: 2655 byte(s)
Add Person REST service

1 package dk.thoerup.webservice;
2
3 import java.util.Collections;
4 import java.util.HashMap;
5 import java.util.Map;
6 import java.util.Set;
7
8 import javax.ws.rs.ApplicationPath;
9 import javax.ws.rs.core.Application;
10
11 @ApplicationPath("rest")
12 public class MyApplication extends Application {
13
14 @Override
15 public Set<Class<?>> getClasses() {
16
17 Set<Class<?>> resources = new java.util.HashSet<>();
18
19 System.out.println("REST configuration starting: getClasses()");
20
21 //features
22 //this will register MOXy JSON providers
23 resources.add(org.glassfish.jersey.moxy.json.MoxyJsonFeature.class);
24 //we could also use this
25 resources.add(org.glassfish.jersey.moxy.xml.MoxyXmlFeature.class);
26
27 //instead let's do it manually:
28 resources.add(JsonMoxyConfigurationContextResolver.class);
29
30
31 resources.add(ExceptionListener.class);
32
33
34 resources.add(RestSimpleJerseyTest.class);
35 resources.add(PersonService.class);
36
37
38
39 //==> we could also choose packages, see below getProperties()
40
41 System.out.println("REST configuration ended successfully.");
42
43 return resources;
44 }
45
46 @Override
47 public Set<Object> getSingletons() {
48 return Collections.emptySet();
49 }
50
51 @Override
52 public Map<String, Object> getProperties() {
53 System.out.println("Application->properties");
54 Map<String, Object> properties = new HashMap<>();
55
56 //in Jersey WADL generation is enabled by default, but we don't
57 //want to expose too much information about our apis.
58 //therefore we want to disable wadl (http://localhost:8080/service/application.wadl should return http 404)
59 //see https://jersey.java.net/nonav/documentation/latest/user-guide.html#d0e9020 for details
60 properties.put("jersey.config.server.wadl.disableWadl", true);
61
62 //we could also use something like this instead of adding each of our resources
63 //explicitely in getClasses():
64 //properties.put("jersey.config.server.provider.packages", "com.nabisoft.tutorials.mavenstruts.service");
65
66
67 return properties;
68 }
69 }
70
71 /*public class MyApplication extends ResourceConfig {
72 public MyApplication() {
73 System.out.println("Loading MyApplication class");
74
75 //register(ApplicationEventListener.class);
76 packages("dk.thoerup.webservice");
77 //register(RestSimpleJerseyTest.class);
78 register(JsonMoxyConfigurationContextResolver.class);
79 }
80
81
82 }*/

  ViewVC Help
Powered by ViewVC 1.1.20