Skip to contentPackage: RestApisApplication$1
RestApisApplication$1
Coverage
1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.app.api.web;
14:
15: import org.eclipse.kapua.app.api.core.KapuaSerializableBodyWriter;
16: import org.eclipse.kapua.app.api.core.ListBodyWriter;
17: import org.eclipse.kapua.app.api.core.MoxyJsonConfigContextResolver;
18: import org.eclipse.kapua.commons.util.xml.XmlUtil;
19: import org.glassfish.hk2.api.ServiceLocator;
20: import org.glassfish.jersey.moxy.json.MoxyJsonFeature;
21: import org.glassfish.jersey.server.ResourceConfig;
22: import org.glassfish.jersey.server.ServerProperties;
23: import org.glassfish.jersey.server.filter.UriConnegFilter;
24: import org.glassfish.jersey.server.spi.Container;
25: import org.glassfish.jersey.server.spi.ContainerLifecycleListener;
26:
27: import javax.ws.rs.core.MediaType;
28: import javax.xml.bind.JAXBException;
29: import java.util.HashMap;
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:
45: // Manually adding MOXyJSONFeature
46: register(MoxyJsonFeature.class);
47: register(MoxyJsonConfigContextResolver.class);
48: register(UriConnegFilter.class);
49: register(JaxbContextResolver.class);
50: register(RestApiJAXBContextProvider.class);
51: register(KapuaSerializableBodyWriter.class);
52: register(ListBodyWriter.class);
53:
54: register(new ContainerLifecycleListener() {
55:
56: @Override
57: public void onStartup(Container container) {
58: ServiceLocator serviceLocator = container.getApplicationHandler().getInjectionManager().getInstance(ServiceLocator.class);
59:
60: RestApiJAXBContextProvider provider = serviceLocator.createAndInitialize(RestApiJAXBContextProvider.class);
61: XmlUtil.setContextProvider(provider);
62: }
63:
64: @Override
65: /**
66: * Nothing to do
67: */
68: public void onReload(Container container) {
69: }
70:
71: @Override
72: /**
73: * Nothing to do
74: */
75: public void onShutdown(Container container) {
76: }
77: });
78: }
79:
80: }