Search in sources :

Example 21 with DefaultServlet

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());
}
Also used : TesterServletContext(org.apache.tomcat.unittest.TesterServletContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) Test(org.junit.Test) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest)

Example 22 with DefaultServlet

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();
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) WebSocketContainer(javax.websocket.WebSocketContainer) SimpleClient(org.apache.tomcat.websocket.pojo.TesterUtil.SimpleClient) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) URI(java.net.URI) Session(javax.websocket.Session) WebSocketBaseTest(org.apache.tomcat.websocket.WebSocketBaseTest) Test(org.junit.Test)

Example 23 with DefaultServlet

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();
}
Also used : InitialContext(javax.naming.InitialContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) TesterEchoServer(org.apache.tomcat.websocket.TesterEchoServer) ApplicationListener(org.apache.catalina.deploy.ApplicationListener) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 24 with DefaultServlet

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();
}
Also used : InitialContext(javax.naming.InitialContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) TesterEchoServer(org.apache.tomcat.websocket.TesterEchoServer) ApplicationListener(org.apache.catalina.deploy.ApplicationListener) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 25 with DefaultServlet

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();
}
Also used : InitialContext(javax.naming.InitialContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) TesterEchoServer(org.apache.tomcat.websocket.TesterEchoServer) ApplicationListener(org.apache.catalina.deploy.ApplicationListener) ArrayList(java.util.ArrayList) DefaultServlet(org.apache.catalina.servlets.DefaultServlet) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

DefaultServlet (org.apache.catalina.servlets.DefaultServlet)93 Context (org.apache.catalina.Context)91 Tomcat (org.apache.catalina.startup.Tomcat)91 Test (org.junit.Test)70 URI (java.net.URI)59 Session (jakarta.websocket.Session)39 WebSocketContainer (jakarta.websocket.WebSocketContainer)36 Session (javax.websocket.Session)30 WebSocketContainer (javax.websocket.WebSocketContainer)27 TesterProgrammaticEndpoint (org.apache.tomcat.websocket.TesterMessageCountClient.TesterProgrammaticEndpoint)27 CountDownLatch (java.util.concurrent.CountDownLatch)24 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)24 ClientEndpointConfig (jakarta.websocket.ClientEndpointConfig)23 ClientEndpointConfig (javax.websocket.ClientEndpointConfig)19 TesterEndpoint (org.apache.tomcat.websocket.TesterMessageCountClient.TesterEndpoint)19 BasicText (org.apache.tomcat.websocket.TesterMessageCountClient.BasicText)18 Endpoint (jakarta.websocket.Endpoint)15 ServerEndpoint (jakarta.websocket.server.ServerEndpoint)15 ServerEndpoint (javax.websocket.server.ServerEndpoint)14 Endpoint (javax.websocket.Endpoint)13