Search in sources :

Example 6 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class StandardServiceSF method storeChildren.

/**
     * Store the specified service element children.
     *
     * @param aWriter Current output writer
     * @param indent Indentation level
     * @param aService Service to store
     * @param parentDesc The element description
     * @throws Exception Configuration storing error
     */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aService, StoreDescription parentDesc) throws Exception {
    if (aService instanceof StandardService) {
        StandardService service = (StandardService) aService;
        // Store nested <Listener> elements
        LifecycleListener[] listeners = ((Lifecycle) service).findLifecycleListeners();
        storeElementArray(aWriter, indent, listeners);
        // Store nested <Executor> elements
        Executor[] executors = service.findExecutors();
        storeElementArray(aWriter, indent, executors);
        Connector[] connectors = service.findConnectors();
        storeElementArray(aWriter, indent, connectors);
        // Store nested <Engine> element
        Engine container = service.getContainer();
        if (container != null) {
            StoreDescription elementDesc = getRegistry().findDescription(container.getClass());
            if (elementDesc != null) {
                IStoreFactory factory = elementDesc.getStoreFactory();
                factory.store(aWriter, indent, container);
            }
        }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) Executor(org.apache.catalina.Executor) Lifecycle(org.apache.catalina.Lifecycle) StandardService(org.apache.catalina.core.StandardService) LifecycleListener(org.apache.catalina.LifecycleListener) Engine(org.apache.catalina.Engine)

Example 7 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class Tomcat method getConnector.

// ------- Extra customization -------
// You can tune individual Tomcat objects, using internal APIs
/**
     * Get the default HTTP connector that is used by the embedded
     * Tomcat. It is first configured connector in the service.
     * If there's no connector defined, it will create and add a default
     * connector using the port and address specified in this Tomcat
     * instance, and return it for further customization.
     *
     * @return The connector object
     */
public Connector getConnector() {
    Service service = getService();
    if (service.findConnectors().length > 0) {
        return service.findConnectors()[0];
    }
    // The same as in standard Tomcat configuration.
    // This creates an APR HTTP connector if AprLifecycleListener has been
    // configured (created) and Tomcat Native library is available.
    // Otherwise it creates a NIO HTTP connector.
    Connector connector = new Connector("HTTP/1.1");
    connector.setPort(port);
    service.addConnector(connector);
    return connector;
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 8 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class Tomcat method setConnector.

/**
     * Set the specified connector in the service, if it is not already
     * present.
     * @param connector The connector instance to add
     */
public void setConnector(Connector connector) {
    Service service = getService();
    boolean found = false;
    for (Connector serviceConnector : service.findConnectors()) {
        if (connector == serviceConnector) {
            found = true;
        }
    }
    if (!found) {
        service.addConnector(connector);
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service)

Example 9 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class TomcatBaseTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    // Trigger loading of catalina.properties
    CatalinaProperties.getProperty("foo");
    File appBase = new File(getTemporaryDirectory(), "webapps");
    if (!appBase.exists() && !appBase.mkdir()) {
        fail("Unable to create appBase for test");
    }
    tomcat = new TomcatWithFastSessionIDs();
    String protocol = getProtocol();
    Connector connector = new Connector(protocol);
    // Listen only on localhost
    connector.setAttribute("address", InetAddress.getByName("localhost").getHostAddress());
    // Use random free port
    connector.setPort(0);
    // Mainly set to reduce timeouts during async tests
    connector.setAttribute("connectionTimeout", "3000");
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);
    // Add AprLifecycleListener if we are using the Apr connector
    if (protocol.contains("Apr")) {
        StandardServer server = (StandardServer) tomcat.getServer();
        AprLifecycleListener listener = new AprLifecycleListener();
        listener.setSSLRandomSeed("/dev/urandom");
        server.addLifecycleListener(listener);
        connector.setAttribute("pollerThreadCount", Integer.valueOf(1));
    }
    File catalinaBase = getTemporaryDirectory();
    tomcat.setBaseDir(catalinaBase.getAbsolutePath());
    tomcat.getHost().setAppBase(appBase.getAbsolutePath());
    accessLogEnabled = Boolean.parseBoolean(System.getProperty("tomcat.test.accesslog", "false"));
    if (accessLogEnabled) {
        String accessLogDirectory = System.getProperty("tomcat.test.reports");
        if (accessLogDirectory == null) {
            accessLogDirectory = new File(getBuildDirectory(), "logs").toString();
        }
        AccessLogValve alv = new AccessLogValve();
        alv.setDirectory(accessLogDirectory);
        alv.setPattern("%h %l %u %t \"%r\" %s %b %I %D");
        tomcat.getHost().getPipeline().addValve(alv);
    }
    // Cannot delete the whole tempDir, because logs are there,
    // but delete known subdirectories of it.
    addDeleteOnTearDown(new File(catalinaBase, "webapps"));
    addDeleteOnTearDown(new File(catalinaBase, "work"));
}
Also used : Connector(org.apache.catalina.connector.Connector) AprLifecycleListener(org.apache.catalina.core.AprLifecycleListener) StandardServer(org.apache.catalina.core.StandardServer) File(java.io.File) AccessLogValve(org.apache.catalina.valves.AccessLogValve) Before(org.junit.Before)

Example 10 with Connector

use of org.apache.catalina.connector.Connector in project tomcat by apache.

the class TestXxxEndpoint method testStartStopBindOnStart.

@Test
public void testStartStopBindOnStart() throws Exception {
    Tomcat tomcat = getTomcatInstance();
    Connector c = tomcat.getConnector();
    c.setProperty("bindOnInit", "false");
    File appDir = new File(getBuildDirectory(), "webapps/examples");
    tomcat.addWebapp(null, "/examples", appDir.getAbsolutePath());
    tomcat.start();
    int port = getPort();
    tomcat.getConnector().stop();
    Exception e = null;
    ServerSocket s = null;
    long pool = 0;
    long nativeSocket = 0;
    boolean isApr = tomcat.getConnector().getProtocolHandlerClassName().contains("Apr");
    try {
        // This should not throw an Exception
        if (isApr) {
            pool = createAprPool();
            assertTrue(pool != 0);
            nativeSocket = createAprSocket(port, pool);
            assertTrue(nativeSocket != 0);
        } else {
            s = new ServerSocket(port, 100, InetAddress.getByName("localhost"));
        }
    } catch (Exception e1) {
        e = e1;
    } finally {
        try {
            if (isApr) {
                destroyAprSocket(nativeSocket, pool);
            } else if (s != null) {
                s.close();
            }
        } catch (Exception e2) {
        /* Ignore */
        }
    }
    assertNull(e);
    tomcat.getConnector().start();
}
Also used : Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) ServerSocket(java.net.ServerSocket) File(java.io.File) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Aggregations

Connector (org.apache.catalina.connector.Connector)66 Test (org.junit.Test)16 Service (org.apache.catalina.Service)14 File (java.io.File)10 Tomcat (org.apache.catalina.startup.Tomcat)10 Context (org.apache.catalina.Context)6 Engine (org.apache.catalina.Engine)6 Properties (java.util.Properties)5 StandardService (org.apache.catalina.core.StandardService)5 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Executor (org.apache.catalina.Executor)4 HashMap (java.util.HashMap)3 ObjectName (javax.management.ObjectName)3 Container (org.apache.catalina.Container)3 LifecycleException (org.apache.catalina.LifecycleException)3 Wrapper (org.apache.catalina.Wrapper)3 InetAddress (java.net.InetAddress)2