use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 by apache.
the class TestWsServerContainer method testBug54807.
@Test
public void testBug54807() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(Bug54807Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
Assert.assertEquals(LifecycleState.STARTED, ctx.getState());
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 by apache.
the class TestWsRemoteEndpointImplServer method testClientDropsConnection.
/*
* https://bz.apache.org/bugzilla/show_bug.cgi?id=58624
*
* This test requires three breakpoints to be set. Two in this file (marked
* A & B with comments) and one (C) at the start of
* WsRemoteEndpointImplServer.doWrite().
*
* With the breakpoints in place, run this test.
* Once breakpoints A & B are reached, progress the thread at breakpoint A
* one line to close the connection.
* Once breakpoint C is reached, allow the thread at breakpoint B to
* continue.
* Then allow the thread at breakpoint C to continue.
*
* In the failure mode, the thread at breakpoint B will not progress past
* the call to sendObject(). If the issue is fixed, the thread at breakpoint
* B will continue past sendObject() and terminate with a TimeoutException.
*/
@Test
public void testClientDropsConnection() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(Bug58624Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
tomcat.start();
SimpleClient client = new SimpleClient();
URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH);
Session session = wsContainer.connectToServer(client, uri);
// Break point A required on following line
session.close();
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 by apache.
the class TestWebSocket method testNoUpgrade.
@Test
public void testNoUpgrade() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Connection: upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 13" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an error response
// No upgrade means it is not treated an as upgrade request so a 404 is
// generated when the request reaches the Default Servlet.s
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 404"));
// Finished with the socket
client.close();
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 by apache.
the class TestWebSocket method testSimple.
@Test
public void testSimple() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Upgrade: websocket" + CRLF);
client.writer.write("Connection: keep-alive, upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 13" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an upgrade response
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 101"));
// Swallow the headers
String responseHeaderLine = client.reader.readLine();
while (!responseHeaderLine.equals("")) {
responseHeaderLine = client.reader.readLine();
}
// Now we can do WebSocket
client.sendMessage("foo", false);
client.sendMessage("foo", true);
Assert.assertEquals("foofoo", client.readMessage());
// Finished with the socket
client.close();
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 by apache.
the class TestWebSocket method testDetectWrongVersion.
@Test
public void testDetectWrongVersion() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(new ApplicationListener(TesterEchoServer.Config.class.getName(), false));
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketClient client = new WebSocketClient(getPort());
// Send the WebSocket handshake
client.writer.write("GET " + TesterEchoServer.Config.PATH_BASIC + " HTTP/1.1" + CRLF);
client.writer.write("Host: foo" + CRLF);
client.writer.write("Upgrade: websocket" + CRLF);
client.writer.write("Connection: upgrade" + CRLF);
client.writer.write("Sec-WebSocket-Version: 8" + CRLF);
client.writer.write("Sec-WebSocket-Key: TODO" + CRLF);
client.writer.write(CRLF);
client.writer.flush();
// Make sure we got an upgrade response
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 426"));
List<String> headerlines = new ArrayList<String>();
String responseHeaderLine = client.reader.readLine();
while (!responseHeaderLine.equals("")) {
headerlines.add(responseHeaderLine);
responseHeaderLine = client.reader.readLine();
}
Assert.assertTrue(headerlines.contains("Sec-WebSocket-Version: 13"));
// Finished with the socket
client.close();
}
Aggregations