mirror of https://github.com/apache/activemq.git
Changing the WebSocket servlet to return a succesful empty response instead of an error when a GET request is made
This commit is contained in:
parent
7dc70e03ea
commit
f40532a23d
|
@ -85,7 +85,7 @@ public class WSServlet extends WebSocketServlet implements BrokerServiceAware {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
getServletContext().getNamedDispatcher("default").forward(request, response);
|
//return empty response - AMQ-6491
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -20,14 +20,13 @@ package org.apache.activemq.transport.ws;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.activemq.transport.http.HttpTraceTestSupport;
|
import org.apache.activemq.transport.http.HttpTraceTestSupport;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.Parameterized;
|
import org.junit.runners.Parameterized;
|
||||||
import org.junit.runners.Parameterized.Parameters;
|
import org.junit.runners.Parameterized.Parameters;
|
||||||
|
|
||||||
@RunWith(Parameterized.class)
|
@RunWith(Parameterized.class)
|
||||||
public class WSTransportHttpTraceTest extends WSTransportTest {
|
public class WSTransportHttpTraceTest extends WSTransportTestSupport {
|
||||||
|
|
||||||
protected String enableTraceParam;
|
protected String enableTraceParam;
|
||||||
protected int expectedStatus;
|
protected int expectedStatus;
|
||||||
|
@ -58,9 +57,4 @@ public class WSTransportHttpTraceTest extends WSTransportTest {
|
||||||
HttpTraceTestSupport.testHttpTraceEnabled("http://127.0.0.1:61623", expectedStatus, null);
|
HttpTraceTestSupport.testHttpTraceEnabled("http://127.0.0.1:61623", expectedStatus, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Ignore
|
|
||||||
@Test
|
|
||||||
public void testBrokerStart() throws Exception {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class WSTransportLinkStealingTest {
|
||||||
context.afterPropertiesSet();
|
context.afterPropertiesSet();
|
||||||
broker.setSslContext(context);
|
broker.setSslContext(context);
|
||||||
|
|
||||||
broker.addConnector(getWSConnectorURI()).setName("ws+mqtt");;
|
broker.addConnector(getWSConnectorURI()).setName("ws+mqtt");
|
||||||
broker.setDeleteAllMessagesOnStartup(deleteMessages);
|
broker.setDeleteAllMessagesOnStartup(deleteMessages);
|
||||||
broker.start();
|
broker.start();
|
||||||
broker.waitUntilStarted();
|
broker.waitUntilStarted();
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.apache.activemq.transport.ws;
|
package org.apache.activemq.transport.ws;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -25,13 +26,22 @@ import java.net.Socket;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.UnknownHostException;
|
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.broker.BrokerService;
|
||||||
import org.apache.activemq.transport.SocketConnectorFactory;
|
import org.apache.activemq.transport.SocketConnectorFactory;
|
||||||
import org.apache.activemq.transport.stomp.StompConnection;
|
import org.apache.activemq.transport.stomp.StompConnection;
|
||||||
import org.apache.activemq.util.Wait;
|
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.Connector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -57,9 +67,10 @@ public class WSTransportTest extends WSTransportTestSupport {
|
||||||
private File profileDir;
|
private File profileDir;
|
||||||
|
|
||||||
private String stompUri;
|
private String stompUri;
|
||||||
|
|
||||||
private StompConnection stompConnection = new StompConnection();
|
private StompConnection stompConnection = new StompConnection();
|
||||||
|
|
||||||
|
protected final int port = 61623;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void addAdditionalConnectors(BrokerService service) throws Exception {
|
protected void addAdditionalConnectors(BrokerService service) throws Exception {
|
||||||
stompUri = service.addConnector("stomp://localhost:0").getPublishableConnectString();
|
stompUri = service.addConnector("stomp://localhost:0").getPublishableConnectString();
|
||||||
|
@ -67,7 +78,7 @@ public class WSTransportTest extends WSTransportTestSupport {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getWSConnectorURI() {
|
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 {
|
protected Server createWebServer() throws Exception {
|
||||||
|
@ -143,6 +154,32 @@ public class WSTransportTest extends WSTransportTestSupport {
|
||||||
assertTrue(broker.isStarted());
|
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
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void testFireFoxWebSockets() throws Exception {
|
public void testFireFoxWebSockets() throws Exception {
|
||||||
|
|
|
@ -21,6 +21,8 @@ import org.apache.activemq.transport.ws.WSTransportTest;
|
||||||
import org.eclipse.jetty.server.Connector;
|
import org.eclipse.jetty.server.Connector;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ServerConnector;
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class WSSTransportTest extends WSTransportTest {
|
public class WSSTransportTest extends WSTransportTest {
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,12 +40,21 @@ public class WSSTransportTest extends WSTransportTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getWSConnectorURI() {
|
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
|
@Override
|
||||||
protected String getTestURI() {
|
protected String getTestURI() {
|
||||||
int port = getProxyPort();
|
int proxyPort = getProxyPort();
|
||||||
return "https://localhost:" + port + "/websocket.html#wss://localhost:61623";
|
return "https://localhost:" + proxyPort + "/websocket.html#wss://localhost:" + port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue