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


Java Tomcat類代碼示例

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


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

示例1: testCreateSessionAndPassivate

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

    // 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("No active sessions", manager.getActiveSessions(), 0);
    Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty());
    String sessionId = getUrl(
            "http://localhost:" + getPort()
                    + "/dummy?no_create_session=false").toString();
    Assert.assertNotNull("Session is stored", store.load(sessionId));
    Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0);
    Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty());
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:31,代碼來源:TestPersistentManagerIntegration.java

示例2: doRequest

import org.apache.catalina.startup.Tomcat; //導入依賴的package包/類
private void doRequest() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    Context root = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(root, "Simple", new SimpleServlet());
    root.addServletMapping("/test", "Simple");

    tomcat.start();
    // Open connection
    setPort(tomcat.getConnector().getLocalPort());
    connect();

    String[] request = new String[1];
    request[0] =
        "GET /test HTTP/1.0" + CRLF +
        "Cookie: " + COOKIE_WITH_SEPS + CRLF + CRLF;
    setRequest(request);
    processRequest(true); // blocks until response has been read
    String response = getResponseBody();

    // Close the connection
    disconnect();
    reset();
    tomcat.stop();
    assertEquals(COOKIE_WITH_SEPS, response);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:26,代碼來源:TestCookiesAllowHttpSeps.java

示例3: testBug36923

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

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug36923.jsp");

    String result = res.toString();
    assertEcho(result, "00-${hello world}");
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TestELInJsp.java

