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