use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestWebSocketFrameClient method testConnectToRootEndpoint.
@Test
public void testConnectToRootEndpoint() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
Context ctx2 = tomcat.addContext("/foo", null);
ctx2.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx2, "default", new DefaultServlet());
ctx2.addServletMappingDecoded("/", "default");
tomcat.start();
echoTester("", null);
echoTester("/", null);
// This will trigger a redirect so there will be 5 requests logged
echoTester("/foo", null);
echoTester("/foo/", null);
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestWebSocketFrameClient method testConnectToServerEndpoint.
@Test
public void testConnectToServerEndpoint() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(TesterFirehoseServer.ConfigInline.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
tomcat.start();
WebSocketContainer wsContainer = ContainerProvider.getWebSocketContainer();
// BZ 62596
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().configurator(new Configurator() {
@Override
public void beforeRequest(Map<String, List<String>> headers) {
headers.put("Dummy", Collections.singletonList(String.join("", Collections.nCopies(4000, "A"))));
super.beforeRequest(headers);
}
}).build();
Session wsSession = wsContainer.connectToServer(TesterProgrammaticEndpoint.class, clientEndpointConfig, new URI("ws://localhost:" + getPort() + TesterFirehoseServer.PATH));
CountDownLatch latch = new CountDownLatch(TesterFirehoseServer.MESSAGE_COUNT);
BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
wsSession.getBasicRemote().sendText("Hello");
System.out.println("Sent Hello message, waiting for data");
// Ignore the latch result as the message count test below will tell us
// if the right number of messages arrived
handler.getLatch().await(TesterFirehoseServer.WAIT_TIME_MILLIS, TimeUnit.MILLISECONDS);
Queue<String> messages = handler.getMessages();
Assert.assertEquals(TesterFirehoseServer.MESSAGE_COUNT, messages.size());
for (String message : messages) {
Assert.assertEquals(TesterFirehoseServer.MESSAGE, message);
}
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestWebSocketFrameClient method testConnectToBasicEndpoint.
@Test
public void testConnectToBasicEndpoint() throws Exception {
Tomcat tomcat = getTomcatInstance();
Context ctx = tomcat.addContext(URI_PROTECTED, null);
ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMappingDecoded("/", "default");
SecurityCollection collection = new SecurityCollection();
collection.addPatternDecoded("/");
String utf8User = "test";
// pound sign
String utf8Pass = "123\u00A3";
tomcat.addUser(utf8User, utf8Pass);
tomcat.addRole(utf8User, ROLE);
SecurityConstraint sc = new SecurityConstraint();
sc.addAuthRole(ROLE);
sc.addCollection(collection);
ctx.addConstraint(sc);
LoginConfig lc = new LoginConfig();
lc.setAuthMethod("BASIC");
ctx.setLoginConfig(lc);
AuthenticatorBase basicAuthenticator = new org.apache.catalina.authenticator.BasicAuthenticator();
ctx.getPipeline().addValve(basicAuthenticator);
tomcat.start();
ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().build();
clientEndpointConfig.getUserProperties().put(Constants.WS_AUTHENTICATION_USER_NAME, utf8User);
clientEndpointConfig.getUserProperties().put(Constants.WS_AUTHENTICATION_PASSWORD, utf8Pass);
echoTester(URI_PROTECTED, clientEndpointConfig);
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestEncodingDecoding method testMessagesEndPoints.
@Test
public void testMessagesEndPoints() throws Exception {
// Set up utility classes
MessagesServer server = new MessagesServer();
SingletonConfigurator.setInstance(server);
ServerConfigListener.setPojoClazz(MessagesServer.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();
StringClient client = new StringClient();
URI uri = new URI("ws://localhost:" + getPort() + PATH_MESSAGES_EP);
Session session = wsContainer.connectToServer(client, uri);
session.getBasicRemote().sendText(MESSAGE_ONE);
// Should not take very long
int i = 0;
while (i < WAIT_LOOPS) {
if (server.received.size() > 0 && client.received.size() > 1) {
break;
}
i++;
Thread.sleep(WAIT_DELAY);
}
// Check messages were received
Assert.assertEquals(1, server.received.size());
Assert.assertEquals(2, client.received.size());
// Check correct messages were received
Assert.assertEquals(MESSAGE_ONE, server.received.peek());
session.close();
Assert.assertNull(server.t);
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat by apache.
the class TestEncodingDecoding method testGenericsCoders.
@Test
public void testGenericsCoders() throws Exception {
// Set up utility classes
GenericsServer server = new GenericsServer();
SingletonConfigurator.setInstance(server);
ServerConfigListener.setPojoClazz(GenericsServer.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();
GenericsClient client = new GenericsClient();
URI uri = new URI("ws://localhost:" + getPort() + PATH_GENERICS_EP);
Session session = wsContainer.connectToServer(client, uri);
ArrayList<String> list = new ArrayList<>(2);
list.add("str1");
list.add("str2");
session.getBasicRemote().sendObject(list);
// Should not take very long
int i = 0;
while (i < WAIT_LOOPS) {
if (server.received.size() > 0 && client.received.size() > 0) {
break;
}
i++;
Thread.sleep(WAIT_DELAY);
}
// Check messages were received
Assert.assertEquals(1, server.received.size());
Assert.assertEquals(server.received.peek().toString(), "[str1, str2]");
Assert.assertEquals(1, client.received.size());
Assert.assertEquals(client.received.peek().toString(), "[str1, str2]");
session.close();
}
Aggregations