2 * Copyright (c) 2018 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.openapi.jaxrs;
10 import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Inject;
14 import javax.inject.Singleton;
15 import javax.servlet.ServletException;
16 import javax.ws.rs.core.Application;
17 import org.opendaylight.aaa.web.ResourceDetails;
18 import org.opendaylight.aaa.web.ServletDetails;
19 import org.opendaylight.aaa.web.WebContext;
20 import org.opendaylight.aaa.web.WebContextSecurer;
21 import org.opendaylight.aaa.web.WebServer;
22 import org.opendaylight.aaa.web.servlet.ServletSupport;
23 import org.opendaylight.restconf.openapi.api.OpenApiService;
24 import org.opendaylight.yangtools.concepts.Registration;
25 import org.osgi.service.component.annotations.Activate;
26 import org.osgi.service.component.annotations.Component;
27 import org.osgi.service.component.annotations.Deactivate;
28 import org.osgi.service.component.annotations.Reference;
31 * Initializes the wep app.
33 * @author Thomas Pantelis
36 @Component(service = { })
37 public final class WebInitializer implements AutoCloseable {
38 private final Registration registration;
42 public WebInitializer(@Reference final WebServer webServer, @Reference final WebContextSecurer webContextSecurer,
43 @Reference final ServletSupport servletSupport, @Reference final OpenApiService openApiService)
44 throws ServletException {
45 final var webContextBuilder = WebContext.builder()
47 .contextPath("/openapi")
48 .supportsSessions(true)
49 .addServlet(ServletDetails.builder()
50 .servlet(servletSupport.createHttpServletBuilder(new Application() {
52 public Set<Object> getSingletons() {
53 return Set.of(openApiService, new JacksonJaxbJsonProvider());
56 .addUrlPattern("/api/v3/*")
58 .addResource(ResourceDetails.builder().name("/explorer").build());
60 webContextSecurer.requireAuthentication(webContextBuilder, "/*");
62 registration = webServer.registerWebContext(webContextBuilder.build());