Avoid explicit DecoratedObjectFactory setup in JettyRequestUpgradeStrategy
Align Jetty support on spring-websocket module. Issue: SPR-14940
This commit is contained in:
parent
7b183048b8
commit
54901ab865
|
|
@ -23,7 +23,6 @@ import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.eclipse.jetty.util.DecoratedObjectFactory;
|
|
||||||
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
|
@ -165,7 +164,6 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Life
|
||||||
synchronized (this.lifecycleMonitor) {
|
synchronized (this.lifecycleMonitor) {
|
||||||
if (this.servletContext == null) {
|
if (this.servletContext == null) {
|
||||||
this.servletContext = request.getServletContext();
|
this.servletContext = request.getServletContext();
|
||||||
this.servletContext.setAttribute(DecoratedObjectFactory.ATTR, new DecoratedObjectFactory());
|
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ public class JettyHttpServer extends HttpServerSupport implements HttpServer, In
|
||||||
|
|
||||||
private Server jettyServer;
|
private Server jettyServer;
|
||||||
|
|
||||||
|
private ServletContextHandler contextHandler;
|
||||||
|
|
||||||
private boolean running;
|
private boolean running;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,8 +44,9 @@ public class JettyHttpServer extends HttpServerSupport implements HttpServer, In
|
||||||
ServletHttpHandlerAdapter servlet = initServletHttpHandlerAdapter();
|
ServletHttpHandlerAdapter servlet = initServletHttpHandlerAdapter();
|
||||||
ServletHolder servletHolder = new ServletHolder(servlet);
|
ServletHolder servletHolder = new ServletHolder(servlet);
|
||||||
|
|
||||||
ServletContextHandler contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
|
this.contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
|
||||||
contextHandler.addServlet(servletHolder, "/");
|
this.contextHandler.addServlet(servletHolder, "/");
|
||||||
|
this.contextHandler.start();
|
||||||
|
|
||||||
ServerConnector connector = new ServerConnector(this.jettyServer);
|
ServerConnector connector = new ServerConnector(this.jettyServer);
|
||||||
connector.setHost(getHost());
|
connector.setHost(getHost());
|
||||||
|
|
@ -79,12 +82,25 @@ public class JettyHttpServer extends HttpServerSupport implements HttpServer, In
|
||||||
if (this.running) {
|
if (this.running) {
|
||||||
try {
|
try {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
jettyServer.stop();
|
if (this.contextHandler.isRunning()) {
|
||||||
jettyServer.destroy();
|
this.contextHandler.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
throw new IllegalStateException(ex);
|
throw new IllegalStateException(ex);
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
if (this.jettyServer.isRunning()) {
|
||||||
|
this.jettyServer.setStopTimeout(5000);
|
||||||
|
this.jettyServer.stop();
|
||||||
|
this.jettyServer.destroy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
throw new IllegalStateException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue