Skip to content

Commit 54901ab

Browse files
committed
Avoid explicit DecoratedObjectFactory setup in JettyRequestUpgradeStrategy
Align Jetty support on spring-websocket module. Issue: SPR-14940
1 parent 7b18304 commit 54901ab

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

spring-web-reactive/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import javax.servlet.http.HttpServletRequest;
2424
import javax.servlet.http.HttpServletResponse;
2525

26-
import org.eclipse.jetty.util.DecoratedObjectFactory;
2726
import org.eclipse.jetty.websocket.server.WebSocketServerFactory;
2827
import reactor.core.publisher.Mono;
2928

@@ -165,7 +164,6 @@ private void startLazily(HttpServletRequest request) {
165164
synchronized (this.lifecycleMonitor) {
166165
if (this.servletContext == null) {
167166
this.servletContext = request.getServletContext();
168-
this.servletContext.setAttribute(DecoratedObjectFactory.ATTR, new DecoratedObjectFactory());
169167
start();
170168
}
171169
}

spring-web/src/test/java/org/springframework/http/server/reactive/bootstrap/JettyHttpServer.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class JettyHttpServer extends HttpServerSupport implements HttpServer, In
3232

3333
private Server jettyServer;
3434

35+
private ServletContextHandler contextHandler;
36+
3537
private boolean running;
3638

3739

@@ -42,8 +44,9 @@ public void afterPropertiesSet() throws Exception {
4244
ServletHttpHandlerAdapter servlet = initServletHttpHandlerAdapter();
4345
ServletHolder servletHolder = new ServletHolder(servlet);
4446

45-
ServletContextHandler contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
46-
contextHandler.addServlet(servletHolder, "/");
47+
this.contextHandler = new ServletContextHandler(this.jettyServer, "", false, false);
48+
this.contextHandler.addServlet(servletHolder, "/");
49+
this.contextHandler.start();
4750

4851
ServerConnector connector = new ServerConnector(this.jettyServer);
4952
connector.setHost(getHost());
@@ -79,12 +82,25 @@ public void stop() {
7982
if (this.running) {
8083
try {
8184
this.running = false;
82-
jettyServer.stop();
83-
jettyServer.destroy();
85+
if (this.contextHandler.isRunning()) {
86+
this.contextHandler.stop();
87+
}
8488
}
8589
catch (Exception ex) {
8690
throw new IllegalStateException(ex);
8791
}
92+
finally {
93+
try {
94+
if (this.jettyServer.isRunning()) {
95+
this.jettyServer.setStopTimeout(5000);
96+
this.jettyServer.stop();
97+
this.jettyServer.destroy();
98+
}
99+
}
100+
catch (Exception ex) {
101+
throw new IllegalStateException(ex);
102+
}
103+
}
88104
}
89105
}
90106

0 commit comments

Comments
 (0)