use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 by apache.
the class TestWsWebSocketContainer method testSessionExpiryContainer.
@Test
public void testSessionExpiryContainer() 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.addServletMapping("/", "default");
tomcat.start();
// Need access to implementation methods for configuring unit tests
WsWebSocketContainer wsContainer = (WsWebSocketContainer) ContainerProvider.getWebSocketContainer();
// 5 second timeout
wsContainer.setDefaultMaxSessionIdleTimeout(5000);
wsContainer.setProcessPeriod(1);
EndpointA endpointA = new EndpointA();
connectToEchoServer(wsContainer, endpointA, TesterEchoServer.Config.PATH_BASIC);
connectToEchoServer(wsContainer, endpointA, TesterEchoServer.Config.PATH_BASIC);
Session s3a = connectToEchoServer(wsContainer, endpointA, TesterEchoServer.Config.PATH_BASIC);
// Check all three sessions are open
Set<Session> setA = s3a.getOpenSessions();
Assert.assertEquals(3, setA.size());
int count = 0;
boolean isOpen = true;
while (isOpen && count < 8) {
count++;
Thread.sleep(1000);
isOpen = false;
for (Session session : setA) {
if (session.isOpen()) {
isOpen = true;
break;
}
}
}
if (isOpen) {
for (Session session : setA) {
if (session.isOpen()) {
System.err.println("Session with ID [" + session.getId() + "] is open");
}
}
Assert.fail("There were open sessions");
}
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 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.addServletMapping("/", "default");
Context ctx2 = tomcat.addContext("/foo", null);
ctx2.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx2, "default", new DefaultServlet());
ctx2.addServletMapping("/", "default");
tomcat.start();
echoTester("", null);
echoTester("/", null);
echoTester("/foo", null);
echoTester("/foo/", null);
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 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.addServletMapping("/", "default");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/");
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 tomcat70 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.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "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() + TesterFirehoseServer.Config.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 tomcat70 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.addServletMapping("/", "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());
}
Aggregations