當前位置: 首頁>>代碼示例>>Java>>正文


Java Tomcat.addContext方法代碼示例

本文整理匯總了Java中org.apache.catalina.startup.Tomcat.addContext方法的典型用法代碼示例。如果您正苦於以下問題:Java Tomcat.addContext方法的具體用法?Java Tomcat.addContext怎麽用?Java Tomcat.addContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.catalina.startup.Tomcat的用法示例。


在下文中一共展示了Tomcat.addContext方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doTestNon2xxResponseAndExpectation

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void doTestNon2xxResponseAndExpectation(boolean useExpectation) throws Exception {
    Tomcat tomcat = getTomcatInstance();

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

    Tomcat.addServlet(ctx, "echo", new EchoBodyServlet());
    ctx.addServletMapping("/echo", "echo");

    SecurityCollection collection = new SecurityCollection("All", "");
    collection.addPattern("/*");
    SecurityConstraint constraint = new SecurityConstraint();
    constraint.addAuthRole("Any");
    constraint.addCollection(collection);
    ctx.addConstraint(constraint);

    tomcat.start();

    Non2xxResponseClient client = new Non2xxResponseClient(useExpectation);
    client.setPort(getPort());
    client.doResourceRequest("GET http://localhost:" + getPort()
            + "/echo HTTP/1.1", "HelloWorld");
    Assert.assertTrue(client.isResponse403());
    Assert.assertTrue(client.checkConnectionHeader());
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:26,代碼來源:TestAbstractHttp11Processor.java

示例2: testConnectToServerEndpointInvalidScheme

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test(expected=javax.websocket.DeploymentException.class)
public void testConnectToServerEndpointInvalidScheme() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(TesterEchoServer.Config.class.getName());

    tomcat.start();

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();
    wsContainer.connectToServer(TesterProgrammaticEndpoint.class,
            ClientEndpointConfig.Builder.create().build(),
            new URI("ftp://" + getHostName() + ":" + getPort() +
                    TesterEchoServer.Config.PATH_ASYNC));
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:17,代碼來源:TestWsWebSocketContainer.java

示例3: testClientDropsConnection

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testClientDropsConnection() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(Bug58624Config.class.getName());
    Tomcat.addServlet(ctx, "default", new DefaultServlet());
    ctx.addServletMapping("/", "default");

    WebSocketContainer wsContainer =
            ContainerProvider.getWebSocketContainer();

    tomcat.start();

    SimpleClient client = new SimpleClient();
    URI uri = new URI("ws://localhost:" + getPort() + Bug58624Config.PATH);

    Session session = wsContainer.connectToServer(client, uri);
    // Break point A required on following line
    session.close();
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:22,代碼來源:TestWsRemoteEndpointImplServer.java

示例4: addServlets

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public static void addServlets(Tomcat tomcat) {
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);

    Tomcat.addServlet(ctx, "invalid", new CookieServlet("na;me", "value"));
    ctx.addServletMapping("/invalid", "invalid");
    Tomcat.addServlet(ctx, "null", new CookieServlet(null, "value"));
    ctx.addServletMapping("/null", "null");
    Tomcat.addServlet(ctx, "blank", new CookieServlet("", "value"));
    ctx.addServletMapping("/blank", "blank");
    Tomcat.addServlet(ctx, "invalidFwd",
            new CookieServlet("na/me", "value"));
    ctx.addServletMapping("/invalidFwd", "invalidFwd");
    Tomcat.addServlet(ctx, "invalidStrict",
            new CookieServlet("na?me", "value"));
    ctx.addServletMapping("/invalidStrict", "invalidStrict");
    Tomcat.addServlet(ctx, "valid", new CookieServlet("name", "value"));
    ctx.addServletMapping("/valid", "valid");
    Tomcat.addServlet(ctx, "switch", new CookieServlet("name", "val?ue"));
    ctx.addServletMapping("/switch", "switch");

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:23,代碼來源:CookiesBaseTest.java

示例5: doTestInvalidate

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void doTestInvalidate(boolean useClustering) throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

    Tomcat.addServlet(ctx, "bug56578", new Bug56578Servlet());
    ctx.addServletMapping("/bug56578", "bug56578");

    if (useClustering) {
        tomcat.getEngine().setCluster(new SimpleTcpCluster());
        ctx.setDistributable(true);
        ctx.setManager(ctx.getCluster().createManager(""));
    }
    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + "/bug56578");
    Assert.assertEquals("PASS", res.toString());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:21,代碼來源:TestStandardSessionIntegration.java

示例6: setUpDigest

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void setUpDigest(Tomcat tomcat) throws Exception {

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

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

        // Configure the appropriate authenticator
        LoginConfig lc = new LoginConfig();
        lc.setAuthMethod("DIGEST");
        ctxt.setLoginConfig(lc);
        ctxt.getPipeline().addValve(new DigestAuthenticator());
    }
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:23,代碼來源:TestSSOnonLoginAndDigestAuthenticator.java

示例7: pathParamExtenionTest

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void pathParamExtenionTest(String path, String expected)
        throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

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

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() + path);
    Assert.assertEquals(expected, res.toString());
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TestCoyoteAdapter.java

