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
(cherry picked from commit f40532a23d
)
This commit is contained in:
parent
1fc93660c6
commit
a50979e308
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue