10
10
import com .google .common .base .Stopwatch ;
11
11
import com .google .common .base .Throwables ;
12
12
import io .lighty .core .controller .api .AbstractLightyModule ;
13
- import io .lighty .modules .northbound .restconf .community .impl .root .resource .discovery .RootFoundApplication ;
14
13
import io .lighty .modules .northbound .restconf .community .impl .util .RestConfConfigUtils ;
14
+ import io .lighty .server .LightyJettyServerProvider ;
15
15
import java .net .InetAddress ;
16
16
import java .net .InetSocketAddress ;
17
- import java .util .Set ;
18
- import io .lighty .server .LightyJettyServerProvider ;
19
17
import javax .servlet .ServletException ;
20
- import javax .ws .rs .core .Application ;
21
- import org .eclipse .jetty .server .Server ;
22
- import org .eclipse .jetty .server .handler .ContextHandlerCollection ;
23
- import org .eclipse .jetty .servlet .ServletContextHandler ;
24
- import org .eclipse .jetty .servlet .ServletHolder ;
25
- import org .glassfish .jersey .server .ResourceConfig ;
26
- import org .glassfish .jersey .servlet .ServletContainer ;
27
18
import org .opendaylight .aaa .filterchain .configuration .impl .CustomFilterAdapterConfigurationImpl ;
28
19
import org .opendaylight .aaa .web .WebContext ;
29
20
import org .opendaylight .aaa .web .WebContextSecurer ;
32
23
import org .opendaylight .mdsal .dom .api .DOMActionService ;
33
24
import org .opendaylight .mdsal .dom .api .DOMDataBroker ;
34
25
import org .opendaylight .mdsal .dom .api .DOMMountPointService ;
35
- import org .opendaylight .mdsal .dom .api .DOMNotificationService ;
36
26
import org .opendaylight .mdsal .dom .api .DOMRpcService ;
37
27
import org .opendaylight .mdsal .dom .api .DOMSchemaService ;
38
- import org .opendaylight .restconf .api .query .PrettyPrintParam ;
39
28
import org .opendaylight .restconf .server .jaxrs .JaxRsEndpoint ;
40
29
import org .opendaylight .restconf .server .jaxrs .JaxRsEndpointConfiguration ;
41
30
import org .opendaylight .restconf .server .jaxrs .JaxRsLocationProvider ;
42
- import org .opendaylight .restconf .server .jaxrs .JaxRsRestconf ;
43
- import org .opendaylight .restconf .server .jaxrs .JsonJaxRsFormattableBodyWriter ;
44
- import org .opendaylight .restconf .server .jaxrs .XmlJaxRsFormattableBodyWriter ;
45
31
import org .opendaylight .restconf .server .mdsal .MdsalDatabindProvider ;
46
32
import org .opendaylight .restconf .server .mdsal .MdsalRestconfServer ;
47
33
import org .opendaylight .restconf .server .mdsal .MdsalRestconfStreamRegistry ;
48
- import org .opendaylight .restconf .server .spi .ErrorTagMapping ;
49
34
import org .slf4j .Logger ;
50
35
import org .slf4j .LoggerFactory ;
51
36
@@ -55,43 +40,41 @@ public class CommunityRestConf extends AbstractLightyModule {
55
40
56
41
private final DOMDataBroker domDataBroker ;
57
42
private final DOMRpcService domRpcService ;
58
- private final DOMNotificationService domNotificationService ;
59
43
private final DOMMountPointService domMountPointService ;
60
44
private final DOMActionService domActionService ;
61
45
private final DOMSchemaService domSchemaService ;
62
- private final int httpPort ;
63
46
private final InetAddress inetAddress ;
64
- private final String restconfServletContextPath ;
47
+ private final int httpPort ;
65
48
private JettyWebServer jettyServer ;
66
49
private LightyJettyServerProvider lightyServerBuilder ;
67
50
private JaxRsEndpoint jaxRsEndpoint ;
51
+ private WebContextSecurer webContextSecurer ;
68
52
69
53
public CommunityRestConf (final DOMDataBroker domDataBroker , final DOMRpcService domRpcService ,
70
- final DOMActionService domActionService , final DOMNotificationService domNotificationService ,
54
+ final DOMActionService domActionService ,
71
55
final DOMMountPointService domMountPointService ,
72
- final DOMSchemaService domSchemaService , final InetAddress inetAddress ,
73
- final int httpPort , final String restconfServletContextPath ,
74
- final LightyJettyServerProvider serverBuilder ) {
56
+ final DOMSchemaService domSchemaService ,
57
+ final InetAddress inetAddress ,
58
+ final int httpPort ,
59
+ final LightyJettyServerProvider serverBuilder ,
60
+ final WebContextSecurer webContextSecurer ) {
75
61
this .domDataBroker = domDataBroker ;
76
62
this .domRpcService = domRpcService ;
77
63
this .domActionService = domActionService ;
78
- this .domNotificationService = domNotificationService ;
79
64
this .domMountPointService = domMountPointService ;
80
65
this .lightyServerBuilder = serverBuilder ;
81
66
this .domSchemaService = domSchemaService ;
82
- this .httpPort = httpPort ;
83
67
this .inetAddress = inetAddress ;
84
- this .restconfServletContextPath = restconfServletContextPath ;
68
+ this .httpPort = httpPort ;
69
+ this .webContextSecurer = (webContextSecurer == null ) ? new LightyWebContextSecurer () : webContextSecurer ;
85
70
}
86
71
87
72
public CommunityRestConf (final DOMDataBroker domDataBroker ,
88
73
final DOMRpcService domRpcService , final DOMActionService domActionService ,
89
- final DOMNotificationService domNotificationService , final DOMMountPointService domMountPointService ,
90
- final DOMSchemaService domSchemaService , final InetAddress inetAddress , final int httpPort ,
91
- final String restconfServletContextPath ) {
92
- this (domDataBroker , domRpcService , domActionService , domNotificationService ,
93
- domMountPointService , domSchemaService , inetAddress , httpPort ,
94
- restconfServletContextPath , null );
74
+ final DOMMountPointService domMountPointService , final DOMSchemaService domSchemaService ,
75
+ final InetAddress inetAddress , final int httpPort , final WebContextSecurer webContextSecurer ) {
76
+ this (domDataBroker , domRpcService , domActionService ,
77
+ domMountPointService , domSchemaService , inetAddress , httpPort , null , webContextSecurer );
95
78
}
96
79
97
80
@ Override
@@ -101,48 +84,24 @@ protected boolean initProcedure() throws ServletException {
101
84
102
85
LOG .info ("Starting RestconfApplication with configuration {}" , streamsConfiguration );
103
86
104
- if (lightyServerBuilder == null ){
105
- lightyServerBuilder = new LightyJettyServerProvider (new JettyWebServer ( ));
87
+ if (lightyServerBuilder == null ) {
88
+ lightyServerBuilder = new LightyJettyServerProvider (new InetSocketAddress ( inetAddress , httpPort ));
106
89
}
107
90
108
91
final MdsalDatabindProvider databindProvider = new MdsalDatabindProvider (domSchemaService );
109
- final var server = new MdsalRestconfServer (databindProvider , domDataBroker , domRpcService , domActionService ,
110
- domMountPointService );
92
+ final var server = new MdsalRestconfServer (databindProvider , domDataBroker , domRpcService ,
93
+ domActionService , domMountPointService );
111
94
112
95
this .jettyServer = this .lightyServerBuilder .build ();
113
- this .jaxRsEndpoint = new JaxRsEndpoint (new JettyWebServer (httpPort ), new LightyWebContextSecurer (),
114
- new JerseyServletSupport (), new CustomFilterAdapterConfigurationImpl (), server ,
96
+ this .jaxRsEndpoint = new JaxRsEndpoint (
97
+ jettyServer ,
98
+ this .webContextSecurer ,
99
+ new JerseyServletSupport (),
100
+ new CustomFilterAdapterConfigurationImpl (),
101
+ server ,
115
102
new MdsalRestconfStreamRegistry (new JaxRsLocationProvider (), domDataBroker ),
116
- JaxRsEndpoint .props (streamsConfiguration ));
117
-
118
- final ServletContainer servletContainer8040 = new ServletContainer (ResourceConfig
119
- .forApplication (new Application () {
120
- @ Override
121
- public Set <Object > getSingletons () {
122
- return Set .of (
123
- new JsonJaxRsFormattableBodyWriter (), new XmlJaxRsFormattableBodyWriter (),
124
- new JaxRsRestconf (server , new MdsalRestconfStreamRegistry (new JaxRsLocationProvider (),
125
- domDataBroker ), jaxRsEndpoint , ErrorTagMapping .RFC8040 , PrettyPrintParam .FALSE ));
126
- }
127
- }));
128
-
129
- final ServletHolder jaxrs = new ServletHolder (servletContainer8040 );
130
-
131
- LOG .info ("RestConf init complete, starting Jetty" );
132
- LOG .info ("http address:port {}:{}, url prefix: {}" , this .inetAddress .toString (), this .httpPort ,
133
- this .restconfServletContextPath );
134
- final InetSocketAddress inetSocketAddress = new InetSocketAddress (this .inetAddress , this .httpPort );
135
- final ContextHandlerCollection contexts = new ContextHandlerCollection ();
136
- final ServletContextHandler mainHandler =
137
- new ServletContextHandler (contexts , this .restconfServletContextPath , true , false );
138
- mainHandler .addServlet (jaxrs , "/*" );
139
-
140
- final ServletContextHandler rrdHandler =
141
- new ServletContextHandler (contexts , "/.well-known" , true , false );
142
- final RootFoundApplication rootDiscoveryApp = new RootFoundApplication (restconfServletContextPath );
143
- rrdHandler .addServlet (new ServletHolder (new ServletContainer (ResourceConfig
144
- .forApplication (rootDiscoveryApp ))), "/*" );
145
-
103
+ JaxRsEndpoint .props (streamsConfiguration )
104
+ );
146
105
147
106
LOG .info ("Lighty RestConf started in {}" , stopwatch .stop ());
148
107
return true ;
@@ -196,7 +155,7 @@ public static class LightyWebContextSecurer implements WebContextSecurer {
196
155
@ Override
197
156
public void requireAuthentication (WebContext .Builder webContextBuilder ,
198
157
boolean asyncSupported , String ... urlPatterns ) {
199
-
158
+ //do nothing since shiro is not used
200
159
}
201
160
202
161
@ Override
0 commit comments