From a50979e308ab97123cfcf058e1acabb2c2c6b9d9 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Tue, 22 Nov 2016 07:27:29 -0500 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6491 Changing the WebSocket servlet to return a succesful empty response instead of an error when a GET request is made (cherry picked from commit f40532a23d70639a027fcf87893de8683edf430f) --- .../transport/ws/jetty9/WSServlet.java | 2 +- .../ws/WSTransportHttpTraceTest.java | 8 +--- .../ws/WSTransportLinkStealingTest.java | 2 +- .../transport/ws/WSTransportTest.java | 41 ++++++++++++++++++- .../transport/wss/WSSTransportTest.java | 17 ++++++-- 5 files changed, 56 insertions(+), 14 deletions(-) diff --git a/activemq-http/src/main/java/org/apache/activemq/transport/ws/jetty9/WSServlet.java b/activemq-http/src/main/java/org/apache/activemq/transport/ws/jetty9/WSServlet.java index 1f7c5e7b8c..21754ada6c 100644 --- a/activemq-http/src/main/java/org/apache/activemq/transport/ws/jetty9/WSServlet.java +++ b/activemq-http/src/main/java/org/apache/activemq/transport/ws/jetty9/WSServlet.java @@ -85,7 +85,7 @@ public class WSServlet extends WebSocketServlet implements BrokerServiceAware { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - getServletContext().getNamedDispatcher("default").forward(request, response); + //return empty response - AMQ-6491 } @Override diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportHttpTraceTest.java b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportHttpTraceTest.java index 5b82ce0e76..64392b15a9 100644 --- a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportHttpTraceTest.java +++ b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportHttpTraceTest.java @@ -20,14 +20,13 @@ package org.apache.activemq.transport.ws; import java.util.Collection; import org.apache.activemq.transport.http.HttpTraceTestSupport; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) -public class WSTransportHttpTraceTest extends WSTransportTest { +public class WSTransportHttpTraceTest extends WSTransportTestSupport { protected String enableTraceParam; protected int expectedStatus; @@ -58,9 +57,4 @@ public class WSTransportHttpTraceTest extends WSTransportTest { HttpTraceTestSupport.testHttpTraceEnabled("http://127.0.0.1:61623", expectedStatus, null); } - @Override - @Ignore - @Test - public void testBrokerStart() throws Exception { - } } diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportLinkStealingTest.java b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportLinkStealingTest.java index bd5770c38c..2ca03c86d7 100644 --- a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportLinkStealingTest.java +++ b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportLinkStealingTest.java @@ -50,7 +50,7 @@ public class WSTransportLinkStealingTest { context.afterPropertiesSet(); broker.setSslContext(context); - broker.addConnector(getWSConnectorURI()).setName("ws+mqtt");; + broker.addConnector(getWSConnectorURI()).setName("ws+mqtt"); broker.setDeleteAllMessagesOnStartup(deleteMessages); broker.start(); broker.waitUntilStarted(); diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java index f9fe74d4f5..ca118769c2 100644 --- a/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java +++ b/activemq-http/src/test/java/org/apache/activemq/transport/ws/WSTransportTest.java @@ -17,6 +17,7 @@ package org.apache.activemq.transport.ws; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.io.File; @@ -25,13 +26,22 @@ import java.net.Socket; import java.net.URI; import java.net.URISyntaxException; import java.net.UnknownHostException; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.transport.SocketConnectorFactory; import org.apache.activemq.transport.stomp.StompConnection; import org.apache.activemq.util.Wait; +import org.eclipse.jetty.client.HttpClient; +import org.eclipse.jetty.client.api.Request; +import org.eclipse.jetty.client.api.Result; +import org.eclipse.jetty.client.util.BufferingResponseListener; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.After; import org.junit.Before; @@ -57,9 +67,10 @@ public class WSTransportTest extends WSTransportTestSupport { private File profileDir; private String stompUri; - private StompConnection stompConnection = new StompConnection(); + protected final int port = 61623; + @Override protected void addAdditionalConnectors(BrokerService service) throws Exception { stompUri = service.addConnector("stomp://localhost:0").getPublishableConnectString(); @@ -67,7 +78,7 @@ public class WSTransportTest extends WSTransportTestSupport { @Override protected String getWSConnectorURI() { - return "ws://127.0.0.1:61623?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001"; + return "ws://127.0.0.1:" + port + "?websocket.maxTextMessageSize=99999&transport.maxIdleTime=1001"; } protected Server createWebServer() throws Exception { @@ -143,6 +154,32 @@ public class WSTransportTest extends WSTransportTestSupport { assertTrue(broker.isStarted()); } + @Test(timeout=10000) + public void testGet() throws Exception { + testGet("http://127.0.0.1:" + port, null); + } + + + protected void testGet(final String uri, SslContextFactory + sslContextFactory) throws Exception { + HttpClient httpClient = sslContextFactory != null ? new HttpClient(sslContextFactory) : + new HttpClient(new SslContextFactory()); + httpClient.start(); + + final CountDownLatch latch = new CountDownLatch(1); + Request request = httpClient.newRequest(uri).method(HttpMethod.GET); + final AtomicInteger status = new AtomicInteger(); + request.send(new BufferingResponseListener() { + @Override + public void onComplete(Result result) { + status.set(result.getResponse().getStatus()); + latch.countDown(); + } + }); + latch.await(); + assertEquals(HttpStatus.OK_200, status.get()); + } + @Ignore @Test public void testFireFoxWebSockets() throws Exception { diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java b/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java index 6af0f4e63c..a3722c2f7b 100644 --- a/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java +++ b/activemq-http/src/test/java/org/apache/activemq/transport/wss/WSSTransportTest.java @@ -21,6 +21,8 @@ import org.apache.activemq.transport.ws.WSTransportTest; import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.util.ssl.SslContextFactory; +import org.junit.Test; public class WSSTransportTest extends WSTransportTest { @Override @@ -38,12 +40,21 @@ public class WSSTransportTest extends WSTransportTest { @Override protected String getWSConnectorURI() { - return "wss://localhost:61623"; + return "wss://localhost:" + port; + } + + @Override + @Test(timeout=10000) + public void testGet() throws Exception { + SslContextFactory factory = new SslContextFactory(); + factory.setSslContext(broker.getSslContext().getSSLContext()); + + testGet("https://127.0.0.1:" + port, factory); } @Override protected String getTestURI() { - int port = getProxyPort(); - return "https://localhost:" + port + "/websocket.html#wss://localhost:61623"; + int proxyPort = getProxyPort(); + return "https://localhost:" + proxyPort + "/websocket.html#wss://localhost:" + port; } }