use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestPojoEndpointBase method testOnOpenPojoMethod.
@Test
public void testOnOpenPojoMethod() throws Exception {
// Set up utility classes
OnOpenServerEndpoint server = new OnOpenServerEndpoint();
SingletonConfigurator.setInstance(server);
ServerConfigListener.setPojoClazz(OnOpenServerEndpoint.class);
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(ServerConfigListener.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
tomcat.start();
Client client = new Client();
URI uri = new URI("ws://localhost:" + getPort() + "/");
Session session = wsContainer.connectToServer(client, uri);
client.waitForClose(5);
Assert.assertTrue(session.isOpen());
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestCloseBug58624 method testOnErrorNotCalledWhenClosingConnection.
@Test
public void testOnErrorNotCalledWhenClosingConnection() throws Throwable {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(Bug58624ServerConfig.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
tomcat.start();
Bug58624ClientEndpoint client = new Bug58624ClientEndpoint();
URI uri = new URI("ws://localhost:" + getPort() + Bug58624ServerConfig.PATH);
Session session = wsContainer.connectToServer(client, uri);
// Wait for session to open on the server
int count = 0;
while (count < 50 && Bug58624ServerEndpoint.getOpenSessionCount() == 0) {
count++;
Thread.sleep(100);
}
Assert.assertNotEquals(0, Bug58624ServerEndpoint.getOpenSessionCount());
// Now close the session
session.close();
// Wait for session to close on the server
count = 0;
while (count < 50 && Bug58624ServerEndpoint.getOpenSessionCount() > 0) {
count++;
Thread.sleep(100);
}
Assert.assertEquals(0, Bug58624ServerEndpoint.getOpenSessionCount());
// Ensure no errors were reported on the server
Assert.assertEquals(0, Bug58624ServerEndpoint.getErrorCount());
if (client.getError() != null) {
throw client.getError();
}
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestSlowClient method testSendingFromAppThread.
@Test
public void testSendingFromAppThread() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context ctx = tomcat.addContext("", null);
// Server side endpoint that sends a stream of messages on a new thread
// in response to any message received.
ctx.addApplicationListener(TesterFirehoseServer.ConfigThread.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
// WebSocket client
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class, ClientEndpointConfig.Builder.create().build(), new URI("ws://localhost:" + getPort() + TesterFirehoseServer.PATH));
// Configure a handler designed to create a backlog causing the server
// side write to time out.
wsSession.addMessageHandler(new VerySlowHandler());
// Trigger the sending of the messages from the server
wsSession.getBasicRemote().sendText("start");
// Wait for server to close connection (it shouldn't)
// 20s should be long enough even for the slowest CI system. May need to
// extend this if not.
int count = 0;
while (wsSession.isOpen() && count < 200) {
Thread.sleep(100);
count++;
}
Assert.assertTrue(wsSession.isOpen());
wsSession.close();
// BZ 64848 (non-container thread variant)
// Confirm there are no waiting processors
AbstractProtocol<?> protocol = (AbstractProtocol<?>) tomcat.getConnector().getProtocolHandler();
Assert.assertEquals(0, protocol.getWaitingProcessorCount());
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat 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.addServletMappingDecoded("/", "default");
tomcat.start();
Assert.assertEquals(LifecycleState.STARTED, ctx.getState());
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestWsServerContainer method testBug58232.
@Test
public void testBug58232() 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.addServletMappingDecoded("/", "default");
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
tomcat.start();
Assert.assertEquals(LifecycleState.STARTED, ctx.getState());
SimpleClient client = new SimpleClient();
URI uri = new URI("ws://localhost:" + getPort() + "/echoBasic");
try (Session session = wsContainer.connectToServer(client, uri)) {
CountDownLatch latch = new CountDownLatch(1);
BasicText handler = new BasicText(latch);
session.addMessageHandler(handler);
session.getBasicRemote().sendText("echoBasic");
boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
Assert.assertTrue(latchResult);
Queue<String> messages = handler.getMessages();
Assert.assertEquals(1, messages.size());
for (String message : messages) {
Assert.assertEquals("echoBasic", message);
}
}
}
Aggregations