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.nb.rfc8040.web;
10 import java.util.List;
11 import javax.annotation.PreDestroy;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import javax.servlet.ServletException;
15 import org.apache.aries.blueprint.annotation.service.Reference;
16 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
17 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
18 import org.opendaylight.aaa.web.FilterDetails;
19 import org.opendaylight.aaa.web.ServletDetails;
20 import org.opendaylight.aaa.web.WebContext;
21 import org.opendaylight.aaa.web.WebContextBuilder;
22 import org.opendaylight.aaa.web.WebContextRegistration;
23 import org.opendaylight.aaa.web.WebContextSecurer;
24 import org.opendaylight.aaa.web.WebServer;
25 import org.opendaylight.aaa.web.servlet.ServletSupport;
26 import org.opendaylight.restconf.nb.rfc8040.DataStreamApplication;
27 import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
28 import org.opendaylight.restconf.nb.rfc8040.RootFoundApplication;
29 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfStreamsConstants;
30 import org.opendaylight.restconf.nb.rfc8040.streams.websockets.WebSocketInitializer;
31 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
34 * Initializes the rfc8040 web app endpoint.
36 * @author Thomas Pantelis
39 public class WebInitializer {
40 private final WebContextRegistration registration;
43 public WebInitializer(@Reference final WebServer webServer, @Reference final WebContextSecurer webContextSecurer,
44 @Reference final ServletSupport servletSupport, final RestconfApplication webApp,
45 final DataStreamApplication webAppNotif,
46 @Reference final CustomFilterAdapterConfiguration customFilterAdapterConfig,
47 final WebSocketInitializer webSocketServlet) throws ServletException {
48 WebContextBuilder webContextBuilder = WebContext.builder()
50 .supportsSessions(false)
51 .addServlet(ServletDetails.builder()
52 .addUrlPattern(RestconfConstants.BASE_URI_PATTERN + "/*")
53 .servlet(servletSupport.createHttpServletBuilder(webApp).build())
55 .addServlet(ServletDetails.builder()
56 .addUrlPattern(RestconfConstants.BASE_URI_PATTERN + "/notif/*")
57 .servlet(servletSupport.createHttpServletBuilder(webAppNotif).build())
58 .name("notificationServlet")
61 .addServlet(ServletDetails.builder()
62 .addAllUrlPatterns(List.of(
63 RestconfConstants.BASE_URI_PATTERN + RestconfStreamsConstants.DATA_CHANGE_EVENT_STREAM_PATTERN,
64 RestconfConstants.BASE_URI_PATTERN + RestconfStreamsConstants.YANG_NOTIFICATION_STREAM_PATTERN))
65 .servlet(webSocketServlet)
67 .addServlet(ServletDetails.builder()
68 .addUrlPattern(".well-known/*")
69 .servlet(servletSupport.createHttpServletBuilder(
70 new RootFoundApplication(RestconfConstants.BASE_URI_PATTERN))
75 // Allows user to add javax.servlet.Filter(s) in front of REST services
76 .addFilter(FilterDetails.builder()
78 .filter(new CustomFilterAdapter(customFilterAdapterConfig))
82 webContextSecurer.requireAuthentication(webContextBuilder, true, RestconfConstants.BASE_URI_PATTERN + "/*");
84 registration = webServer.registerWebContext(webContextBuilder.build());
89 if (registration != null) {