当前位置: 首页>>代码示例>>Java>>正文


Java Context.addServletMapping方法代码示例

本文整理汇总了Java中org.apache.catalina.Context.addServletMapping方法的典型用法代码示例。如果您正苦于以下问题:Java Context.addServletMapping方法的具体用法?Java Context.addServletMapping怎么用?Java Context.addServletMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.catalina.Context的用法示例。


在下文中一共展示了Context.addServletMapping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testTimeoutDispatchCustomErrorPage

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testTimeoutDispatchCustomErrorPage() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    Context context = tomcat.addContext("", null);
    tomcat.addServlet("", "timeout", Bug58751AsyncServlet.class.getName())
            .setAsyncSupported(true);
    CustomErrorServlet customErrorServlet = new CustomErrorServlet();
    Tomcat.addServlet(context, "customErrorServlet", customErrorServlet);
    context.addServletMapping("/timeout", "timeout");
    context.addServletMapping("/error", "customErrorServlet");
    ErrorPage errorPage = new ErrorPage();
    errorPage.setLocation("/error");
    context.addErrorPage(errorPage);
    tomcat.start();

    ByteChunk responseBody = new ByteChunk();
    int rc = getUrl("http://localhost:" + getPort() + "/timeout", responseBody, null);

    Assert.assertEquals(503, rc);
    Assert.assertEquals(CustomErrorServlet.ERROR_MESSAGE, responseBody.toString());
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:22,代码来源:TestAsyncContextImpl.java

示例2: doBug56501

import org.apache.catalina.Context; //导入方法依赖的package包/类
private void doBug56501(String deployPath, String requestPath, String expected)
        throws Exception {

    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext(deployPath, null);

    Tomcat.addServlet(ctx, "servlet", new Bug56501Servelet());
    ctx.addServletMapping("/*", "servlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + requestPath);
    String resultPath = res.toString();
    if (resultPath == null) {
        resultPath = "";
    }
    assertEquals(expected, resultPath);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:22,代码来源:TestRequest.java

示例3: testAsyncContextListenerClearing

import org.apache.catalina.Context; //导入方法依赖的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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:37,代码来源:TestAsyncContextImpl.java

示例4: testNoTrailingHeaders

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testNoTrailingHeaders() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "servlet", new EchoHeaderServlet(true));
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    String request =
        "POST /echo-params.jsp HTTP/1.1" + SimpleHttpClient.CRLF +
        "Host: any" + SimpleHttpClient.CRLF +
        "Transfer-encoding: chunked" + SimpleHttpClient.CRLF +
        "Content-Type: application/x-www-form-urlencoded" +
                SimpleHttpClient.CRLF +
        "Connection: close" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF +
        "3" + SimpleHttpClient.CRLF +
        "a=0" + SimpleHttpClient.CRLF +
        "4" + SimpleHttpClient.CRLF +
        "&b=1" + SimpleHttpClient.CRLF +
        "0" + SimpleHttpClient.CRLF +
        SimpleHttpClient.CRLF;

    TrailerClient client =
            new TrailerClient(tomcat.getConnector().getLocalPort());
    client.setRequest(new String[] {request});

    client.connect();
    client.processRequest();
    assertEquals("nullnull7nullnull", client.getResponseBody());
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:37,代码来源:TestChunkedInputFilter.java

示例5: init

import org.apache.catalina.Context; //导入方法依赖的package包/类
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context root = tomcat.addContext("", null);
    Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
    root.addServletMapping("/test", "Bug37794");

    if (createFilter) {
        FilterDef failedRequestFilter = new FilterDef();
        failedRequestFilter.setFilterName("failedRequestFilter");
        failedRequestFilter.setFilterClass(
                FailedRequestFilter.class.getName());
        FilterMap failedRequestFilterMap = new FilterMap();
        failedRequestFilterMap.setFilterName("failedRequestFilter");
        failedRequestFilterMap.addURLPattern("/*");
        root.addFilterDef(failedRequestFilter);
        root.addFilterMap(failedRequestFilterMap);
    }

    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:28,代码来源:TestRequest.java

示例6: testBug49528

import org.apache.catalina.Context; //导入方法依赖的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);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:37,代码来源:TestAsyncContextImpl.java

示例7: testBug38113

import org.apache.catalina.Context; //导入方法依赖的package包/类
/**
 * Test case for
 * <a href="https://bz.apache.org/bugzilla/show_bug.cgi?id=38113">bug
 * 38118</a>.
 */
@Test
public void testBug38113() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    // Add the Servlet
    Tomcat.addServlet(ctx, "servlet", new EchoQueryStringServlet());
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    // No query string
    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("QueryString=null", res.toString());

    // Query string
    res = getUrl("http://localhost:" + getPort() + "/?a=b");
    assertEquals("QueryString=a=b", res.toString());

    // Empty string
    res = getUrl("http://localhost:" + getPort() + "/?");
    assertEquals("QueryString=", res.toString());
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:32,代码来源:TestRequest.java

示例8: pathParamTest

import org.apache.catalina.Context; //导入方法依赖的package包/类
private void pathParamTest(String path, String expected) throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "servlet", new PathParamServlet());
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + path);
    Assert.assertEquals(expected, res.toString());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:16,代码来源:TestCoyoteAdapter.java

