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();
}
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());
}
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());
}
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());
}
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());
}
Aggregations