From: Jakub Toth Date: Sat, 7 May 2016 22:31:20 +0000 (-0400) Subject: Bug 5526 - Added new servlet to the web.xml for new restconf X-Git-Tag: release/boron~105^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=8aee58a098b3e9b6bd7d0b1aa40a81454f181db9;p=netconf.git Bug 5526 - Added new servlet to the web.xml for new restconf implementation * application for new servlet * register SchemaContextListener via SchemaContextHandler Change-Id: Ifb42aed73f7524a07174c0c5e966ca44bcb228d8 Signed-off-by: Jakub Toth --- diff --git a/restconf/sal-rest-connector/pom.xml b/restconf/sal-rest-connector/pom.xml index 86c8a3dd67..15ee20b310 100644 --- a/restconf/sal-rest-connector/pom.xml +++ b/restconf/sal-rest-connector/pom.xml @@ -186,6 +186,7 @@ org.opendaylight.netconf.sal.restconf.impl, org.opendaylight.netconf.md.sal.rest.common.*, org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.rest.connector.rev140724.*, + org.opendaylight.restconf.*, javax.annotation diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java index 7b2a3b65ad..5cca1deca7 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java @@ -16,6 +16,9 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.netconf.sal.rest.api.RestConnector; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; /** * Provider for restconf draft11. @@ -28,6 +31,16 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose @Override public void onSessionInitiated(final ProviderSession session) { final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class)); + final RestconfApplication restApp = getObjectFromBundleContext(RestconfApplication.class, + RestconfApplicationService.class.getName()); + Preconditions.checkNotNull(restApp, "RestconfApplication service doesn't exist."); + this.listenerRegistration = schemaService.registerSchemaContextListener(restApp.getSchemaContextHandler()); + } + + private T getObjectFromBundleContext(final Class type, final String serviceRefName) { + final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext(); + final ServiceReference serviceReference = bundleContext.getServiceReference(serviceRefName); + return (T) bundleContext.getService(serviceReference); } @Override diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java new file mode 100644 index 0000000000..50f66f2777 --- /dev/null +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.rest; + +import com.google.common.collect.ImmutableSet; +import java.util.HashSet; +import java.util.Set; +import javax.ws.rs.core.Application; +import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYangBodyWriter; +import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter; +import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter; +import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter; +import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler; +import org.opendaylight.restconf.rest.impl.schema.context.SchemaContextHandlerImpl; +import org.opendaylight.restconf.rest.impl.services.Draft11ServicesWrapperImpl; +import org.osgi.framework.FrameworkUtil; + +public class RestconfApplication extends Application implements RestconfApplicationService { + + private final SchemaContextHandler schemaContextHandler; + + public RestconfApplication() { + this.schemaContextHandler = new SchemaContextHandlerImpl(); + FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(RestconfApplicationService.class.getName(), + this, null); + } + + @Override + public Set> getClasses() { + return ImmutableSet.> builder().add(NormalizedNodeJsonBodyWriter.class) + .add(NormalizedNodeXmlBodyWriter.class).add(SchemaExportContentYinBodyWriter.class) + .add(SchemaExportContentYangBodyWriter.class) + .build(); + } + + @Override + public Set getSingletons() { + final Set singletons = new HashSet<>(); + singletons.add(this.schemaContextHandler); + singletons.add(new Draft11ServicesWrapperImpl(this.schemaContextHandler)); + return singletons; + } + + @Override + public SchemaContextHandler getSchemaContextHandler() { + return this.schemaContextHandler; + } +} diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java new file mode 100644 index 0000000000..8c15bec7f8 --- /dev/null +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.restconf.rest; + +import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler; +import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; +import org.osgi.framework.BundleContext; + +/** + * Interface for register RestconfApplication service via {@link BundleContext}. + * + */ +public interface RestconfApplicationService { + + /** + * Get {@link SchemaContextHandler} via service. Actually use by + * {@link RestConnectorProvider} to register {@link SchemaContextListener} + * of {@link SchemaContextHandler}. + * + * @return {@link SchemaContextHandler} + */ + SchemaContextHandler getSchemaContextHandler(); +} diff --git a/restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml b/restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml index 6b801d7321..6b4193ef54 100644 --- a/restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml +++ b/restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml @@ -10,6 +10,16 @@ javax.ws.rs.Application org.opendaylight.netconf.sal.rest.impl.RestconfApplication + 0 + + + + Restconf + com.sun.jersey.spi.container.servlet.ServletContainer + + javax.ws.rs.Application + org.opendaylight.restconf.rest.RestconfApplication + 1 @@ -48,6 +58,11 @@ /* + + Restconf + /11/* + + GzipFilter org.eclipse.jetty.servlets.GzipFilter