1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest.tools; |
35 |
|
|
36 |
|
import info.magnolia.cms.util.CustomServletConfig; |
37 |
|
import info.magnolia.event.EventBus; |
38 |
|
import info.magnolia.event.SystemEventBus; |
39 |
|
import info.magnolia.rest.RestDispatcherServlet; |
40 |
|
import info.magnolia.rest.RestIntegrationModule; |
41 |
|
import info.magnolia.rest.registry.ConfiguredEndpointDefinition; |
42 |
|
import info.magnolia.rest.registry.EndpointDefinitionRegistry; |
43 |
|
import info.magnolia.rest.registry.EndpointDefinitionRegistryEvent; |
44 |
|
|
45 |
|
import java.util.HashMap; |
46 |
|
|
47 |
|
import javax.inject.Inject; |
48 |
|
import javax.inject.Named; |
49 |
|
import javax.servlet.ServletConfig; |
50 |
|
import javax.servlet.ServletException; |
51 |
|
|
52 |
|
import com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig; |
53 |
|
import com.wordnik.swagger.jaxrs.listing.ApiListingResource; |
54 |
|
import com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@link |
60 |
|
@link |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 7 |
Complexity Density: 0.32 |
|
62 |
|
public class SwaggerRestDispatcherServlet extends RestDispatcherServlet { |
63 |
|
|
64 |
|
private final static String PARAMETER_API_VERSION = "api.version"; |
65 |
|
private final static String PARAMETER_API_BASEPATH = "swagger.api.basepath"; |
66 |
|
|
67 |
|
private final RestToolsModule restToolsModule; |
68 |
|
private ApiListingResource apiListingResource; |
69 |
|
private DefaultJaxrsConfig config; |
70 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
71 |
0 |
@Inject... |
72 |
|
public SwaggerRestDispatcherServlet(final RestIntegrationModule restIntegrationModule, final EndpointDefinitionRegistry endpointDefinitionRegistry, @Named(SystemEventBus.NAME) EventBus systemEventBus, final RestToolsModule restToolsModule) { |
73 |
0 |
super(restIntegrationModule, endpointDefinitionRegistry, systemEventBus); |
74 |
0 |
this.restToolsModule = restToolsModule; |
75 |
|
} |
76 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
77 |
0 |
@Override... |
78 |
|
public void init(ServletConfig servletConfig) throws ServletException { |
79 |
0 |
super.init(servletConfig); |
80 |
|
|
81 |
|
|
82 |
0 |
ConfiguredEndpointDefinition endpointDefinition = new ConfiguredEndpointDefinition(); |
83 |
0 |
endpointDefinition.setImplementationClass(ApiListingResourceJSON.class); |
84 |
0 |
endpointDefinition.setName("api-listing-resource-json"); |
85 |
0 |
this.apiListingResource = (ApiListingResourceJSON) super.registerEndpoint(endpointDefinition); |
86 |
|
|
87 |
0 |
config = new DefaultJaxrsConfig(); |
88 |
0 |
HashMap<String, String> initParameters = new HashMap<String, String>(); |
89 |
0 |
initParameters.put(PARAMETER_API_VERSION, restToolsModule.getApiVersion()); |
90 |
0 |
initParameters.put(PARAMETER_API_BASEPATH, restToolsModule.getApiBasepath()); |
91 |
0 |
config.init(new CustomServletConfig("DefaultJaxrsConfig", super.getServletContext(), initParameters)); |
92 |
|
} |
93 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
94 |
0 |
@Override... |
95 |
|
public void destroy() { |
96 |
0 |
unregisterEndpoint("api-listing-resource-json"); |
97 |
0 |
super.destroy(); |
98 |
0 |
if (config != null) { |
99 |
0 |
config.destroy(); |
100 |
|
} |
101 |
|
} |
102 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
103 |
0 |
@Override... |
104 |
|
public void onEndpointRegistered(EndpointDefinitionRegistryEvent event) { |
105 |
0 |
super.onEndpointRegistered(event); |
106 |
0 |
apiListingResource.invalidateCache(); |
107 |
|
} |
108 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
109 |
0 |
@Override... |
110 |
|
public void onEndpointReregistered(EndpointDefinitionRegistryEvent event) { |
111 |
0 |
super.onEndpointReregistered(event); |
112 |
0 |
apiListingResource.invalidateCache(); |
113 |
|
} |
114 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
115 |
0 |
@Override... |
116 |
|
public void onEndpointUnregistered(EndpointDefinitionRegistryEvent event) { |
117 |
0 |
super.onEndpointUnregistered(event); |
118 |
0 |
apiListingResource.invalidateCache(); |
119 |
|
} |
120 |
|
} |