Add UpgradeRequestStrategy for WildFly/Undertow
Issue: SPR-11237
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +30,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
import org.springframework.web.socket.server.RequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy;
|
||||
@@ -48,6 +50,7 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
static {
|
||||
upgradeStrategyConfigTypes.put(JettyWebSocketTestServer.class, JettyUpgradeStrategyConfig.class);
|
||||
upgradeStrategyConfigTypes.put(TomcatWebSocketTestServer.class, TomcatUpgradeStrategyConfig.class);
|
||||
upgradeStrategyConfigTypes.put(UndertowTestServer.class, UndertowUpgradeStrategyConfig.class);
|
||||
}
|
||||
|
||||
@Parameter(0)
|
||||
@@ -141,4 +144,13 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class UndertowUpgradeStrategyConfig extends AbstractRequestUpgradeStrategyConfig {
|
||||
|
||||
@Bean
|
||||
public RequestUpgradeStrategy requestUpgradeStrategy() {
|
||||
return new UndertowRequestUpgradeStrategy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.socket;
|
||||
|
||||
import io.undertow.Undertow;
|
||||
import io.undertow.servlet.api.DeploymentInfo;
|
||||
import io.undertow.servlet.api.DeploymentManager;
|
||||
import io.undertow.servlet.api.InstanceFactory;
|
||||
import io.undertow.servlet.api.InstanceHandle;
|
||||
import io.undertow.websockets.jsr.ServerWebSocketContainer;
|
||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.xnio.ByteBufferSlicePool;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import static io.undertow.servlet.Servlets.defaultContainer;
|
||||
import static io.undertow.servlet.Servlets.deployment;
|
||||
import static io.undertow.servlet.Servlets.servlet;
|
||||
|
||||
/**
|
||||
* Undertow-based {@link WebSocketTestServer}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class UndertowTestServer implements WebSocketTestServer {
|
||||
|
||||
private Undertow server;
|
||||
|
||||
private DeploymentManager manager;
|
||||
|
||||
private final int port;
|
||||
|
||||
|
||||
public UndertowTestServer() {
|
||||
this.port = SocketUtils.findAvailableTcpPort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPort() {
|
||||
return this.port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deployConfig(WebApplicationContext cxt) {
|
||||
|
||||
DispatcherServletInstanceFactory servletFactory = new DispatcherServletInstanceFactory(cxt);
|
||||
|
||||
DeploymentInfo servletBuilder = deployment()
|
||||
.setClassLoader(UndertowTestServer.class.getClassLoader())
|
||||
.setDeploymentName("underow-websocket-test")
|
||||
.setContextPath("/")
|
||||
.addServlet(servlet("DispatcherServlet", DispatcherServlet.class, servletFactory).addMapping("/"))
|
||||
.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, new WebSocketDeploymentInfo());
|
||||
|
||||
|
||||
this.manager = defaultContainer().addDeployment(servletBuilder);
|
||||
this.manager.deploy();
|
||||
|
||||
try {
|
||||
this.server = Undertow.builder()
|
||||
.addListener(this.port, "localhost")
|
||||
.setHandler(this.manager.start()).build();
|
||||
}
|
||||
catch (ServletException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeployConfig() {
|
||||
this.manager.undeploy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() throws Exception {
|
||||
this.server.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
this.server.stop();
|
||||
}
|
||||
|
||||
|
||||
private static class DispatcherServletInstanceFactory implements InstanceFactory<Servlet> {
|
||||
|
||||
private final WebApplicationContext wac;
|
||||
|
||||
|
||||
private DispatcherServletInstanceFactory(WebApplicationContext wac) {
|
||||
this.wac = wac;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstanceHandle<Servlet> createInstance() throws InstantiationException {
|
||||
return new InstanceHandle<Servlet>() {
|
||||
@Override
|
||||
public Servlet getInstance() {
|
||||
return new DispatcherServlet(wac);
|
||||
}
|
||||
@Override
|
||||
public void release() {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,7 +49,8 @@ public class WebSocketIntegrationTests extends AbstractWebSocketIntegrationTest
|
||||
public static Iterable<Object[]> arguments() {
|
||||
return Arrays.asList(new Object[][]{
|
||||
{new JettyWebSocketTestServer(), new JettyWebSocketClient()},
|
||||
{new TomcatWebSocketTestServer(), new StandardWebSocketClient()}
|
||||
{new TomcatWebSocketTestServer(), new StandardWebSocketClient()},
|
||||
{new UndertowTestServer(), new JettyWebSocketClient()}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,10 +27,7 @@ import org.junit.runners.Parameterized.Parameters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.socket.AbstractWebSocketIntegrationTests;
|
||||
import org.springframework.web.socket.JettyWebSocketTestServer;
|
||||
import org.springframework.web.socket.TomcatWebSocketTestServer;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.*;
|
||||
import org.springframework.web.socket.handler.AbstractWebSocketHandler;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
@@ -51,7 +48,8 @@ public class WebSocketConfigurationTests extends AbstractWebSocketIntegrationTes
|
||||
public static Iterable<Object[]> arguments() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{new JettyWebSocketTestServer(), new JettyWebSocketClient()},
|
||||
{new TomcatWebSocketTestServer(), new StandardWebSocketClient()}
|
||||
{new TomcatWebSocketTestServer(), new StandardWebSocketClient()},
|
||||
{new UndertowTestServer(), new StandardWebSocketClient()}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,24 +36,18 @@ import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.handler.annotation.MessageExceptionHandler;
|
||||
import org.springframework.messaging.handler.annotation.MessageMapping;
|
||||
import org.springframework.messaging.simp.config.ChannelRegistration;
|
||||
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
|
||||
import org.springframework.messaging.simp.stomp.StompCommand;
|
||||
import org.springframework.messaging.support.AbstractSubscribableChannel;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.socket.AbstractWebSocketIntegrationTests;
|
||||
import org.springframework.web.socket.JettyWebSocketTestServer;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.TomcatWebSocketTestServer;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.*;
|
||||
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
|
||||
import org.springframework.web.socket.server.HandshakeHandler;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
@@ -70,7 +64,8 @@ public class SimpAnnotationMethodIntegrationTests extends AbstractWebSocketInteg
|
||||
public static Iterable<Object[]> arguments() {
|
||||
return Arrays.asList(new Object[][] {
|
||||
{new JettyWebSocketTestServer(), new JettyWebSocketClient()},
|
||||
{new TomcatWebSocketTestServer(), new StandardWebSocketClient()}
|
||||
{new TomcatWebSocketTestServer(), new StandardWebSocketClient()},
|
||||
{new UndertowTestServer(), new StandardWebSocketClient()}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user