Bug 5526 - Added new servlet to the web.xml for new restconf 40/37240/35
authorJakub Toth <jatoth@cisco.com>
Sat, 7 May 2016 22:31:20 +0000 (18:31 -0400)
committerJakub Toth <jatoth@cisco.com>
Sat, 7 May 2016 22:31:32 +0000 (18:31 -0400)
implementation

  * application for new servlet
  * register SchemaContextListener via SchemaContextHandler

Change-Id: Ifb42aed73f7524a07174c0c5e966ca44bcb228d8
Signed-off-by: Jakub Toth <jatoth@cisco.com>
restconf/sal-rest-connector/pom.xml
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/resources/WEB-INF/web.xml

index 86c8a3dd6723c799ce949f3cf89e8ab90f135a99..15ee20b310ab8c1b4e75c19546606019035a41fa 100644 (file)
               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
             </Private-Package>
             <Import-Package>
index 7b2a3b65ad576bad346593c72378429a376d58c8..5cca1deca7d558fcd2b2c24e3ce58488445dc5dc 100644 (file)
@@ -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> T getObjectFromBundleContext(final Class<T> 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 (file)
index 0000000..50f66f2
--- /dev/null
@@ -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<Class<?>> getClasses() {
+        return ImmutableSet.<Class<?>> builder().add(NormalizedNodeJsonBodyWriter.class)
+                .add(NormalizedNodeXmlBodyWriter.class).add(SchemaExportContentYinBodyWriter.class)
+                .add(SchemaExportContentYangBodyWriter.class)
+                .build();
+    }
+
+    @Override
+    public Set<Object> getSingletons() {
+        final Set<Object> 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 (file)
index 0000000..8c15bec
--- /dev/null
@@ -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();
+}
index 6b801d7321307adc5cf70ea2f62c662933dc17a4..6b4193ef548d491eccef5c62476202dda8e9c798 100644 (file)
             <param-name>javax.ws.rs.Application</param-name>
             <param-value>org.opendaylight.netconf.sal.rest.impl.RestconfApplication</param-value>
         </init-param>
+        <load-on-startup>0</load-on-startup>
+    </servlet>
+
+    <servlet>
+        <servlet-name>Restconf</servlet-name>
+        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+        <init-param>
+            <param-name>javax.ws.rs.Application</param-name>
+            <param-value>org.opendaylight.restconf.rest.RestconfApplication</param-value>
+        </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet>
 
         <url-pattern>/*</url-pattern>
     </servlet-mapping>
 
+    <servlet-mapping>
+        <servlet-name>Restconf</servlet-name>
+        <url-pattern>/11/*</url-pattern>
+    </servlet-mapping>
+
     <filter>
         <filter-name>GzipFilter</filter-name>
         <filter-class>org.eclipse.jetty.servlets.GzipFilter</filter-class>