use of org.apache.catalina.Wrapper 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.Wrapper 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.Wrapper in project tomcat by apache.
the class TestSsl method testRenegotiateWorks.
@Test
public void testRenegotiateWorks() throws Exception {
Tomcat tomcat = getTomcatInstance();
Assume.assumeTrue("SSL renegotiation has to be supported for this test", TesterSupport.isClientRenegotiationSupported(getTomcatInstance()));
Context root = tomcat.addContext("", TEMP_DIR);
Wrapper w = Tomcat.addServlet(root, "tester", new TesterServlet());
w.setAsyncSupported(true);
root.addServletMappingDecoded("/", "tester");
TesterSupport.initSsl(tomcat);
tomcat.start();
SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(null, TesterSupport.getTrustManagers(), null);
SSLSocketFactory socketFactory = sslCtx.getSocketFactory();
SSLSocket socket = (SSLSocket) socketFactory.createSocket("localhost", getPort());
OutputStream os = socket.getOutputStream();
InputStream is = socket.getInputStream();
Reader r = new InputStreamReader(is);
doRequest(os, r);
TesterHandshakeListener listener = new TesterHandshakeListener();
socket.addHandshakeCompletedListener(listener);
socket.startHandshake();
// One request should be sufficient
int requestCount = 0;
int listenerComplete = 0;
try {
while (requestCount < 10) {
requestCount++;
doRequest(os, r);
if (listener.isComplete() && listenerComplete == 0) {
listenerComplete = requestCount;
}
}
} catch (AssertionError | IOException e) {
String message = "Failed on request number " + requestCount + " after startHandshake(). " + e.getMessage();
log.error(message, e);
Assert.fail(message);
}
Assert.assertTrue(listener.isComplete());
System.out.println("Renegotiation completed after " + listenerComplete + " requests");
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class ContainerBase method getMBeanKeyProperties.
@Override
public String getMBeanKeyProperties() {
Container c = this;
StringBuilder keyProperties = new StringBuilder();
int containerCount = 0;
// each container
while (!(c instanceof Engine)) {
if (c instanceof Wrapper) {
keyProperties.insert(0, ",servlet=");
keyProperties.insert(9, c.getName());
} else if (c instanceof Context) {
keyProperties.insert(0, ",context=");
ContextName cn = new ContextName(c.getName(), false);
keyProperties.insert(9, cn.getDisplayName());
} else if (c instanceof Host) {
keyProperties.insert(0, ",host=");
keyProperties.insert(6, c.getName());
} else if (c == null) {
// May happen in unit testing and/or some embedding scenarios
keyProperties.append(",container");
keyProperties.append(containerCount++);
keyProperties.append("=null");
break;
} else {
// Should never happen...
keyProperties.append(",container");
keyProperties.append(containerCount++);
keyProperties.append('=');
keyProperties.append(c.getName());
}
c = c.getParent();
}
return keyProperties.toString();
}
use of org.apache.catalina.Wrapper in project tomcat by apache.
the class StandardContext method removeServletMapping.
/**
* Remove any servlet mapping for the specified pattern, if it exists;
* otherwise, no action is taken.
*
* @param pattern URL pattern of the mapping to remove
*/
@Override
public void removeServletMapping(String pattern) {
String name = null;
synchronized (servletMappingsLock) {
name = servletMappings.remove(pattern);
}
Wrapper wrapper = (Wrapper) findChild(name);
if (wrapper != null) {
wrapper.removeMapping(pattern);
}
fireContainerEvent("removeServletMapping", pattern);
}
Aggregations