本文整理汇总了Java中org.apache.catalina.Wrapper.setAsyncSupported方法的典型用法代码示例。如果您正苦于以下问题:Java Wrapper.setAsyncSupported方法的具体用法?Java Wrapper.setAsyncSupported怎么用?Java Wrapper.setAsyncSupported使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.catalina.Wrapper
的用法示例。
在下文中一共展示了Wrapper.setAsyncSupported方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAsyncContextListenerClearing
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testAsyncContextListenerClearing() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Servlet stage1 = new DispatchingServletTracking("/stage2", true);
Wrapper wrapper1 = Tomcat.addServlet(ctx, "stage1", stage1);
wrapper1.setAsyncSupported(true);
ctx.addServletMapping("/stage1", "stage1");
Servlet stage2 = new DispatchingServletTracking("/stage3", false);
Wrapper wrapper2 = Tomcat.addServlet(ctx, "stage2", stage2);
wrapper2.setAsyncSupported(true);
ctx.addServletMapping("/stage2", "stage2");
Servlet stage3 = new NonAsyncServlet();
Tomcat.addServlet(ctx, "stage3", stage3);
ctx.addServletMapping("/stage3", "stage3");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
getUrl("http://localhost:" + getPort()+ "/stage1");
assertEquals("doGet-startAsync-doGet-startAsync-onStartAsync-NonAsyncServletGet-onComplete-", getTrack());
// Check the access log
alv.validateAccessLog(1, 200, 0, REQUEST_TIME);
}
示例2: testBug49528
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testBug49528() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug49528Servlet servlet = new Bug49528Servlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet once
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("OK", bc.toString());
// Give the async thread a chance to finish (but not too long)
int counter = 0;
while (!servlet.isDone() && counter < 10) {
Thread.sleep(1000);
counter++;
}
assertEquals("1false2true3true4true5false", servlet.getResult());
// Check the access log
alv.validateAccessLog(1, 200, Bug49528Servlet.THREAD_SLEEP_TIME,
Bug49528Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
示例3: testBug49567
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testBug49567() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug49567Servlet servlet = new Bug49567Servlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet once
ByteChunk bc = getUrl("http://localhost:" + getPort() + "/");
assertEquals("OK", bc.toString());
// Give the async thread a chance to finish (but not too long)
int counter = 0;
while (!servlet.isDone() && counter < 10) {
Thread.sleep(1000);
counter++;
}
assertEquals("1false2true3true4true5false", servlet.getResult());
// Check the access log
alv.validateAccessLog(1, 200, Bug49567Servlet.THREAD_SLEEP_TIME,
Bug49567Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
示例4: testBug50753
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testBug50753() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Bug50753Servlet servlet = new Bug50753Servlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet once
Map<String,List<String>> headers = new LinkedHashMap<String,List<String>>();
ByteChunk bc = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() + "/", bc, headers);
assertEquals(200, rc);
assertEquals("OK", bc.toString());
List<String> testHeader = headers.get("A");
assertNotNull(testHeader);
assertEquals(1, testHeader.size());
assertEquals("xyz",testHeader.get(0));
// Check the access log
alv.validateAccessLog(1, 200, Bug50753Servlet.THREAD_SLEEP_TIME,
Bug50753Servlet.THREAD_SLEEP_TIME + REQUEST_TIME);
}
示例5: testBug53337
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testBug53337() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
Wrapper a = Tomcat.addServlet(ctx, "ServletA", new Bug53337ServletA());
a.setAsyncSupported(true);
Wrapper b = Tomcat.addServlet(ctx, "ServletB", new Bug53337ServletB());
b.setAsyncSupported(true);
Tomcat.addServlet(ctx, "ServletC", new Bug53337ServletC());
ctx.addServletMapping("/ServletA", "ServletA");
ctx.addServletMapping("/ServletB", "ServletB");
ctx.addServletMapping("/ServletC", "ServletC");
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/ServletA");
ByteChunk body = new ByteChunk();
int rc = getUrl(url.toString(), body, null);
assertEquals(HttpServletResponse.SC_OK, rc);
assertEquals("OK", body.toString());
}
示例6: testCommitOnComplete
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testCommitOnComplete() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStatusServlet asyncStatusServlet =
new AsyncStatusServlet(HttpServletResponse.SC_BAD_REQUEST);
Wrapper wrapper =
Tomcat.addServlet(ctx, "asyncStatusServlet", asyncStatusServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/asyncStatusServlet", "asyncStatusServlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/asyncStatusServlet");
int rc = getUrl(url.toString(), new ByteChunk(), null);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
// Without this test may complete before access log has a chance to log
// the request
Thread.sleep(REQUEST_TIME);
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0,
REQUEST_TIME);
}
示例7: doTestAsyncISE
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
private void doTestAsyncISE(boolean useGetRequest) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncISEServlet servlet = new AsyncISEServlet();
Wrapper w = Tomcat.addServlet(ctx, "AsyncISEServlet", servlet);
w.setAsyncSupported(true);
ctx.addServletMapping("/test", "AsyncISEServlet");
tomcat.start();
ByteChunk response = new ByteChunk();
int rc = getUrl("http://localhost:" + getPort() +"/test", response,
null);
Assert.assertEquals(HttpServletResponse.SC_OK, rc);
boolean hasIse = false;
try {
if (useGetRequest) {
servlet.getAsyncContext().getRequest();
} else {
servlet.getAsyncContext().getResponse();
}
} catch (IllegalStateException ise) {
hasIse = true;
}
Assert.assertTrue(hasIse);
}
示例8: testBug57621
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testBug57621() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Must have a real docBase - just use temp
Context root = tomcat.addContext("", System.getProperty("java.io.tmpdir"));
Wrapper w = Tomcat.addServlet(root, "Bug57621", new Bug57621Servlet());
w.setAsyncSupported(true);
root.addServletMapping("/test", "Bug57621");
tomcat.start();
Bug57621Client client = new Bug57621Client();
client.setPort(tomcat.getConnector().getLocalPort());
client.setUseContentLength(true);
client.connect();
client.doRequest();
assertTrue(client.getResponseLine(), client.isResponse200());
assertTrue(client.isResponseBodyOK());
// Do the request again to ensure that the remaining body was swallowed
client.resetResponse();
client.processRequest();
assertTrue(client.isResponse200());
assertTrue(client.isResponseBodyOK());
client.disconnect();
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:34,代码来源:TestAbstractHttp11Processor.java
示例9: testListeners
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testListeners() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
TrackingServlet tracking = new TrackingServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "tracking", tracking);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/stage1", "tracking");
TimeoutServlet timeout = new TimeoutServlet(Boolean.TRUE, null);
Wrapper wrapper2 = Tomcat.addServlet(ctx, "timeout", timeout);
wrapper2.setAsyncSupported(true);
ctx.addServletMapping("/stage2", "timeout");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/stage1");
getUrl(url.toString());
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = "DispatchingServletGet-DispatchingServletGet-" +
"onStartAsync-TimeoutServletGet-onStartAsync-onTimeout-" +
"onComplete-";
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count ++;
}
Assert.assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 200, TimeoutServlet.ASYNC_TIMEOUT,
TimeoutServlet.ASYNC_TIMEOUT + TIMEOUT_MARGIN + REQUEST_TIME);
}
示例10: testForbiddenDispatching
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testForbiddenDispatching() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
NonAsyncServlet nonAsyncServlet = new NonAsyncServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "nonAsyncServlet",
nonAsyncServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/target", "nonAsyncServlet");
DispatchingGenericServlet forbiddenDispatchingServlet = new DispatchingGenericServlet();
Wrapper wrapper1 = Tomcat.addServlet(ctx,
"forbiddenDispatchingServlet", forbiddenDispatchingServlet);
wrapper1.setAsyncSupported(true);
ctx.addServletMapping("/forbiddenDispatchingServlet",
"forbiddenDispatchingServlet");
tomcat.start();
try {
getUrl("http://localhost:" + getPort()
+ "/forbiddenDispatchingServlet");
} catch (IOException ioe) {
// This may happen if test fails. Output the exception in case it is
// useful and let asserts handle the failure
ioe.printStackTrace();
}
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = "OKNonAsyncServletGet-";
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count ++;
}
Assert.assertEquals(expectedTrack, getTrack());
}
示例11: testAsyncStartNoComplete
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testAsyncStartNoComplete() throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// Minimise pauses during test
tomcat.getConnector().setAttribute(
"connectionTimeout", Integer.valueOf(3000));
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncStartNoCompleteServlet servlet =
new AsyncStartNoCompleteServlet();
Wrapper wrapper = Tomcat.addServlet(ctx, "servlet", servlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/", "servlet");
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
// Call the servlet the first time
getUrl("http://localhost:" + getPort() + "/?echo=run1");
Assert.assertEquals("OK-run1", getTrack());
resetTracker();
// Call the servlet the second time with a request parameter
getUrl("http://localhost:" + getPort() + "/?echo=run2");
Assert.assertEquals("OK-run2", getTrack());
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
// Check the access log
alv.validateAccessLog(2, 500,
AsyncStartNoCompleteServlet.ASYNC_TIMEOUT,
AsyncStartNoCompleteServlet.ASYNC_TIMEOUT + TIMEOUT_MARGIN +
REQUEST_TIME);
}
示例12: doTestDispatchError
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
private void doTestDispatchError(int iter, boolean useThread,
boolean completeOnError)
throws Exception {
resetTracker();
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
DispatchingServlet dispatch =
new DispatchingServlet(true, completeOnError);
Wrapper wrapper = Tomcat.addServlet(ctx, "dispatch", dispatch);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/stage1", "dispatch");
ErrorServlet error = new ErrorServlet();
Tomcat.addServlet(ctx, "error", error);
ctx.addServletMapping("/stage2", "error");
ctx.addApplicationListener(TrackingRequestListener.class.getName());
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/stage1?iter=");
url.append(iter);
if (useThread) {
url.append("&useThread=y");
}
getUrl(url.toString());
StringBuilder expected = new StringBuilder("requestInitialized-");
int loop = iter;
while (loop > 0) {
expected.append("DispatchingServletGet-");
if (loop != iter) {
expected.append("onStartAsync-");
}
loop--;
}
expected.append("ErrorServletGet-onError-onComplete-requestDestroyed");
// Request may complete before listener has finished processing so wait
// up to 5 seconds for the right response
String expectedTrack = expected.toString();
int count = 0;
while (!expectedTrack.equals(getTrack()) && count < 100) {
Thread.sleep(50);
count ++;
}
assertEquals(expectedTrack, getTrack());
// Check the access log
alv.validateAccessLog(1, 500, 0, REQUEST_TIME);
}
示例13: doTestBug51197
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
private void doTestBug51197(boolean threaded, boolean customError) throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncErrorServlet asyncErrorServlet =
new AsyncErrorServlet(HttpServletResponse.SC_BAD_REQUEST, threaded);
Wrapper wrapper =
Tomcat.addServlet(ctx, "asyncErrorServlet", asyncErrorServlet);
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/asyncErrorServlet", "asyncErrorServlet");
if (customError) {
CustomErrorServlet customErrorServlet = new CustomErrorServlet();
Tomcat.addServlet(ctx, "customErrorServlet", customErrorServlet);
ctx.addServletMapping("/customErrorServlet", "customErrorServlet");
ErrorPage ep = new ErrorPage();
ep.setLocation("/customErrorServlet");
ctx.addErrorPage(ep);
}
TesterAccessLogValve alv = new TesterAccessLogValve();
ctx.getPipeline().addValve(alv);
tomcat.start();
StringBuilder url = new StringBuilder(48);
url.append("http://localhost:");
url.append(getPort());
url.append("/asyncErrorServlet");
ByteChunk res = new ByteChunk();
int rc = getUrl(url.toString(), res, null);
assertEquals(HttpServletResponse.SC_BAD_REQUEST, rc);
// SRV 10.9.2 - Handling an error is entirely the application's
// responsibility when an error occurs on an application thread.
// Calling sendError() followed by complete() and expecting the standard
// error page mechanism to kick in could be viewed as handling the error
String responseBody = res.toString();
Assert.assertNotNull(responseBody);
assertTrue(responseBody.length() > 0);
if (customError) {
assertTrue(responseBody, responseBody.contains(CustomErrorServlet.ERROR_MESSAGE));
} else {
assertTrue(responseBody, responseBody.contains(AsyncErrorServlet.ERROR_MESSAGE));
}
// Without this test may complete before access log has a chance to log
// the request
Thread.sleep(REQUEST_TIME);
// Check the access log
alv.validateAccessLog(1, HttpServletResponse.SC_BAD_REQUEST, 0,
REQUEST_TIME);
}
示例14: testBug54928
import org.apache.catalina.Wrapper; //导入方法依赖的package包/类
@Test
public void testBug54928() throws Exception {
// Setup Tomcat instance
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
AsyncServlet servlet = new AsyncServlet();
Wrapper w = Tomcat.addServlet(ctx, "async", servlet);
w.setAsyncSupported(true);
ctx.addServletMapping("/async", "async");
tomcat.start();
SimpleHttpClient client = new SimpleHttpClient() {
@Override
public boolean isResponseBodyOK() {
return true;
}
};
String request = "GET /async HTTP/1.1" + SimpleHttpClient.CRLF +
"Host: a" + SimpleHttpClient.CRLF + SimpleHttpClient.CRLF;
client.setPort(getPort());
client.setRequest(new String[] {request});
client.connect();
client.sendRequest();
for (int i = 0; i < 10; i++) {
String line = client.readLine();
if (line != null && line.length() > 20) {
log.info(line.subSequence(0, 20) + "...");
}
}
client.disconnect();
// Wait for server thread to stop
Thread t = servlet.getThread();
long startTime = System.nanoTime();
t.join(5000);
long endTime = System.nanoTime();
log.info("Waited for servlet thread to stop for "
+ (endTime - startTime) / 1000000 + " ms");
Assert.assertTrue(servlet.isCompleted());
}