<configuration>
<instructions>
<Bundle-Name>YangLib</Bundle-Name>
- <Import-Package>
- com.sun.jersey.spi.container.servlet,
- org.eclipse.jetty.servlets,
- !javax.annotation,
- javax.ws.rs.*;version="[1.1.0,2.0.0)",
- *
- </Import-Package>
- <Web-ContextPath>/yanglib</Web-ContextPath>
</instructions>
</configuration>
</plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-model-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.aaa.web</groupId>
+ <artifactId>web-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.jersey</groupId>
+ <artifactId>jersey-servlet</artifactId>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
+++ /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.yanglib.api;
-
-import org.opendaylight.yanglib.impl.YangLibServiceImpl;
-import org.osgi.framework.BundleContext;
-
-/**
- * Interface for register YangLibRestApp service via {@link BundleContext}.
- */
-public interface YangLibRestAppService {
-
- /**
- * Get {@link YangLibServiceImpl} via service.
- * @return YangLibServiceImpl
- */
- YangLibServiceImpl getYangLibService();
-}
--- /dev/null
+/*
+ * Copyright (c) 2018 Inocybe Technologies 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.yanglib.impl;
+
+import javax.servlet.ServletException;
+import javax.ws.rs.core.Application;
+import org.opendaylight.aaa.web.ServletDetails;
+import org.opendaylight.aaa.web.WebContext;
+import org.opendaylight.aaa.web.WebContextBuilder;
+import org.opendaylight.aaa.web.WebContextRegistration;
+import org.opendaylight.aaa.web.WebContextSecurer;
+import org.opendaylight.aaa.web.WebServer;
+
+/**
+ * Initializes the wep app.
+ *
+ * @author Thomas Pantelis
+ */
+public class WebInitializer {
+ private final WebContextRegistration registration;
+
+ public WebInitializer(WebServer webServer, WebContextSecurer webContextSecurer, Application webApp)
+ throws ServletException {
+ WebContextBuilder webContextBuilder = WebContext.builder().contextPath("yanglib").supportsSessions(true)
+ .addServlet(ServletDetails.builder().servlet(
+ new com.sun.jersey.spi.container.servlet.ServletContainer(webApp))
+ .addUrlPattern("/*").build());
+
+ webContextSecurer.requireAuthentication(webContextBuilder, "/*");
+
+ registration = webServer.registerWebContext(webContextBuilder.build());
+ }
+
+ public void close() {
+ registration.close();
+ }
+}
private final DataBroker dataBroker;
private final YanglibConfig yanglibConfig;
+ private final SharedSchemaRepository schemaRepository;
private SchemaListenerRegistration schemaListenerRegistration;
- private SharedSchemaRepository schemaRepository;
- public YangLibProvider(final YanglibConfig yanglibConfig, final DataBroker dataBroker) {
+ public YangLibProvider(final YanglibConfig yanglibConfig, final DataBroker dataBroker,
+ final SharedSchemaRepository schemaRepository) {
this.yanglibConfig = Preconditions.checkNotNull(yanglibConfig);
this.dataBroker = Preconditions.checkNotNull(dataBroker);
+ this.schemaRepository = Preconditions.checkNotNull(schemaRepository);
}
@Override
public void close() {
- YangLibServiceImpl.setSchemaRepository(null);
if (schemaListenerRegistration != null) {
schemaListenerRegistration.close();
}
Preconditions.checkArgument(cacheFolderFile.isDirectory(), "cache-folder %s is not a directory",
cacheFolderFile);
- schemaRepository = new SharedSchemaRepository("yang-library");
final FilesystemSchemaSourceCache<YangTextSchemaSource> cache =
new FilesystemSchemaSourceCache<>(schemaRepository, YangTextSchemaSource.class, cacheFolderFile);
schemaRepository.registerSchemaSourceListener(cache);
schemaListenerRegistration = schemaRepository.registerSchemaSourceListener(this);
- YangLibServiceImpl.setSchemaRepository(schemaRepository);
LOG.info("Started yang library with sources from {}", cacheFolderFile);
}
import java.util.Collections;
import java.util.Set;
import javax.ws.rs.core.Application;
-import org.opendaylight.yanglib.api.YangLibRestAppService;
+import org.opendaylight.yanglib.api.YangLibService;
-public class YangLibRestApp extends Application implements YangLibRestAppService {
- private final YangLibServiceImpl yangLibService = new YangLibServiceImpl();
+public class YangLibRestApp extends Application {
+ private final YangLibService yangLibService;
- @Override
- public Set<Object> getSingletons() {
- return Collections.<Object>singleton(this.yangLibService);
+ public YangLibRestApp(YangLibService yangLibService) {
+ this.yangLibService = yangLibService;
}
@Override
- public YangLibServiceImpl getYangLibService() {
- return yangLibService;
+ public Set<Object> getSingletons() {
+ return Collections.<Object>singleton(this.yangLibService);
}
}
public class YangLibServiceImpl implements YangLibService {
private static final Logger LOG = LoggerFactory.getLogger(YangLibServiceImpl.class);
- private static volatile SchemaRepository schemaRepository;
+ private final SchemaRepository schemaRepository;
- public YangLibServiceImpl() {
-
- }
-
- public static void setSchemaRepository(final SchemaRepository schemaRepository) {
- LOG.debug("Setting schema repository {}", schemaRepository);
- YangLibServiceImpl.schemaRepository = schemaRepository;
+ public YangLibServiceImpl(final SchemaRepository schemaRepository) {
+ this.schemaRepository = schemaRepository;
}
@Override
+++ /dev/null
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- version="3.0">
-
- <servlet>
- <servlet-name>JAXRSYanglib</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.yanglib.impl.YangLibRestApp</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>JAXRSYanglib</servlet-name>
- <url-pattern>/*</url-pattern>
- </servlet-mapping>
-</web-app>
binding-class="org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.yanglib.impl.rev141210.YanglibConfig"/>
<reference id="dataBroker" interface="org.opendaylight.controller.md.sal.binding.api.DataBroker"/>
+ <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer"/>
+ <reference id="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer"/>
+
+ <bean id="schemaRepository" class="org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository">
+ <argument value="yang-library"/>
+ </bean>
+
+ <bean id="yangLibService" class="org.opendaylight.yanglib.impl.YangLibServiceImpl">
+ <argument ref="schemaRepository"/>
+ </bean>
+
+ <bean id="yangLibRestApp" class="org.opendaylight.yanglib.impl.YangLibRestApp">
+ <argument ref="yangLibService"/>
+ </bean>
<bean id="yangLibProvider" class="org.opendaylight.yanglib.impl.YangLibProvider"
init-method="init" destroy-method="close">
<argument ref="yanglibConfig"/>
<argument ref="dataBroker"/>
+ <argument ref="schemaRepository"/>
</bean>
+ <bean id="webInitializer" class="org.opendaylight.yanglib.impl.WebInitializer"
+ destroy-method="close">
+ <argument ref="webServer"/>
+ <argument ref="webContextSecurer"/>
+ <argument ref="yangLibRestApp"/>
+ </bean>
</blueprint>
import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
import org.opendaylight.yangtools.yang.model.repo.api.YinSchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
+import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
import org.opendaylight.yangtools.yang.parser.rfc7950.repo.ASTSchemaSource;
public class YangLibProviderTest {
final YanglibConfig yanglibConfig = new YanglibConfigBuilder().setBindingAddr("www.fake.com")
.setBindingPort(300L).setCacheFolder(CACHE_DIR.getAbsolutePath()).build();
- yangLibProvider = new YangLibProvider(yanglibConfig, dataBroker);
+ yangLibProvider = new YangLibProvider(yanglibConfig, dataBroker, new SharedSchemaRepository("yang-library"));
}
@Test
+++ /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.yanglib.impl;
-
-import static junit.framework.TestCase.assertTrue;
-
-import java.util.Set;
-import org.junit.Test;
-
-public class YangLibRestAppTest {
-
- @Test
- public void testYangLibRestApp() {
- final YangLibRestApp yangLibRestApp = new YangLibRestApp();
- final Set singleton = yangLibRestApp.getSingletons();
-
- assertTrue(singleton.contains(yangLibRestApp.getYangLibService()));
- }
-}
public void testSchema() throws SchemaSourceException {
final SchemaRepository schemaRepository = mock(SchemaRepository.class);
- final YangLibServiceImpl yangLibService = new YangLibServiceImpl();
- yangLibService.setSchemaRepository(schemaRepository);
+ final YangLibServiceImpl yangLibService = new YangLibServiceImpl(schemaRepository);
final SourceIdentifier sourceIdentifier = RevisionSourceIdentifier.create("name", Revision.of("2016-01-01"));