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


Java Tomcat.getConnector方法代碼示例

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


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

示例1: testPort

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

    Connector connector1 = tomcat.getConnector();
    connector1.setPort(0);

    Connector connector2 = new Connector();
    connector2.setPort(0);

    tomcat.getService().addConnector(connector2);

    tomcat.start();

    int localPort1 = connector1.getLocalPort();
    int localPort2 = connector2.getLocalPort();

    assertTrue(localPort1 > 0);
    assertTrue(localPort2 > 0);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:TestConnector.java

示例2: getBaseUrlForEmbeddedTomcat

import org.apache.catalina.startup.Tomcat; //導入方法依賴的package包/類
/**
 * /!\ Work only if application run on embedded Tomcat server
 *
 * @return
 * @throws Exception
 */
public static String getBaseUrlForEmbeddedTomcat() throws Exception {

    // get embedded tomcat
    EmbeddedWebApplicationContext appContext = (EmbeddedWebApplicationContext) new ApplicationContextProvider().getApplicationContext();
    Tomcat tomcat = ((TomcatEmbeddedServletContainer) appContext.getEmbeddedServletContainer()).getTomcat();
    Connector connector = tomcat.getConnector();

    // compose address
    String scheme = connector.getScheme();
    String hostName = tomcat.getHost().getName();
    int port = connector.getPort();
    String contextPath = appContext.getServletContext().getContextPath();

    return scheme + "://" + hostName + ":" + port + contextPath;
}
 
開發者ID:remipassmoilesel,項目名稱:simple-hostel-management,代碼行數:22,代碼來源:Utils.java

示例3: testStop

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

    // No file system docBase required
    Context root = tomcat.addContext("", null);
    Wrapper w =
        Tomcat.addServlet(root, "tester", new TesterServlet());
    w.setAsyncSupported(true);
    root.addServletMapping("/", "tester");

    Connector connector = tomcat.getConnector();

    tomcat.start();

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

    assertEquals(200, rc);
    assertEquals("OK", bc.toString());

    rc = -1;
    bc.recycle();

    connector.stop();

    try {
        rc = getUrl("http://localhost:" + getPort() + "/", bc, 1000,
                null, null);
    } catch (SocketTimeoutException ste) {
        // May also see this with NIO
        // Make sure the test passes if we do
        rc = 503;
    }
    assertEquals(503, rc);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:37,代碼來源:TestConnector.java

示例4: testCustomSslImplementation

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

    TesterSupport.configureClientSsl();

    Tomcat tomcat = getTomcatInstance();
    Connector connector = tomcat.getConnector();

    Assume.assumeFalse("This test is only for JSSE based SSL connectors",
            connector.getProtocolHandlerClassName().contains("Apr"));

    connector.setProperty("sslImplementationName",
            "org.apache.tomcat.util.net.jsse.TesterBug50640SslImpl");
    connector.setProperty(TesterBug50640SslImpl.PROPERTY_NAME,
            TesterBug50640SslImpl.PROPERTY_VALUE);

    connector.setProperty("sslProtocol", "tls");

    File keystoreFile =
        new File("test/org/apache/tomcat/util/net/localhost.jks");
    connector.setAttribute(
            "keystoreFile", keystoreFile.getAbsolutePath());

    connector.setSecure(true);
    connector.setProperty("SSLEnabled", "true");

    File appDir = new File(getBuildDirectory(), "webapps/examples");
    tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());

    tomcat.start();
    ByteChunk res = getUrl("https://localhost:" + getPort() +
        "/examples/servlets/servlet/HelloWorldExample");
    assertTrue(res.toString().indexOf("<a href=\"../helloworld.html\">") > 0);
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:35,代碼來源:TestCustomSsl.java


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