summaryrefslogtreecommitdiffstats
path: root/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java')
-rw-r--r--infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java b/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java
index a87459560..8a3ee62f6 100644
--- a/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java
+++ b/infra/northbound/restconf/src/main/java/io/fd/honeycomb/northbound/restconf/JettyServerProvider.java
@@ -27,10 +27,21 @@ import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.util.security.Password;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.servlet.ServletContainer;
+import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
+import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
+import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
+import org.opendaylight.netconf.sal.rest.impl.RestconfApplication;
+import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
+import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
+import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
final class JettyServerProvider extends ProviderTrait<Server> {
@@ -41,6 +52,7 @@ final class JettyServerProvider extends ProviderTrait<Server> {
"application/yang.data+xml",
"application/json",
"application/yang.data+json"};
+ public static final String RESTCONF_APP_NAME = "JAXRSRestconf";
@Inject
private RestconfConfiguration cfg;
@@ -48,6 +60,15 @@ final class JettyServerProvider extends ProviderTrait<Server> {
@Inject
private CredentialsConfiguration credentialsCfg;
+ @Inject
+ private RestconfApplication restconfApplication;
+
+ @Inject
+ private RestconfImpl restconf;
+
+ @Inject
+ private ControllerContext controllerContext;
+
@Override
protected Server create() {
Server server = new Server(new QueuedThreadPool(cfg.restPoolMaxSize.get(), cfg.restPoolMinSize.get()));
@@ -62,7 +83,26 @@ final class JettyServerProvider extends ProviderTrait<Server> {
final URL resource = getClass().getResource("/");
WebAppContext webapp = new WebAppContext(resource.getPath(), cfg.restconfRootPath.get());
+ // Create Restconf application implementation for server
+ ResourceConfig resourceConfig = new ResourceConfig();
+ resourceConfig.setApplicationName(RESTCONF_APP_NAME);
+ resourceConfig = resourceConfig.registerInstances(restconf, new NormalizedNodeJsonBodyWriter(),
+ new NormalizedNodeXmlBodyWriter(), new XmlNormalizedNodeBodyReader(controllerContext),
+ new JsonNormalizedNodeBodyReader(controllerContext),
+ new RestconfDocumentedExceptionMapper(controllerContext));
+ // register Restconf Application classes
+ resourceConfig.registerClasses(restconfApplication.getClasses());
+
+ // Create Servlet container which holds configured application
+ ServletContainer servlet = new ServletContainer(resourceConfig);
+ ServletHolder servletHolder = new ServletHolder(RESTCONF_APP_NAME, servlet);
+ // init on startup
+ servletHolder.setInitOrder(1);
+ // set service handler
server.setHandler(getGzip(service, webapp));
+
+ //add servlet with "/*" mapping
+ webapp.addServlet(servletHolder, "/*");
return server;
}