Avoid explicit DecoratedObjectFactory setup in JettyRequestUpgradeStrategy
Issue: SPR-14940
(cherry picked from commit 709d4ba
)
This commit is contained in:
parent
e07d110a67
commit
483abfe266
|
@ -26,7 +26,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.api.WebSocketPolicy;
|
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||||
import org.eclipse.jetty.websocket.server.HandshakeRFC6455;
|
import org.eclipse.jetty.websocket.server.HandshakeRFC6455;
|
||||||
|
@ -296,7 +295,6 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy, Serv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected WebSocketServerFactory createFactory(WebSocketPolicy policy) throws Exception {
|
protected WebSocketServerFactory createFactory(WebSocketPolicy policy) throws Exception {
|
||||||
servletContext.setAttribute(DecoratedObjectFactory.ATTR, new DecoratedObjectFactory());
|
|
||||||
return new WebSocketServerFactory(servletContext, policy);
|
return new WebSocketServerFactory(servletContext, policy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,11 +86,10 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||||
|
|
||||||
this.server.setup();
|
this.server.setup();
|
||||||
this.server.deployConfig(this.wac);
|
this.server.deployConfig(this.wac);
|
||||||
// Set ServletContext in WebApplicationContext after deployment but before
|
this.server.start();
|
||||||
// starting the server.
|
|
||||||
this.wac.setServletContext(this.server.getServletContext());
|
this.wac.setServletContext(this.server.getServletContext());
|
||||||
this.wac.refresh();
|
this.wac.refresh();
|
||||||
this.server.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Class<?>[] getAnnotatedConfigClasses();
|
protected abstract Class<?>[] getAnnotatedConfigClasses();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -52,11 +52,6 @@ public class JettyWebSocketTestServer implements WebSocketTestServer {
|
||||||
this.jettyServer = new Server(0);
|
this.jettyServer = new Server(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
return this.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deployConfig(WebApplicationContext wac, Filter... filters) {
|
public void deployConfig(WebApplicationContext wac, Filter... filters) {
|
||||||
ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(wac));
|
ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(wac));
|
||||||
|
@ -72,11 +67,6 @@ public class JettyWebSocketTestServer implements WebSocketTestServer {
|
||||||
return EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC);
|
return EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServletContext getServletContext() {
|
|
||||||
return this.contextHandler.getServletContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undeployConfig() {
|
public void undeployConfig() {
|
||||||
// Stopping jetty will undeploy the servlet
|
// Stopping jetty will undeploy the servlet
|
||||||
|
@ -85,6 +75,7 @@ public class JettyWebSocketTestServer implements WebSocketTestServer {
|
||||||
@Override
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
this.jettyServer.start();
|
this.jettyServer.start();
|
||||||
|
this.contextHandler.start();
|
||||||
|
|
||||||
Connector[] connectors = jettyServer.getConnectors();
|
Connector[] connectors = jettyServer.getConnectors();
|
||||||
NetworkConnector connector = (NetworkConnector) connectors[0];
|
NetworkConnector connector = (NetworkConnector) connectors[0];
|
||||||
|
@ -93,10 +84,27 @@ public class JettyWebSocketTestServer implements WebSocketTestServer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
if (this.jettyServer.isRunning()) {
|
try {
|
||||||
this.jettyServer.setStopTimeout(5000);
|
if (this.contextHandler.isRunning()) {
|
||||||
this.jettyServer.stop();
|
this.contextHandler.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (this.jettyServer.isRunning()) {
|
||||||
|
this.jettyServer.setStopTimeout(5000);
|
||||||
|
this.jettyServer.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPort() {
|
||||||
|
return this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServletContext getServletContext() {
|
||||||
|
return this.contextHandler.getServletContext();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ package org.springframework.web.socket;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javax.servlet.Filter;
|
import javax.servlet.Filter;
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
|
||||||
|
@ -82,15 +81,10 @@ public class TomcatWebSocketTestServer implements WebSocketTestServer {
|
||||||
return tempFolder;
|
return tempFolder;
|
||||||
}
|
}
|
||||||
catch (IOException ex) {
|
catch (IOException ex) {
|
||||||
throw new RuntimeException("Unable to create temp directory", ex);
|
throw new IllegalStateException("Unable to create temp directory", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
return this.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deployConfig(WebApplicationContext wac, Filter... filters) {
|
public void deployConfig(WebApplicationContext wac, Filter... filters) {
|
||||||
Assert.state(this.port != -1, "setup() was never called.");
|
Assert.state(this.port != -1, "setup() was never called.");
|
||||||
|
@ -112,11 +106,6 @@ public class TomcatWebSocketTestServer implements WebSocketTestServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServletContext getServletContext() {
|
|
||||||
return this.context.getServletContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undeployConfig() {
|
public void undeployConfig() {
|
||||||
if (this.context != null) {
|
if (this.context != null) {
|
||||||
|
@ -143,4 +132,14 @@ public class TomcatWebSocketTestServer implements WebSocketTestServer {
|
||||||
this.tomcatServer.stop();
|
this.tomcatServer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPort() {
|
||||||
|
return this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServletContext getServletContext() {
|
||||||
|
return this.context.getServletContext();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,6 +16,13 @@
|
||||||
|
|
||||||
package org.springframework.web.socket;
|
package org.springframework.web.socket;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.servlet.DispatcherType;
|
||||||
|
import javax.servlet.Filter;
|
||||||
|
import javax.servlet.Servlet;
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
|
||||||
import io.undertow.Undertow;
|
import io.undertow.Undertow;
|
||||||
import io.undertow.server.HttpHandler;
|
import io.undertow.server.HttpHandler;
|
||||||
import io.undertow.servlet.api.DeploymentInfo;
|
import io.undertow.servlet.api.DeploymentInfo;
|
||||||
|
@ -24,23 +31,14 @@ import io.undertow.servlet.api.FilterInfo;
|
||||||
import io.undertow.servlet.api.InstanceFactory;
|
import io.undertow.servlet.api.InstanceFactory;
|
||||||
import io.undertow.servlet.api.InstanceHandle;
|
import io.undertow.servlet.api.InstanceHandle;
|
||||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
||||||
|
import org.xnio.OptionMap;
|
||||||
import java.io.IOException;
|
import org.xnio.Xnio;
|
||||||
|
|
||||||
import javax.servlet.DispatcherType;
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.Servlet;
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.SocketUtils;
|
import org.springframework.util.SocketUtils;
|
||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.servlet.DispatcherServlet;
|
import org.springframework.web.servlet.DispatcherServlet;
|
||||||
|
|
||||||
import org.xnio.OptionMap;
|
|
||||||
import org.xnio.Xnio;
|
|
||||||
|
|
||||||
import static io.undertow.servlet.Servlets.*;
|
import static io.undertow.servlet.Servlets.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,11 +61,6 @@ public class UndertowTestServer implements WebSocketTestServer {
|
||||||
this.port = SocketUtils.findAvailableTcpPort();
|
this.port = SocketUtils.findAvailableTcpPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPort() {
|
|
||||||
return this.port;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public void deployConfig(WebApplicationContext wac, Filter... filters) {
|
public void deployConfig(WebApplicationContext wac, Filter... filters) {
|
||||||
|
@ -108,11 +101,6 @@ public class UndertowTestServer implements WebSocketTestServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ServletContext getServletContext() {
|
|
||||||
return this.manager.getDeployment().getServletContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void undeployConfig() {
|
public void undeployConfig() {
|
||||||
this.manager.undeploy();
|
this.manager.undeploy();
|
||||||
|
@ -128,6 +116,16 @@ public class UndertowTestServer implements WebSocketTestServer {
|
||||||
this.server.stop();
|
this.server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPort() {
|
||||||
|
return this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ServletContext getServletContext() {
|
||||||
|
return this.manager.getDeployment().getServletContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class DispatcherServletInstanceFactory implements InstanceFactory<Servlet> {
|
private static class DispatcherServletInstanceFactory implements InstanceFactory<Servlet> {
|
||||||
|
|
||||||
|
@ -151,6 +149,7 @@ public class UndertowTestServer implements WebSocketTestServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class FilterInstanceFactory implements InstanceFactory<Filter> {
|
private static class FilterInstanceFactory implements InstanceFactory<Filter> {
|
||||||
|
|
||||||
private final Filter filter;
|
private final Filter filter;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -29,26 +29,24 @@ import org.springframework.web.context.WebApplicationContext;
|
||||||
*/
|
*/
|
||||||
public interface WebSocketTestServer {
|
public interface WebSocketTestServer {
|
||||||
|
|
||||||
int getPort();
|
|
||||||
|
|
||||||
void setup();
|
void setup();
|
||||||
|
|
||||||
void deployConfig(WebApplicationContext cxt, Filter... filters);
|
void deployConfig(WebApplicationContext cxt, Filter... filters);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the {@link ServletContext} created by the underlying server.
|
|
||||||
*
|
|
||||||
* <p>The {@code ServletContext} is only guaranteed to be available
|
|
||||||
* after {@link #deployConfig} has been invoked.
|
|
||||||
*
|
|
||||||
* @since 4.2
|
|
||||||
*/
|
|
||||||
ServletContext getServletContext();
|
|
||||||
|
|
||||||
void undeployConfig();
|
void undeployConfig();
|
||||||
|
|
||||||
void start() throws Exception;
|
void start() throws Exception;
|
||||||
|
|
||||||
void stop() throws Exception;
|
void stop() throws Exception;
|
||||||
|
|
||||||
}
|
int getPort();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the {@link ServletContext} created by the underlying server.
|
||||||
|
* <p>The {@code ServletContext} is only guaranteed to be available
|
||||||
|
* after {@link #deployConfig} has been invoked.
|
||||||
|
* @since 4.2
|
||||||
|
*/
|
||||||
|
ServletContext getServletContext();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -97,9 +97,9 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||||
@Override
|
@Override
|
||||||
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
|
||||||
registry.addHandler(serverHandler(), "/ws")
|
registry.addHandler(serverHandler(), "/ws")
|
||||||
.setHandshakeHandler(this.handshakeHandler);
|
.setHandshakeHandler(this.handshakeHandler);
|
||||||
registry.addHandler(serverHandler(), "/sockjs").withSockJS()
|
registry.addHandler(serverHandler(), "/sockjs").withSockJS()
|
||||||
.setTransportHandlerOverrides(new WebSocketTransportHandler(this.handshakeHandler));
|
.setTransportHandlerOverrides(new WebSocketTransportHandler(this.handshakeHandler));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -108,6 +108,7 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class TestHandler extends AbstractWebSocketHandler {
|
private static class TestHandler extends AbstractWebSocketHandler {
|
||||||
|
|
||||||
private CountDownLatch connectLatch = new CountDownLatch(1);
|
private CountDownLatch connectLatch = new CountDownLatch(1);
|
||||||
|
|
Loading…
Reference in New Issue