use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 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.addServletMapping("/", "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);
}
use of org.apache.catalina.servlets.DefaultServlet in project tomcat70 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.addServletMapping("/", "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 tomcat70 by apache.
the class TestWebSocket method testNoConnection.
@Test
public void testNoConnection() 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("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
String responseLine = client.reader.readLine();
Assert.assertTrue(responseLine.startsWith("HTTP/1.1 400"));
// Finished with the socket
client.close();
}
use of org.apache.catalina.servlets.DefaultServlet in project cxf by apache.
the class StatsServer method main.
public static void main(final String[] args) throws Exception {
// Register and map the dispatcher servlet
final File base = new File(System.getProperty("java.io.tmpdir"));
final Tomcat server = new Tomcat();
server.setPort(8686);
server.setBaseDir(base.getAbsolutePath());
final StandardContext context = (StandardContext) server.addWebapp("/", base.getAbsolutePath());
context.setConfigFile(StatsServer.class.getResource("/META-INF/context.xml"));
context.addApplicationListener(ContextLoaderListener.class.getName());
context.setAddWebinfClassesResources(true);
context.setResources(resourcesFrom(context, "target/classes"));
context.setParentClassLoader(Thread.currentThread().getContextClassLoader());
final Wrapper cxfServlet = Tomcat.addServlet(context, "cxfServlet", new CXFServlet());
cxfServlet.setAsyncSupported(true);
context.addServletMappingDecoded("/rest/*", "cxfServlet");
final Context staticContext = server.addWebapp("/static", base.getAbsolutePath());
Tomcat.addServlet(staticContext, "cxfStaticServlet", new DefaultServlet());
staticContext.addServletMappingDecoded("/static/*", "cxfStaticServlet");
staticContext.setResources(resourcesFrom(staticContext, "target/classes/web-ui"));
staticContext.setParentClassLoader(Thread.currentThread().getContextClassLoader());
server.start();
server.getServer().await();
}
use of org.apache.catalina.servlets.DefaultServlet in project Payara by payara.
the class StandardContext method setDirectoryListing.
/**
* Enables or disables directory listings on this <tt>Context</tt>.
*/
public void setDirectoryListing(boolean directoryListing) {
this.directoryListing = directoryListing;
Wrapper wrapper = (Wrapper) findChild(org.apache.catalina.core.Constants.DEFAULT_SERVLET_NAME);
if (wrapper != null) {
Servlet servlet = ((StandardWrapper) wrapper).getServlet();
if (servlet instanceof DefaultServlet) {
((DefaultServlet) servlet).setListings(directoryListing);
}
}
}
Aggregations