示例9: testPathParamsRedirect

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testPathParamsRedirect() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // Must have a real docBase. Don't use java.io.tmpdir as it may not be
    // writable.
    File docBase = new File(getTemporaryDirectory(), "testCoyoteAdapter");
    addDeleteOnTearDown(docBase);
    if (!docBase.mkdirs() && !docBase.isDirectory()) {
        Assert.fail("Failed to create: [" + docBase.toString() + "]");
    }

    // Create the folder that will trigger the redirect
    File foo = new File(docBase, "foo");
    addDeleteOnTearDown(foo);
    if (!foo.mkdirs() && !foo.isDirectory()) {
        Assert.fail("Unable to create foo directory in docBase");
    }

    Context ctx = tomcat.addContext("", docBase.getAbsolutePath());

    Tomcat.addServlet(ctx, "servlet", new PathParamServlet());
    ctx.addServletMapping("/", "servlet");

    tomcat.start();

    testPath("/", "none");
    testPath("/;jsessionid=1234", "1234");
    testPath("/foo;jsessionid=1234", "1234");
    testPath("/foo;jsessionid=1234;dummy", "1234");
    testPath("/foo;jsessionid=1234;dummy=5678", "1234");
    testPath("/foo;jsessionid=1234;=5678", "1234");
    testPath("/foo;jsessionid=1234/bar", "1234");
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:36,代码来源:TestCoyoteAdapter.java

示例10: doRequest

import org.apache.catalina.Context; //导入方法依赖的package包/类
private Exception doRequest() {

            Tomcat tomcat = getTomcatInstance();

            Context root = tomcat.addContext("", TEMP_DIR);
            Tomcat.addServlet(root, "test", new TesterServlet());
            root.addServletMapping("/test", "test");

            try {
                tomcat.start();
                setPort(tomcat.getConnector().getLocalPort());

                // Open connection
                connect();

                String[] request = new String[1];
                request[0] =
                    newLines +
                    "GET http://localhost:8080/test HTTP/1.1" + CRLF +
                    "X-Bug48839: abcd" + CRLF +
                    "\tefgh" + CRLF +
                    "Connection: close" + CRLF +
                    CRLF;

                setRequest(request);
                processRequest(); // blocks until response has been read

                // Close the connection
                disconnect();
            } catch (Exception e) {
                return e;
            }
            return null;
        }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:TestInternalInputBuffer.java

