64
64
import org .eclipse .jetty .util .thread .QueuedThreadPool ;
65
65
import org .eclipse .jetty .xml .XmlConfiguration ;
66
66
import org .ops4j .pax .web .service .AuthenticatorService ;
67
+ import org .ops4j .pax .web .service .PaxWebConfig ;
67
68
import org .ops4j .pax .web .service .jetty .internal .web .JettyResourceServlet ;
68
69
import org .ops4j .pax .web .service .spi .config .Configuration ;
69
70
import org .ops4j .pax .web .service .spi .config .LogConfiguration ;
@@ -245,6 +246,13 @@ class JettyServerWrapper implements BatchVisitor {
245
246
246
247
private final Map <String , TreeMap <OsgiContextModel , SecurityConfigurationModel >> contextSecurityConstraints = new HashMap <>();
247
248
249
+ /**
250
+ * Whether contexts should be started immediately or only after some <em>active</em> element
251
+ * (like Servlet) was registered. Pax Web runs with deferred configuration, but for TCK we switch
252
+ * to immediate;
253
+ */
254
+ private boolean deferredConfiguration = true ;
255
+
248
256
JettyServerWrapper (Configuration config , JettyFactory jettyFactory ,
249
257
Bundle paxWebJettyBundle , ClassLoader classLoader ) {
250
258
this .configuration = config ;
@@ -253,6 +261,10 @@ class JettyServerWrapper implements BatchVisitor {
253
261
this .classLoader = classLoader ;
254
262
255
263
this .mainHandler = new PrioritizedHandlerCollection ();
264
+
265
+ String flag = paxWebJettyBundle == null ? null
266
+ : paxWebJettyBundle .getBundleContext ().getProperty (PaxWebConfig .BUNDLE_CONTEXT_PROPERTY_CONFIGURATION_DEFERRED );
267
+ deferredConfiguration = flag == null || Boolean .parseBoolean (flag );
256
268
}
257
269
258
270
// --- lifecycle and configuration methods
@@ -1127,6 +1139,10 @@ public void visitServletModelChange(ServletModelChange change) {
1127
1139
return ;
1128
1140
}
1129
1141
1142
+ if (!deferredConfiguration && model .getLoadOnStartup () == null ) {
1143
+ model .setLoadOnStartup (0 );
1144
+ }
1145
+
1130
1146
LOG .debug ("Adding servlet {} to {}" , model .getName (), contextPath );
1131
1147
1132
1148
// there may be many instances of ServletHolder using the same instance of servlet (added to
@@ -1668,12 +1684,18 @@ public void visitEventListenerModelChange(EventListenerModelChange change) {
1668
1684
// if there are many OsgiServletContexts per ServletContext)
1669
1685
servletContextHandler .addEventListener (eventListenerModel , eventListener );
1670
1686
1671
- if (stopped ) {
1687
+ if (stopped || ! deferredConfiguration ) {
1672
1688
// we have to start it again
1673
1689
// register a "callback batch operation", which will be submitted within a new batch
1674
1690
// as new task in single paxweb-config thread pool's thread
1675
- LOG .info ("Scheduling start of the {} context after listener registration for already started context" , contextPath );
1676
- change .registerBatchCompletedAction (new ContextStartChange (OpCode .MODIFY , contextPath ));
1691
+ if (stopped ) {
1692
+ LOG .info ("Scheduling start of the {} context after listener registration for already started context" , contextPath );
1693
+ } else {
1694
+ LOG .info ("Scheduling start of the {} context after listener registration for immediately started context" , contextPath );
1695
+ }
1696
+ ContextStartChange action = new ContextStartChange (OpCode .MODIFY , contextPath );
1697
+ action .setAsync (change .getEventListenerModel ().isAsynchronusRegistration ());
1698
+ change .registerBatchCompletedAction (action );
1677
1699
}
1678
1700
});
1679
1701
}
0 commit comments