Search in sources :

Example 76 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class TestAbortedUpload method configureAndStartWebApplication.

@Override
protected void configureAndStartWebApplication() throws LifecycleException {
    Tomcat tomcat = getTomcatInstance();
    // Retain '/simple' url-pattern since it enables code re-use
    Context ctxt = tomcat.addContext("", null);
    Tomcat.addServlet(ctxt, "abort", new AbortServlet());
    ctxt.addServletMappingDecoded("/simple", "abort");
    tomcat.start();
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat)

Example 77 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class TestStreamQueryString method testQueryString.

@Test
public void testQueryString() throws Exception {
    String queryValue = "xxx" + queryValueToTest + "xxx";
    enableHttp2();
    Tomcat tomcat = getTomcatInstance();
    Context ctxt = tomcat.addContext("", null);
    Tomcat.addServlet(ctxt, "simple", new SimpleServlet());
    ctxt.addServletMappingDecoded("/simple", "simple");
    Tomcat.addServlet(ctxt, "query", new Query(queryValue));
    ctxt.addServletMappingDecoded("/query", "query");
    tomcat.start();
    openClientConnection();
    doHttpUpgrade();
    sendClientPreface();
    validateHttp2InitialResponse();
    byte[] frameHeader = new byte[9];
    ByteBuffer headersPayload = ByteBuffer.allocate(128);
    buildGetRequest(frameHeader, headersPayload, null, 3, "/query?" + Query.PARAM_NAME + "=" + queryValue);
    writeFrame(frameHeader, headersPayload);
    readSimpleGetResponse();
    Assert.assertEquals(queryValue, "3-HeadersStart\n" + "3-Header-[:status]-[200]\n" + "3-Header-[content-type]-[text/plain;charset=UTF-8]\n" + "3-Header-[date]-[Wed, 11 Nov 2015 19:18:42 GMT]\n" + "3-HeadersEnd\n" + "3-Body-2\n" + "3-EndOfStream\n", output.getTrace());
}
Also used : Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 78 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class TestStreamProcessor method testAsyncDispatch.

@Test
public void testAsyncDispatch() throws Exception {
    enableHttp2();
    Tomcat tomcat = getTomcatInstance();
    // Map the async servlet to /simple so we can re-use the HTTP/2 handling
    // logic from the super class.
    Context ctxt = tomcat.addContext("", null);
    Tomcat.addServlet(ctxt, "simple", new SimpleServlet());
    ctxt.addServletMappingDecoded("/simple", "simple");
    Wrapper w = Tomcat.addServlet(ctxt, "async", new AsyncDispatch());
    w.setAsyncSupported(true);
    ctxt.addServletMappingDecoded("/async", "async");
    tomcat.start();
    openClientConnection();
    doHttpUpgrade();
    sendClientPreface();
    validateHttp2InitialResponse();
    byte[] frameHeader = new byte[9];
    ByteBuffer headersPayload = ByteBuffer.allocate(128);
    buildGetRequest(frameHeader, headersPayload, null, 3, "/async");
    writeFrame(frameHeader, headersPayload);
    readSimpleGetResponse();
    Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace());
}
Also used : Context(org.apache.catalina.Context) AsyncContext(javax.servlet.AsyncContext) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 79 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class TestStreamProcessor method testAsyncComplete.

@Test
public void testAsyncComplete() throws Exception {
    enableHttp2();
    Tomcat tomcat = getTomcatInstance();
    // Map the async servlet to /simple so we can re-use the HTTP/2 handling
    // logic from the super class.
    Context ctxt = tomcat.addContext("", null);
    Tomcat.addServlet(ctxt, "simple", new SimpleServlet());
    ctxt.addServletMappingDecoded("/simple", "simple");
    Wrapper w = Tomcat.addServlet(ctxt, "async", new AsyncComplete());
    w.setAsyncSupported(true);
    ctxt.addServletMappingDecoded("/async", "async");
    tomcat.start();
    openClientConnection();
    doHttpUpgrade();
    sendClientPreface();
    validateHttp2InitialResponse();
    byte[] frameHeader = new byte[9];
    ByteBuffer headersPayload = ByteBuffer.allocate(128);
    buildGetRequest(frameHeader, headersPayload, null, 3, "/async");
    writeFrame(frameHeader, headersPayload);
    readSimpleGetResponse();
    // Flush before startAsync means body is written in two packets so an
    // additional frame needs to be read
    parser.readFrame(true);
    Assert.assertEquals("3-HeadersStart\n" + "3-Header-[:status]-[200]\n" + "3-Header-[content-type]-[text/plain;charset=UTF-8]\n" + "3-Header-[date]-[Wed, 11 Nov 2015 19:18:42 GMT]\n" + "3-HeadersEnd\n" + "3-Body-17\n" + "3-Body-8\n" + "3-EndOfStream\n", output.getTrace());
}
Also used : Context(org.apache.catalina.Context) AsyncContext(javax.servlet.AsyncContext) Wrapper(org.apache.catalina.Wrapper) Tomcat(org.apache.catalina.startup.Tomcat) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 80 with Context

use of org.apache.catalina.Context in project tomcat by apache.

the class TesterSupport method configureClientCertContext.

protected static void configureClientCertContext(Tomcat tomcat) {
    TesterSupport.initSsl(tomcat);
    // Need a web application with a protected and unprotected URL
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    Tomcat.addServlet(ctx, "simple", new SimpleServlet());
    ctx.addServletMappingDecoded("/unprotected", "simple");
    ctx.addServletMappingDecoded("/protected", "simple");
    // Security constraints
    SecurityCollection collection = new SecurityCollection();
    collection.addPatternDecoded("/protected");
    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    ctx.addConstraint(sc);
    // Configure the Realm
    TesterMapRealm realm = new TesterMapRealm();
    realm.addUser("CN=user1, C=US", "not used");
    realm.addUserRole("CN=user1, C=US", ROLE);
    ctx.setRealm(realm);
    // Configure the authenticator
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("CLIENT-CERT");
    ctx.setLoginConfig(lc);
    ctx.getPipeline().addValve(new SSLAuthenticator());
}
Also used : SSLContext(javax.net.ssl.SSLContext) Context(org.apache.catalina.Context) TesterMapRealm(org.apache.catalina.startup.TesterMapRealm) SSLAuthenticator(org.apache.catalina.authenticator.SSLAuthenticator) LoginConfig(org.apache.tomcat.util.descriptor.web.LoginConfig) SecurityConstraint(org.apache.tomcat.util.descriptor.web.SecurityConstraint) SecurityCollection(org.apache.tomcat.util.descriptor.web.SecurityCollection)

Aggregations

Context (org.apache.catalina.Context)376 Tomcat (org.apache.catalina.startup.Tomcat)212 Test (org.junit.Test)180 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)127 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)96 File (java.io.File)77 ServletContext (javax.servlet.ServletContext)74 AsyncContext (javax.servlet.AsyncContext)73 StandardContext (org.apache.catalina.core.StandardContext)65 Wrapper (org.apache.catalina.Wrapper)53 IOException (java.io.IOException)40 TesterContext (org.apache.tomcat.unittest.TesterContext)39 DefaultServlet (org.apache.catalina.servlets.DefaultServlet)37 URI (java.net.URI)33 WebSocketContainer (javax.websocket.WebSocketContainer)32 Session (javax.websocket.Session)31 Host (org.apache.catalina.Host)30 Container (org.apache.catalina.Container)26 ArrayList (java.util.ArrayList)25 ServletRequestWrapper (javax.servlet.ServletRequestWrapper)24