Skip to content

Package: RestApisApplication

RestApisApplication

nameinstructionbranchcomplexitylinemethod
RestApisApplication()
M: 72 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 15 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2020 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: * Contributors:
10: * Eurotech - initial API and implementation
11: *******************************************************************************/
12: package org.eclipse.kapua.app.api.web;
13:
14: import java.util.HashMap;
15:
16: import javax.ws.rs.core.MediaType;
17: import javax.xml.bind.JAXBException;
18:
19: import org.eclipse.kapua.app.api.core.KapuaSerializableBodyWriter;
20: import org.eclipse.kapua.app.api.core.ListBodyWriter;
21: import org.eclipse.kapua.app.api.core.MoxyJsonConfigContextResolver;
22: import org.eclipse.kapua.commons.util.xml.XmlUtil;
23:
24: import org.glassfish.hk2.api.ServiceLocator;
25: import org.glassfish.jersey.server.ResourceConfig;
26: import org.glassfish.jersey.server.ServerProperties;
27: import org.glassfish.jersey.server.filter.UriConnegFilter;
28: import org.glassfish.jersey.server.spi.Container;
29: import org.glassfish.jersey.server.spi.ContainerLifecycleListener;
30:
31: public class RestApisApplication extends ResourceConfig {
32:
33: public RestApisApplication() throws JAXBException {
34: packages("org.eclipse.kapua.app.api",
35: "org.eclipse.kapua.service");
36:
37: // Bind media type to resource extension
38: HashMap<String, MediaType> mappedMediaTypes = new HashMap<>();
39: mappedMediaTypes.put("xml", MediaType.APPLICATION_XML_TYPE);
40: mappedMediaTypes.put("json", MediaType.APPLICATION_JSON_TYPE);
41:
42: property(ServerProperties.MEDIA_TYPE_MAPPINGS, mappedMediaTypes);
43: property(ServerProperties.WADL_FEATURE_DISABLE, true);
44: register(UriConnegFilter.class);
45: register(JaxbContextResolver.class);
46: register(RestApiJAXBContextProvider.class);
47: register(KapuaSerializableBodyWriter.class);
48: register(ListBodyWriter.class);
49: register(MoxyJsonConfigContextResolver.class);
50:
51: register(new ContainerLifecycleListener() {
52:
53: @Override
54: public void onStartup(Container container) {
55: ServiceLocator serviceLocator = container.getApplicationHandler().getServiceLocator();
56:
57: RestApiJAXBContextProvider provider = serviceLocator.createAndInitialize(RestApiJAXBContextProvider.class);
58: XmlUtil.setContextProvider(provider);
59: }
60:
61: @Override
62: /**
63: * Nothing to do
64: */
65: public void onReload(Container container) {
66: }
67:
68: @Override
69: /**
70: * Nothing to do
71: */
72: public void onShutdown(Container container) {
73: }
74: });
75: }
76:
77: }