示例11: setUp

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
    super.setUp();

    // Configure a context with digest auth and a single protected resource
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctxt = tomcat.addContext(CONTEXT_PATH, null);

    // Add protected servlet
    Tomcat.addServlet(ctxt, "TesterServlet", new TesterServlet());
    ctxt.addServletMapping(URI, "TesterServlet");
    SecurityCollection collection = new SecurityCollection();
    collection.addPattern(URI);
    SecurityConstraint sc = new SecurityConstraint();
    sc.addAuthRole(ROLE);
    sc.addCollection(collection);
    ctxt.addConstraint(sc);

    // Configure the Realm
    MapRealm realm = new MapRealm();
    realm.addUser(USER, PWD);
    realm.addUserRole(USER, ROLE);
    ctxt.setRealm(realm);

    // Configure the authenticator
    LoginConfig lc = new LoginConfig();
    lc.setAuthMethod("DIGEST");
    lc.setRealmName(REALM);
    ctxt.setLoginConfig(lc);
    ctxt.getPipeline().addValve(new DigestAuthenticator());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:34,代码来源:TestDigestAuthenticator.java

示例12: testErrorHandling

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testErrorHandling() throws Exception {
    resetTracker();
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    ErrorServlet error = new ErrorServlet();
    Tomcat.addServlet(ctx, "error", error);
    ctx.addServletMapping("/error", "error");

    TesterAccessLogValve alv = new TesterAccessLogValve();
    ctx.getPipeline().addValve(alv);

    tomcat.start();

    StringBuilder url = new StringBuilder(48);
    url.append("http://localhost:");
    url.append(getPort());
    url.append("/error");

    int rc = getUrl(url.toString(), new ByteChunk(), null);

    assertEquals(500, 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, 500, 0, REQUEST_TIME);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:TestAsyncContextImpl.java

示例13: testBug49424NoChunking

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testBug49424NoChunking() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context root = tomcat.addContext("", null);
    Tomcat.addServlet(root, "Bug37794", new Bug37794Servlet());
    root.addServletMapping("/", "Bug37794");
    tomcat.start();

    HttpURLConnection conn = getConnection("http://localhost:" + getPort() + "/");
    InputStream is = conn.getInputStream();
    assertNotNull(is);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:14,代码来源:TestRequest.java

示例14: testDefaultClassLoader

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testDefaultClassLoader() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "ClassLoaderReport", new ClassLoaderReport(null));
    ctx.addServletMapping("/", "ClassLoaderReport");

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/");
    assertEquals("WEBAPP,SYSTEM,OTHER,", res.toString());
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:16,代码来源:TestTomcatClassLoader.java

示例15: testGenericsCoders

import org.apache.catalina.Context; //导入方法依赖的package包/类
@Test
public void testGenericsCoders() throws Exception {
    // Set up utility classes
    GenericsServer server = new GenericsServer();
    SingletonConfigurator.setInstance(server);
    ServerConfigListener.setPojoClazz(GenericsServer.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();

    GenericsClient client = new GenericsClient();
    URI uri = new URI("ws://localhost:" + getPort() + PATH_GENERICS_EP);
    Session session = wsContainer.connectToServer(client, uri);

    ArrayList<String> list = new ArrayList<String>(2);
    list.add("str1");
    list.add("str2");
    session.getBasicRemote().sendObject(list);

    // Should not take very long
    int i = 0;
    while (i < 20) {
        if (server.received.size() > 0 && client.received.size() > 0) {
            break;
        }
        Thread.sleep(100);
    }

    // Check messages were received
    Assert.assertEquals(1, server.received.size());
    Assert.assertEquals(server.received.peek().toString(), "[str1, str2]");

    Assert.assertEquals(1, client.received.size());
    Assert.assertEquals(client.received.peek().toString(), "[str1, str2]");

    session.close();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:47,代码来源:TestEncodingDecoding.java


注:本文中的org.apache.catalina.Context.addServletMapping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。