X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fcommons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnorthbound%2Fcommons%2FNorthboundApplication.java;h=87f51364ba1c5b59f3b9326a518a07c99c72129c;hp=5b8219126b8abbb7c82124b22f502505c2791e8c;hb=31c83799d67d0bf4012aefedaba5356ebfaad8ab;hpb=8f430e4ce6dc900607a3fc74c546a2a5bb63b6fa diff --git a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java index 5b8219126b..87f51364ba 100644 --- a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java +++ b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java @@ -19,9 +19,8 @@ import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.annotation.XmlRootElement; -import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider; -import org.codehaus.jackson.map.DeserializationConfig; import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService; +import org.opendaylight.controller.northbound.commons.query.QueryContextProvider; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleReference; @@ -31,15 +30,37 @@ import org.osgi.framework.ServiceReference; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; + /** * Instance of javax.ws.rs.core.Application used to return the classes * that will be instantiated for JAXRS processing. This hooks onto the * bundle scanner service to provide JAXB classes to JAX-RS for prorcessing. */ -@SuppressWarnings("unchecked") public class NorthboundApplication extends Application { public static final String JAXRS_RESOURCES_MANIFEST_NAME = "Jaxrs-Resources"; + public static final String JAXRS_EXCLUDES_MANIFEST_NAME = "Jaxrs-Exclude-Types"; private static final Logger LOGGER = LoggerFactory.getLogger(NorthboundApplication.class); + private final Set _singletons; + + public NorthboundApplication() { + _singletons = new HashSet(); + _singletons.add(new ContextResolver() { + JAXBContext jaxbContext; + @Override + public synchronized JAXBContext getContext(Class type) { + if (jaxbContext == null) { + jaxbContext = newJAXBContext(); + } + return jaxbContext; + } + + } ); + _singletons.add(getJsonProvider()); + _singletons.add(new JacksonJsonProcessingExceptionMapper()); + _singletons.add(new QueryContextProvider()); + } //////////////////////////////////////////////////////////////// // Application overrides @@ -47,17 +68,7 @@ public class NorthboundApplication extends Application { @Override public Set getSingletons() { - Set singletons = new HashSet(); - singletons.add(new ContextResolver() { - @Override - public JAXBContext getContext(Class type) { - return newJAXBContext(); - } - - } ); - singletons.add(getJsonProvider()); - singletons.add(new JacksonJsonProcessingExceptionMapper()); - return singletons; + return _singletons; } @Override @@ -69,7 +80,7 @@ public class NorthboundApplication extends Application { private static final JacksonJaxbJsonProvider getJsonProvider() { JacksonJaxbJsonProvider jsonProvider = new JacksonJaxbJsonProvider(); - jsonProvider.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, + jsonProvider.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); return jsonProvider; } @@ -89,7 +100,7 @@ public class NorthboundApplication extends Application { } private static final IBundleScanService lookupBundleScanner(BundleContext ctx) { - ServiceReference svcRef = ctx.getServiceReference(IBundleScanService.class); + ServiceReference svcRef = ctx.getServiceReference(IBundleScanService.class); if (svcRef == null) { throw new ServiceException("Unable to lookup IBundleScanService"); } @@ -102,6 +113,7 @@ public class NorthboundApplication extends Application { try { List> cls = svc.getAnnotatedClasses(ctx, new String[] { XmlRootElement.class.getPackage().getName() }, + parseManifestEntry(ctx, JAXRS_EXCLUDES_MANIFEST_NAME), true); return JAXBContext.newInstance(cls.toArray(new Class[cls.size()])); } catch (JAXBException je) { @@ -118,29 +130,22 @@ public class NorthboundApplication extends Application { try { IBundleScanService svc = lookupBundleScanner(ctx); result.addAll(svc.getAnnotatedClasses(ctx, - new String[] { javax.ws.rs.Path.class.getName() }, false)); + new String[] { javax.ws.rs.Path.class.getName() }, + null, false)); } catch (ServiceException se) { recordException = se; LOGGER.debug("Error finding JAXRS resource annotated classes in " + "bundle: {} error: {}.", bundleName, se.getMessage()); // the bundle scan service cannot be lookedup. Lets attempt to // lookup the resources from the bundle manifest header - Dictionary headers = ctx.getBundle().getHeaders(); - String header = headers.get(JAXRS_RESOURCES_MANIFEST_NAME); - if (header != null) { - for (String s : header.split(",")) { - s = s.trim(); - if (s.length() > 0) { - try { - result.add(ctx.getBundle().loadClass(s)); - } catch (ClassNotFoundException cnfe) { - LOGGER.error("Cannot load class: {} in bundle: {} " + - "defined as MANIFEST JAX-RS resource", s, bundleName, cnfe); - } - } + for (String c : parseManifestEntry(ctx, JAXRS_RESOURCES_MANIFEST_NAME)) { + try { + result.add(ctx.getBundle().loadClass(c)); + } catch (ClassNotFoundException cnfe) { + LOGGER.error("Cannot load class: {} in bundle: {} " + + "defined as MANIFEST JAX-RS resource", c, bundleName, cnfe); } } - } if (result.size() == 0) { @@ -154,4 +159,19 @@ public class NorthboundApplication extends Application { return result; } + private final Set parseManifestEntry(BundleContext ctx, String name) { + Set result = new HashSet(); + Dictionary headers = ctx.getBundle().getHeaders(); + String header = headers.get(name); + if (header != null) { + for (String s : header.split(",")) { + s = s.trim(); + if (s.length() > 0) { + result.add(s); + } + } + } + return result; + } + }