示例8: testBug49598

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testBug49598() throws Exception {
    // Setup Tomcat instance
    Tomcat tomcat = getTomcatInstance();

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

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

    tomcat.start();

    Map<String,List<String>> headers = new HashMap<String,List<String>>();
    getUrl("http://localhost:" + getPort() + "/", new ByteChunk(), headers);

    // Check for headers without a name
    for (Map.Entry<String,List<String>> header : headers.entrySet()) {
        if (header.getKey() == null) {
            // Expected if this is the response line
            List<String> values = header.getValue();
            if (values.size() == 1 &&
                    values.get(0).startsWith("HTTP/1.1")) {
                continue;
            }
            fail("Null header name detected for value " + values);
        }
    }

    // Check for exactly one Set-Cookie header
    int count = 0;
    for (String headerName : headers.keySet()) {
        if ("Set-Cookie".equals(headerName)) {
            count ++;
        }
    }
    assertEquals(1, count);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:39,代碼來源:TestResponse.java

示例9: TomcatHttpServer

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
public TomcatHttpServer(URL url, final HttpHandler handler) {
        super(url, handler);

        this.url = url;
        DispatcherServlet.addHttpHandler(url.getPort(), handler);
        String baseDir = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
        tomcat = new Tomcat();
        tomcat.setBaseDir(baseDir);
        tomcat.setPort(url.getPort());
        tomcat.getConnector().setProperty(
                "maxThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));
//        tomcat.getConnector().setProperty(
//                "minSpareThreads", String.valueOf(url.getParameter(Constants.THREADS_KEY, Constants.DEFAULT_THREADS)));

        tomcat.getConnector().setProperty(
                "maxConnections", String.valueOf(url.getParameter(Constants.ACCEPTS_KEY, -1)));

        tomcat.getConnector().setProperty("URIEncoding", "UTF-8");
        tomcat.getConnector().setProperty("connectionTimeout", "60000");

        tomcat.getConnector().setProperty("maxKeepAliveRequests", "-1");
        tomcat.getConnector().setProtocol("org.apache.coyote.http11.Http11NioProtocol");

        Context context = tomcat.addContext("/", baseDir);
        Tomcat.addServlet(context, "dispatcher", new DispatcherServlet());
        context.addServletMapping("/*", "dispatcher");
        ServletManager.getInstance().addServletContext(url.getPort(), context.getServletContext());

        try {
            tomcat.start();
        } catch (LifecycleException e) {
            throw new IllegalStateException("Failed to start tomcat server at " + url.getAddress(), e);
        }
    }
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:35,代碼來源:TomcatHttpServer.java

示例10: noSessionCreate_57637

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void noSessionCreate_57637() throws IOException, LifecycleException {

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

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

    Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet());
    ctx.addServletMapping("/dummy", "DummyServlet");

    PersistentManager manager = new PersistentManager();
    TesterStore store = new TesterStore();

    manager.setStore(store);
    manager.setMaxIdleBackup(0);
    ctx.setManager(manager);
    ctx.addValve(new PersistentValve());
    tomcat.start();
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    Assert.assertEquals(
            "NO_SESSION",
            getUrl(
                    "http://localhost:" + getPort()
                            + "/dummy?no_create_session=true").toString());
    Assert.assertEquals(manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions where created", manager.getSessionIdsFull().isEmpty());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:32,代碼來源:TestPersistentManagerIntegration.java

示例11: setUpNonLogin

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void setUpNonLogin(Tomcat tomcat) throws Exception {

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

        // Add protected servlet
        Tomcat.addServlet(ctxt, "TesterServlet1", new TesterServlet());
        ctxt.addServletMapping(URI_PROTECTED, "TesterServlet1");
        SecurityCollection collection1 = new SecurityCollection();
        collection1.addPattern(URI_PROTECTED);
        SecurityConstraint sc1 = new SecurityConstraint();
        sc1.addAuthRole(ROLE);
        sc1.addCollection(collection1);
        ctxt.addConstraint(sc1);

        // Add unprotected servlet
        Tomcat.addServlet(ctxt, "TesterServlet2", new TesterServlet());
        ctxt.addServletMapping(URI_PUBLIC, "TesterServlet2");
        SecurityCollection collection2 = new SecurityCollection();
        collection2.addPattern(URI_PUBLIC);
        SecurityConstraint sc2 = new SecurityConstraint();
        // do not add a role - which signals access permitted without one
        sc2.addCollection(collection2);
        ctxt.addConstraint(sc2);

        // Configure the appropriate authenticator
        LoginConfig lc = new LoginConfig();
        lc.setAuthMethod("NONE");
        ctxt.setLoginConfig(lc);
        ctxt.getPipeline().addValve(new NonLoginAuthenticator());
    }
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:33,代碼來源:TestSSOnonLoginAndDigestAuthenticator.java

示例12: testBug54807

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
@Test
public void testBug54807() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    // No file system docBase required
    Context ctx = tomcat.addContext("", null);
    ctx.addApplicationListener(Bug54807Config.class.getName());
    Tomcat.addServlet(ctx, "default", new DefaultServlet());
    ctx.addServletMapping("/", "default");

    tomcat.start();

    Assert.assertEquals(LifecycleState.STARTED, ctx.getState());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:14,代碼來源:TestWsServerContainer.java

示例13: doTestAsyncISE

import org.apache.catalina.startup.Tomcat; //導入方法依賴的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);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:35,代碼來源:TestAsyncContextImpl.java

示例14: testBug53337

import org.apache.catalina.startup.Tomcat; //導入方法依賴的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());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:30,代碼來源:TestAsyncContextImpl.java

示例15: doTestSecurityAnnotationsAddServlet

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
private void doTestSecurityAnnotationsAddServlet(boolean useCreateServlet)
        throws Exception {

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

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

    Servlet s = new DenyAllServlet();
    ServletContainerInitializer sci = new SCI(s, useCreateServlet);
    ctx.addServletContainerInitializer(sci, null);

    tomcat.start();

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

    if (useCreateServlet) {
        assertTrue(bc.getLength() > 0);
        assertEquals(403, rc);
    } else {
        assertEquals("OK", bc.toString());
        assertEquals(200, rc);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:28,代碼來源:TestStandardWrapper.java


注:本文中的org.apache.catalina.startup.Tomcat.addContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。