INT-3515: Fix Some WebSockets Issues
JIRA: https://jira.spring.io/browse/INT-3515 Change test suite to the Tomcat according IO INT-3515: IllegalStateException for the `WebSocketInboundChannelAdapter`, when `useBroker = true`, but there is no Broker Relay in the Context
This commit is contained in:
committed by
Gary Russell
parent
2587ed6bd0
commit
a5bddddac2
12
build.gradle
12
build.gradle
@@ -108,6 +108,7 @@ subprojects { subproject ->
|
||||
saajImplVersion = '1.3.23'
|
||||
servletApiVersion = '3.1.0'
|
||||
slf4jVersion = "1.7.6"
|
||||
tomcatVersion = "7.0.55"
|
||||
smack3Version = '3.2.1'
|
||||
smackVersion = '4.0.0'
|
||||
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.4.0.M1'
|
||||
@@ -565,15 +566,8 @@ project('spring-integration-websocket') {
|
||||
|
||||
compile ("org.springframework:spring-webmvc:$springVersion", optional)
|
||||
|
||||
testCompile("org.eclipse.jetty:jetty-webapp:$jettyVersion") {
|
||||
exclude group: "javax.servlet", module: "javax.servlet"
|
||||
}
|
||||
testCompile("org.eclipse.jetty.websocket:websocket-server:$jettyVersion") {
|
||||
exclude group: "javax.servlet", module: "javax.servlet"
|
||||
}
|
||||
testCompile "org.eclipse.jetty.websocket:websocket-client:$jettyVersion"
|
||||
testCompile"org.eclipse.jetty:jetty-client:$jettyVersion"
|
||||
testCompile "org.slf4j:slf4j-jcl:$slf4jVersion"
|
||||
testCompile "org.apache.tomcat.embed:tomcat-embed-websocket:$tomcatVersion"
|
||||
testCompile("org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -116,6 +116,10 @@ public abstract class IntegrationWebSocketContainer implements ApplicationEventP
|
||||
return Collections.unmodifiableList(protocols);
|
||||
}
|
||||
|
||||
public Map<String, WebSocketSession> getSessions() {
|
||||
return Collections.unmodifiableMap(this.sessions);
|
||||
}
|
||||
|
||||
public WebSocketSession getSession(String sessionId) throws Exception {
|
||||
WebSocketSession session = this.sessions.get(sessionId);
|
||||
Assert.notNull(session, "Session not found for id '" + sessionId + "'");
|
||||
|
||||
@@ -50,11 +50,9 @@ public class ClientWebSocketContainerParser extends AbstractSingleBeanDefinition
|
||||
@Override
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
builder.addConstructorArgReference(element.getAttribute("client"))
|
||||
.addConstructorArgValue(element.getAttribute("uri"));
|
||||
String uriVariables = element.getAttribute("uri-variables");
|
||||
if (StringUtils.hasText(uriVariables)) {
|
||||
builder.addConstructorArgValue(StringUtils.commaDelimitedListToStringArray(uriVariables));
|
||||
}
|
||||
.addConstructorArgValue(element.getAttribute("uri"))
|
||||
.addConstructorArgValue(StringUtils.commaDelimitedListToStringArray(element.getAttribute("uri-variables")));
|
||||
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-size-limit");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-time-limit");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "origin");
|
||||
|
||||
@@ -189,10 +189,9 @@ public class WebSocketInboundChannelAdapter extends MessageProducerSupport imple
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.brokerHandler == null) {
|
||||
logger.warn("'AbstractBrokerMessageHandler' isn't present in the application context. " +
|
||||
"The non-MESSAGE WebSocketMessages will be ignored.");
|
||||
}
|
||||
Assert.state(this.brokerHandler != null,
|
||||
"WebSocket Broker Relay isn't present in the application context; " +
|
||||
"it is required when 'useBroker = true'.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
|
||||
@@ -108,7 +109,7 @@ public final class SubProtocolHandlerRegistry {
|
||||
public SubProtocolHandler findProtocolHandler(WebSocketSession session) {
|
||||
SubProtocolHandler handler;
|
||||
String protocol = session.getAcceptedProtocol();
|
||||
if (protocol != null) {
|
||||
if (StringUtils.hasText(protocol)) {
|
||||
handler = this.protocolHandlers.get(protocol);
|
||||
Assert.state(handler != null,
|
||||
"No handler for sub-protocol '" + protocol + "', handlers = " + this.protocolHandlers);
|
||||
|
||||
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -40,7 +39,7 @@ import org.springframework.web.socket.PingMessage;
|
||||
import org.springframework.web.socket.PongMessage;
|
||||
import org.springframework.web.socket.WebSocketMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -48,7 +47,7 @@ import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
*/
|
||||
public class ClientWebSocketContainerTests {
|
||||
|
||||
private final static JettyWebSocketTestServer server = new JettyWebSocketTestServer(TestServerConfig.class);
|
||||
private final static TomcatWebSocketTestServer server = new TomcatWebSocketTestServer(TestServerConfig.class);
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws Exception {
|
||||
@@ -63,7 +62,7 @@ public class ClientWebSocketContainerTests {
|
||||
@Test
|
||||
public void testClientWebSocketContainer() throws Exception {
|
||||
ClientWebSocketContainer container =
|
||||
new ClientWebSocketContainer(new JettyWebSocketClient(), server.getWsBaseUrl() + "/ws/websocket");
|
||||
new ClientWebSocketContainer(new StandardWebSocketClient(), server.getWsBaseUrl() + "/ws/websocket");
|
||||
|
||||
TestWebSocketListener messageListener = new TestWebSocketListener();
|
||||
container.setMessageListener(messageListener);
|
||||
@@ -75,8 +74,7 @@ public class ClientWebSocketContainerTests {
|
||||
assertTrue(session.isOpen());
|
||||
assertEquals("v10.stomp", session.getAcceptedProtocol());
|
||||
|
||||
//TODO Jetty Server treats empty ByteBuffer as 'null' for PongMessage
|
||||
session.sendMessage(new PingMessage(ByteBuffer.wrap("ping".getBytes())));
|
||||
session.sendMessage(new PingMessage());
|
||||
|
||||
assertTrue(messageListener.messageLatch.await(10, TimeUnit.SECONDS));
|
||||
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 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.integration.websocket;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.1
|
||||
*/
|
||||
public class JettyWebSocketTestServer implements InitializingBean, DisposableBean {
|
||||
|
||||
private final Server jettyServer;
|
||||
|
||||
private final int port;
|
||||
|
||||
private final AnnotationConfigWebApplicationContext serverContext;
|
||||
|
||||
public JettyWebSocketTestServer(Class<?>... serverConfigs) {
|
||||
this.port = SocketUtils.findAvailableTcpPort();
|
||||
this.jettyServer = new Server(this.port);
|
||||
this.serverContext = new AnnotationConfigWebApplicationContext();
|
||||
this.serverContext.register(serverConfigs);
|
||||
this.serverContext.refresh();
|
||||
|
||||
ServletContextHandler contextHandler = new ServletContextHandler();
|
||||
ServletHolder servletHolder = new ServletHolder(new DispatcherServlet(this.serverContext));
|
||||
contextHandler.addServlet(servletHolder, "/");
|
||||
this.jettyServer.setHandler(contextHandler);
|
||||
}
|
||||
|
||||
public AnnotationConfigWebApplicationContext getServerContext() {
|
||||
return this.serverContext;
|
||||
}
|
||||
|
||||
public String getWsBaseUrl() {
|
||||
return "ws://localhost:" + this.port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.jettyServer.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
if (this.jettyServer.isRunning()) {
|
||||
this.jettyServer.setStopTimeout(0);
|
||||
this.jettyServer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright 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.integration.websocket;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.apache.catalina.startup.Tomcat;
|
||||
import org.apache.coyote.http11.Http11NioProtocol;
|
||||
import org.apache.tomcat.websocket.server.WsContextListener;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.SocketUtils;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
/**
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Artem Bilan
|
||||
* @since 4.1
|
||||
*/
|
||||
public class TomcatWebSocketTestServer implements InitializingBean, DisposableBean {
|
||||
|
||||
private final Tomcat tomcatServer;
|
||||
|
||||
private final int port;
|
||||
|
||||
private final AnnotationConfigWebApplicationContext serverContext;
|
||||
|
||||
public TomcatWebSocketTestServer(Class<?>... serverConfigs) {
|
||||
this.port = SocketUtils.findAvailableTcpPort();
|
||||
Connector connector = new Connector(Http11NioProtocol.class.getName());
|
||||
connector.setPort(this.port);
|
||||
|
||||
File baseDir = createTempDir("tomcat");
|
||||
String baseDirPath = baseDir.getAbsolutePath();
|
||||
|
||||
this.tomcatServer = new Tomcat();
|
||||
this.tomcatServer.setBaseDir(baseDirPath);
|
||||
this.tomcatServer.setPort(this.port);
|
||||
this.tomcatServer.getService().addConnector(connector);
|
||||
this.tomcatServer.setConnector(connector);
|
||||
|
||||
this.serverContext = new AnnotationConfigWebApplicationContext();
|
||||
this.serverContext.register(serverConfigs);
|
||||
|
||||
Context context = this.tomcatServer.addContext("", System.getProperty("java.io.tmpdir"));
|
||||
context.addApplicationListener(WsContextListener.class.getName());
|
||||
Tomcat.addServlet(context, "dispatcherServlet", new DispatcherServlet(this.serverContext)).setAsyncSupported(true);
|
||||
context.addServletMapping("/", "dispatcherServlet");
|
||||
}
|
||||
|
||||
private File createTempDir(String prefix) {
|
||||
try {
|
||||
File tempFolder = File.createTempFile(prefix + ".", "." + this.port);
|
||||
tempFolder.delete();
|
||||
tempFolder.mkdir();
|
||||
tempFolder.deleteOnExit();
|
||||
return tempFolder;
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException("Unable to create temp directory", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public AnnotationConfigWebApplicationContext getServerContext() {
|
||||
return this.serverContext;
|
||||
}
|
||||
|
||||
public String getWsBaseUrl() {
|
||||
return "ws://localhost:" + this.port;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
this.tomcatServer.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
this.tomcatServer.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,7 +52,7 @@ import org.springframework.integration.core.MessageProducer;
|
||||
import org.springframework.integration.transformer.ExpressionEvaluatingTransformer;
|
||||
import org.springframework.integration.websocket.ClientWebSocketContainer;
|
||||
import org.springframework.integration.websocket.IntegrationWebSocketContainer;
|
||||
import org.springframework.integration.websocket.JettyWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter;
|
||||
import org.springframework.integration.websocket.outbound.WebSocketOutboundMessageHandler;
|
||||
import org.springframework.integration.websocket.support.SubProtocolHandlerRegistry;
|
||||
@@ -72,12 +72,13 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.server.jetty.JettyRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy;
|
||||
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
|
||||
|
||||
/**
|
||||
@@ -247,13 +248,13 @@ public class StompIntegrationTests {
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public JettyWebSocketTestServer server() {
|
||||
return new JettyWebSocketTestServer(ServerConfig.class);
|
||||
public TomcatWebSocketTestServer server() {
|
||||
return new TomcatWebSocketTestServer(ServerConfig.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationWebSocketContainer clientWebSocketContainer() {
|
||||
return new ClientWebSocketContainer(new JettyWebSocketClient(), server().getWsBaseUrl() + "/ws/websocket");
|
||||
return new ClientWebSocketContainer(new StandardWebSocketClient(), server().getWsBaseUrl() + "/ws/websocket");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -370,7 +371,7 @@ public class StompIntegrationTests {
|
||||
|
||||
@Bean
|
||||
public DefaultHandshakeHandler handshakeHandler() {
|
||||
return new DefaultHandshakeHandler(new JettyRequestUpgradeStrategy());
|
||||
return new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,8 +40,8 @@ import org.springframework.integration.core.MessageProducer;
|
||||
import org.springframework.integration.transformer.ObjectToStringTransformer;
|
||||
import org.springframework.integration.websocket.ClientWebSocketContainer;
|
||||
import org.springframework.integration.websocket.IntegrationWebSocketContainer;
|
||||
import org.springframework.integration.websocket.JettyWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.TestServerConfig;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter;
|
||||
import org.springframework.integration.websocket.outbound.WebSocketOutboundMessageHandler;
|
||||
import org.springframework.integration.websocket.support.SubProtocolHandlerRegistry;
|
||||
@@ -56,7 +56,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.sockjs.client.SockJsClient;
|
||||
@@ -99,13 +99,13 @@ public class WebSocketClientTests {
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public JettyWebSocketTestServer server() {
|
||||
return new JettyWebSocketTestServer(ServerFlowConfig.class);
|
||||
public TomcatWebSocketTestServer server() {
|
||||
return new TomcatWebSocketTestServer(ServerFlowConfig.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebSocketClient webSocketClient() {
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new JettyWebSocketClient())));
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -101,4 +101,8 @@
|
||||
|
||||
<int:channel id="clientOutboundChannel"/>
|
||||
|
||||
<int-websocket:client-container id="simpleClientWebSocketContainer"
|
||||
client="webSocketClient"
|
||||
uri="ws://foo.bar"/>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -104,6 +104,10 @@ public class WebSocketParserTests {
|
||||
@Qualifier("clientWebSocketContainer")
|
||||
private IntegrationWebSocketContainer clientWebSocketContainer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("simpleClientWebSocketContainer")
|
||||
private IntegrationWebSocketContainer simpleClientWebSocketContainer;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("customInboundAdapter")
|
||||
private WebSocketInboundChannelAdapter customInboundAdapter;
|
||||
@@ -235,6 +239,19 @@ public class WebSocketParserTests {
|
||||
WebSocketHttpHeaders.class);
|
||||
assertEquals("FOO", headers.getOrigin());
|
||||
assertEquals(Arrays.asList("BAR", "baz"), headers.get("FOO"));
|
||||
|
||||
assertEquals(10 * 1000, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendTimeLimit"));
|
||||
assertEquals(512 * 1024, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferSizeLimit"));
|
||||
assertEquals(new URI("ws://foo.bar"),
|
||||
TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.uri", URI.class));
|
||||
assertSame(this.webSocketClient,
|
||||
TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.client"));
|
||||
assertEquals(Integer.MAX_VALUE,
|
||||
TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.phase"));
|
||||
assertFalse(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer,
|
||||
"connectionManager.autoStartup", Boolean.class));
|
||||
assertTrue(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "headers",
|
||||
WebSocketHttpHeaders.class).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.integration.core.MessageProducer;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.websocket.ClientWebSocketContainer;
|
||||
import org.springframework.integration.websocket.IntegrationWebSocketContainer;
|
||||
import org.springframework.integration.websocket.JettyWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.TestServerConfig;
|
||||
import org.springframework.integration.websocket.support.SubProtocolHandlerRegistry;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -55,6 +55,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
@@ -124,13 +125,13 @@ public class WebSocketInboundChannelAdapterTests {
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public JettyWebSocketTestServer server() {
|
||||
return new JettyWebSocketTestServer(TestServerConfig.class);
|
||||
public TomcatWebSocketTestServer server() {
|
||||
return new TomcatWebSocketTestServer(TestServerConfig.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebSocketClient webSocketClient() {
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new JettyWebSocketClient())));
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.websocket.ClientWebSocketContainer;
|
||||
import org.springframework.integration.websocket.IntegrationWebSocketContainer;
|
||||
import org.springframework.integration.websocket.JettyWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.TestServerConfig;
|
||||
import org.springframework.integration.websocket.support.SubProtocolHandlerRegistry;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -49,6 +49,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.sockjs.client.SockJsClient;
|
||||
@@ -101,13 +102,13 @@ public class WebSocketOutboundMessageHandlerTests {
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public JettyWebSocketTestServer server() {
|
||||
return new JettyWebSocketTestServer(TestServerConfig.class);
|
||||
public TomcatWebSocketTestServer server() {
|
||||
return new TomcatWebSocketTestServer(TestServerConfig.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebSocketClient webSocketClient() {
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new JettyWebSocketClient())));
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.springframework.integration.websocket.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Collections;
|
||||
@@ -28,10 +30,13 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
@@ -44,8 +49,8 @@ import org.springframework.integration.core.MessageProducer;
|
||||
import org.springframework.integration.transformer.ExpressionEvaluatingTransformer;
|
||||
import org.springframework.integration.websocket.ClientWebSocketContainer;
|
||||
import org.springframework.integration.websocket.IntegrationWebSocketContainer;
|
||||
import org.springframework.integration.websocket.JettyWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.ServerWebSocketContainer;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter;
|
||||
import org.springframework.integration.websocket.outbound.WebSocketOutboundMessageHandler;
|
||||
import org.springframework.integration.websocket.support.SubProtocolHandlerRegistry;
|
||||
@@ -64,7 +69,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.jetty.JettyWebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
|
||||
@@ -130,19 +135,37 @@ public class WebSocketServerTests {
|
||||
assertEquals("subs1", subscription.get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBrokerIsNotPresented() throws Exception {
|
||||
WebSocketInboundChannelAdapter webSocketInboundChannelAdapter =
|
||||
new WebSocketInboundChannelAdapter(Mockito.mock(ServerWebSocketContainer.class));
|
||||
webSocketInboundChannelAdapter.setOutputChannel(new DirectChannel());
|
||||
webSocketInboundChannelAdapter.setUseBroker(true);
|
||||
webSocketInboundChannelAdapter.setBeanFactory(Mockito.mock(BeanFactory.class));
|
||||
webSocketInboundChannelAdapter.setApplicationContext(Mockito.mock(ApplicationContext.class));
|
||||
try {
|
||||
webSocketInboundChannelAdapter.afterPropertiesSet();
|
||||
fail("IllegalStateException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, instanceOf(IllegalStateException.class));
|
||||
assertThat(e.getMessage(), containsString("WebSocket Broker Relay isn't present in the application context;"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableIntegration
|
||||
public static class ContextConfiguration {
|
||||
|
||||
@Bean
|
||||
public JettyWebSocketTestServer server() {
|
||||
return new JettyWebSocketTestServer(ServerConfig.class);
|
||||
public TomcatWebSocketTestServer server() {
|
||||
return new TomcatWebSocketTestServer(ServerConfig.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebSocketClient webSocketClient() {
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new JettyWebSocketClient())));
|
||||
return new SockJsClient(Collections.<Transport>singletonList(new WebSocketTransport(new StandardWebSocketClient())));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -87,7 +87,7 @@ public class SubProtocolHandlerRegistryTests {
|
||||
SubProtocolHandlerRegistry subProtocolHandlerRegistry =
|
||||
new SubProtocolHandlerRegistry(testProtocolHandler);
|
||||
WebSocketSession session = mock(WebSocketSession.class);
|
||||
when(session.getAcceptedProtocol()).thenReturn("foo", (String) null);
|
||||
when(session.getAcceptedProtocol()).thenReturn("foo", "", null);
|
||||
|
||||
try {
|
||||
subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
@@ -101,6 +101,10 @@ public class SubProtocolHandlerRegistryTests {
|
||||
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, testProtocolHandler);
|
||||
|
||||
protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
|
||||
assertNotNull(protocolHandler);
|
||||
assertSame(protocolHandler, testProtocolHandler);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user