示例4: testBug56147

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

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    StandardContext ctx = (StandardContext) tomcat.addWebapp(
            null, "/test", appDir.getAbsolutePath());

    // This test needs the JSTL libraries
    File lib = new File("webapps/examples/WEB-INF/lib");
    ctx.setAliases("/WEB-INF/lib=" + lib.getCanonicalPath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug56147.jsp");

    String result = res.toString();
    assertEcho(result, "00-OK");
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:22,代碼來源:TestELInJsp.java

示例5: mbeansAvailableBeforeBinder

import org.apache.catalina.startup.Tomcat; //導入依賴的package包/類
@Test
void mbeansAvailableBeforeBinder() throws LifecycleException {
    Tomcat server = new Tomcat();
    try {
        StandardHost host = new StandardHost();
        host.setName("localhost");
        server.setHost(host);
        server.setPort(61000);
        server.start();

        TomcatMetrics.monitor(registry, null);
        assertThat(registry.find("tomcat.global.received").functionCounter()).isNotNull();
    } finally {
        server.stop();
        server.destroy();
    }
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:18,代碼來源:TomcatMetricsTest.java

示例6: testBug44994

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

    File appDir =
        new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/bug44994.jsp");

    String result = res.toString();
    assertEcho(result, "00-none");
    assertEcho(result, "01-one");
    assertEcho(result, "02-many");
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:20,代碼來源:TestELInJsp.java

示例7: testBug49297MultiplePageEncoding2

import org.apache.catalina.startup.Tomcat; //導入依賴的package包/類
@Test
public void testBug49297MultiplePageEncoding2() throws Exception {

    Tomcat tomcat = getTomcatInstance();

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = new ByteChunk();
    int sc = getUrl("http://localhost:" + getPort() +
            "/test/bug49nnn/bug49297MultiplePageEncoding2.jsp", res,
            new HashMap<String,List<String>>());

    assertEquals(500, sc);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:19,代碼來源:TestParser.java

示例8: testParameterImmutability

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

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

    Tomcat.addServlet(ctx, "forward", new ForwardServlet("/modify"));
    ctx.addServletMapping("/forward", "forward");

    Tomcat.addServlet(ctx, "modify", new ModifyParameterServlet());
    ctx.addServletMapping("/modify", "modify");

    tomcat.start();

    ByteChunk response = new ByteChunk();
    StringBuilder target = new StringBuilder("http://localhost:");
    target.append(getPort());
    target.append("/forward");
    int rc = getUrl(target.toString(), response, null);

    Assert.assertEquals(200, rc);
    Assert.assertEquals("OK", response.toString());
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:25,代碼來源:TestApplicationHttpRequest.java

示例9: setupHeadersTest

import org.apache.catalina.startup.Tomcat; //導入依賴的package包/類
private void setupHeadersTest(Tomcat tomcat) {
    Context ctx = tomcat.addContext("", getTemporaryDirectory()
            .getAbsolutePath());
    Tomcat.addServlet(ctx, "servlet", new HttpServlet() {
        private static final long serialVersionUID = 1L;

        @Override
        public void service(ServletRequest req, ServletResponse res)
                throws ServletException, IOException {
            res.setContentType("text/plain; charset=ISO-8859-1");
            res.getWriter().write("OK");
        }
    });
    ctx.addServletMapping("/", "servlet");

    alv = new HeaderCountLogValve();
    tomcat.getHost().getPipeline().addValve(alv);
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:19,代碼來源:TestMimeHeaders.java

示例10: bug54241a

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

    File appDir = new File("test/webapp-3.0");
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = new ByteChunk();

    int rc = getUrl("http://localhost:" + getPort() +
            "/test/bug5nnnn/bug54241a.jsp", res, null);

    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    String body = res.toString();
    Assert.assertTrue(body.contains("01: null"));
    Assert.assertTrue(body.contains("02: null"));
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:TestJspWriterImpl.java

示例11: testBug49297DuplicateAttr

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

    File appDir = new File("test/webapp-3.0");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    int sc = getUrl("http://localhost:" + getPort() +
            "/test/bug49nnn/bug49297DuplicateAttr.jsp", new ByteChunk(),
            new HashMap<String,List<String>>());

    assertEquals(500, sc);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:17,代碼來源:TestParserNoStrictWhitespace.java

示例12: testServlet24NoEL

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

    File appDir =
        new File("test/webapp-2.4");
    // app dir is relative to server home
    tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());

    tomcat.start();

    ByteChunk res = getUrl("http://localhost:" + getPort() +
            "/test/el-as-literal.jsp");

    String result = res.toString();

    assertTrue(result.indexOf("<p>00-hello world</p>") > 0);
    assertTrue(result.indexOf("<p>01-#{'hello world'}</p>") > 0);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:20,代碼來源:TestJspConfig.java

示例13: testBug52577

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

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

    Bug52577Servlet bug52577 = new Bug52577Servlet();
    Tomcat.addServlet(root, "bug52577", bug52577);
    root.addServletMapping("/", "bug52577");

    tomcat.start();

    ByteChunk bc = new ByteChunk();

    int rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
    assertEquals(HttpServletResponse.SC_OK, rc);
    assertEquals("OK", bc.toString());
}
 
開發者ID:sunmingshuai,項目名稱:apache-tomcat-7.0.73-with-comment,代碼行數:20,代碼來源:TestOutputBuffer.java

示例14: doTestUriDecoding

import org.apache.catalina.startup.Tomcat; //導入依賴的package包/類
private void doTestUriDecoding(String path, String encoding,
        String expectedPathInfo) throws Exception{

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

    tomcat.getConnector().setURIEncoding(encoding);

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

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

    tomcat.start();

    int rc = getUrl("http://localhost:" + getPort() + path,
            new ByteChunk(), null);
    Assert.assertEquals(HttpServletResponse.SC_OK, rc);

    Assert.assertEquals(expectedPathInfo, servlet.getPathInfo());
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:24,代碼來源:TestCoyoteAdapter.java

示例15: doClassUnloadingPrep

import org.apache.catalina.startup.Tomcat; //導入依賴的package包/類
private DefaultInstanceManager doClassUnloadingPrep() throws Exception {
    Tomcat tomcat = getTomcatInstance();

    // Create the context (don't use addWebapp as we want to modify the
    // JSP Servlet settings).
    File appDir = new File("test/webapp-3.0");
    StandardContext ctxt = (StandardContext) tomcat.addContext(
            null, "/test", appDir.getAbsolutePath());

    // Configure the defaults and then tweak the JSP servlet settings
    // Note: Min value for maxLoadedJsps is 2
    Tomcat.initWebappDefaults(ctxt);
    Wrapper w = (Wrapper) ctxt.findChild("jsp");
    w.addInitParameter("maxLoadedJsps", "2");

    tomcat.start();

    return (DefaultInstanceManager) ctxt.getInstanceManager();
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:20,代碼來源:TestDefaultInstanceManager.java


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