|
|
@ -18,7 +18,6 @@ package org.springframework.boot.web.embedded.jetty;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
|
|
|
|
|
|
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
|
|
|
|
|
|
|
import org.eclipse.jetty.webapp.AbstractConfiguration;
|
|
|
|
import org.eclipse.jetty.webapp.AbstractConfiguration;
|
|
|
|
import org.eclipse.jetty.webapp.Configuration;
|
|
|
|
import org.eclipse.jetty.webapp.Configuration;
|
|
|
|
import org.eclipse.jetty.webapp.WebAppContext;
|
|
|
|
import org.eclipse.jetty.webapp.WebAppContext;
|
|
|
@ -50,54 +49,35 @@ public class ServletContextInitializerConfiguration extends AbstractConfiguratio
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void configure(WebAppContext context) throws Exception {
|
|
|
|
public void configure(WebAppContext context) throws Exception {
|
|
|
|
context.addBean(new Initializer(context), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Jetty {@link AbstractLifeCycle} to call the {@link ServletContextInitializer
|
|
|
|
|
|
|
|
* ServletContextInitializers}.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private class Initializer extends AbstractLifeCycle {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final WebAppContext context;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Initializer(WebAppContext context) {
|
|
|
|
|
|
|
|
this.context = context;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
protected void doStart() throws Exception {
|
|
|
|
|
|
|
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
|
|
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
|
|
|
Thread.currentThread().setContextClassLoader(this.context.getClassLoader());
|
|
|
|
Thread.currentThread().setContextClassLoader(context.getClassLoader());
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
callInitializers();
|
|
|
|
callInitializers(context);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
finally {
|
|
|
|
Thread.currentThread().setContextClassLoader(classLoader);
|
|
|
|
Thread.currentThread().setContextClassLoader(classLoader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void callInitializers() throws ServletException {
|
|
|
|
private void callInitializers(WebAppContext context) throws ServletException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
setExtendedListenerTypes(true);
|
|
|
|
setExtendedListenerTypes(context, true);
|
|
|
|
for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) {
|
|
|
|
for (ServletContextInitializer initializer : this.initializers) {
|
|
|
|
initializer.onStartup(this.context.getServletContext());
|
|
|
|
initializer.onStartup(context.getServletContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally {
|
|
|
|
finally {
|
|
|
|
setExtendedListenerTypes(false);
|
|
|
|
setExtendedListenerTypes(context, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setExtendedListenerTypes(boolean extended) {
|
|
|
|
private void setExtendedListenerTypes(WebAppContext context, boolean extended) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
this.context.getServletContext().setExtendedListenerTypes(extended);
|
|
|
|
context.getServletContext().setExtendedListenerTypes(extended);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NoSuchMethodError ex) {
|
|
|
|
catch (NoSuchMethodError ex) {
|
|
|
|
// Not available on Jetty 8
|
|
|
|
// Not available on Jetty 8
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|