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>
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.
@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
--- /dev/null
+/*
+ * 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;
+ }
+}
--- /dev/null
+/*
+ * 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();
+}
<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>