use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestEncodingDecoding method testUnsupportedObject.
@Test
public void testUnsupportedObject() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(ProgrammaticServerEndpointConfig.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() + PATH_PROGRAMMATIC_EP);
Session session = wsContainer.connectToServer(client, uri);
// This should fail
Object msg1 = new Object();
try {
session.getBasicRemote().sendObject(msg1);
Assert.fail("No exception thrown ");
} catch (EncodeException e) {
// Expected
} catch (Throwable t) {
Assert.fail("Wrong exception type");
} finally {
session.close();
}
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestEncodingDecoding method testProgrammaticEndPoints.
@Test
public void testProgrammaticEndPoints() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(ProgrammaticServerEndpointConfig.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() + PATH_PROGRAMMATIC_EP);
Session session = wsContainer.connectToServer(client, uri);
MsgString msg1 = new MsgString();
msg1.setData(MESSAGE_ONE);
session.getBasicRemote().sendObject(msg1);
// Should not take very long
int i = 0;
while (i < WAIT_LOOPS) {
if (MsgStringMessageHandler.received.size() > 0 && client.received.size() > 0) {
break;
}
i++;
Thread.sleep(WAIT_DELAY);
}
// Check messages were received
Assert.assertEquals(1, MsgStringMessageHandler.received.size());
Assert.assertEquals(1, client.received.size());
// Check correct messages were received
Assert.assertEquals(MESSAGE_ONE, ((MsgString) MsgStringMessageHandler.received.peek()).getData());
Assert.assertEquals(MESSAGE_ONE, new String(((MsgByte) client.received.peek()).getData()));
session.close();
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestPojoMethodMapping method test.
@Test
public void test() throws Exception {
// Set up utility classes
Server server = new Server();
SingletonConfigurator.setInstance(server);
ServerConfigListener.setPojoClazz(Server.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();
SimpleClient client = new SimpleClient();
URI uri = new URI("ws://localhost:" + getPort() + "/" + PARAM_ONE + "/" + PARAM_TWO + "/" + PARAM_THREE);
Session session = wsContainer.connectToServer(client, uri);
session.getBasicRemote().sendText("NO-OP");
session.close();
// Give server 20s to close. 5s should be plenty but the Gump VM is slow
int count = 0;
while (count < 200) {
if (server.isClosed()) {
break;
}
count++;
Thread.sleep(100);
}
if (count == 50) {
Assert.fail("Server did not process an onClose event within 5 " + "seconds of the client sending a close message");
}
// Check no errors
List<String> errors = server.getErrors();
for (String error : errors) {
System.err.println(error);
}
Assert.assertEquals("Found errors", 0, errors.size());
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestAsyncMessages method testAsyncTiming.
@Test
public void testAsyncTiming() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(TesterAsyncTiming.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class, clientEndpointConfig, new URI("ws://localhost:" + getPort() + TesterAsyncTiming.Config.PATH));
AsyncTimingClientHandler handler = new AsyncTimingClientHandler();
wsSession.addMessageHandler(ByteBuffer.class, handler);
wsSession.getBasicRemote().sendText("Hello");
System.out.println("Sent Hello message, waiting for data");
handler.waitForLatch();
Assert.assertFalse(handler.hasFailed());
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestPojoEndpointBase method testBug54716.
@Test
public void testBug54716() throws Exception {
TestUtil.generateMask();
// Set up utility classes
Bug54716 server = new Bug54716();
SingletonConfigurator.setInstance(server);
ServerConfigListener.setPojoClazz(Bug54716.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() + "/");
wsContainer.connectToServer(client, uri);
// Server should close the connection after the exception on open.
boolean closed = client.waitForClose(5);
Assert.assertTrue("Server failed to close connection", closed);
}
Aggregations