Search in sources :

Example 41 with Connector

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

the class StandardService method destroyInternal.

@Override
protected void destroyInternal() throws LifecycleException {
    mapperListener.destroy();
    // Destroy our defined Connectors
    synchronized (connectorsLock) {
        for (Connector connector : connectors) {
            connector.destroy();
        }
    }
    // Destroy any Executors
    for (Executor executor : findExecutors()) {
        executor.destroy();
    }
    if (engine != null) {
        engine.destroy();
    }
    super.destroyInternal();
}
Also used : Connector(org.apache.catalina.connector.Connector) Executor(org.apache.catalina.Executor)

Example 42 with Connector

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

the class ConnectorStoreAppender method isPrintValue.

/**
     * Print Connector Values. <ul><li> Special handling to default jkHome.
     * </li><li> Don't save catalina.base path at server.xml</li><li></ul>
     *
     * @see org.apache.catalina.storeconfig.StoreAppender#isPrintValue(java.lang.Object,
     *      java.lang.Object, java.lang.String,
     *      org.apache.catalina.storeconfig.StoreDescription)
     */
@Override
public boolean isPrintValue(Object bean, Object bean2, String attrName, StoreDescription desc) {
    boolean isPrint = super.isPrintValue(bean, bean2, attrName, desc);
    if (isPrint) {
        if ("jkHome".equals(attrName)) {
            Connector connector = ((Connector) bean);
            File catalinaBase = getCatalinaBase();
            File jkHomeBase = getJkHomeBase((String) connector.getProperty("jkHome"), catalinaBase);
            isPrint = !catalinaBase.equals(jkHomeBase);
        }
    }
    return isPrint;
}
Also used : Connector(org.apache.catalina.connector.Connector) File(java.io.File)

Example 43 with Connector

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

the class TestRequestFilterValve method oneTest.

private void oneTest(String allow, String deny, boolean denyStatus, boolean addConnectorPort, boolean auth, String property, String type, boolean allowed) {
    // PREPARE
    RequestFilterValve valve = null;
    Connector connector = new Connector();
    Context context = new StandardContext();
    Request request = new Request(connector);
    Response response = new MockResponse();
    StringBuilder msg = new StringBuilder();
    int expected = allowed ? OK : FORBIDDEN;
    connector.setPort(PORT);
    request.getMappingData().context = context;
    request.setCoyoteRequest(new org.apache.coyote.Request());
    Assert.assertNotNull("Invalid test with null type", type);
    if (property != null) {
        if (type.equals("Addr")) {
            valve = new RemoteAddrValve();
            request.setRemoteAddr(property);
            msg.append(" ip='" + property + "'");
        } else if (type.equals("Host")) {
            valve = new RemoteHostValve();
            request.setRemoteHost(property);
            msg.append(" host='" + property + "'");
        }
    }
    Assert.assertNotNull("Invalid test type" + type, valve);
    valve.setNext(new TerminatingValve());
    if (allow != null) {
        valve.setAllow(allow);
        msg.append(" allow='" + allow + "'");
    }
    if (deny != null) {
        valve.setDeny(deny);
        msg.append(" deny='" + deny + "'");
    }
    if (denyStatus) {
        valve.setDenyStatus(CUSTOM);
        msg.append(" denyStatus='" + CUSTOM + "'");
        if (!allowed) {
            expected = CUSTOM;
        }
    }
    if (addConnectorPort) {
        if (valve instanceof RemoteAddrValve) {
            ((RemoteAddrValve) valve).setAddConnectorPort(true);
        } else if (valve instanceof RemoteHostValve) {
            ((RemoteHostValve) valve).setAddConnectorPort(true);
        } else {
            fail("Can only set 'addConnectorPort' for RemoteAddrValve and RemoteHostValve");
        }
        msg.append(" addConnectorPort='true'");
    }
    if (auth) {
        context.setPreemptiveAuthentication(true);
        valve.setInvalidAuthenticationWhenDeny(true);
        msg.append(" auth='true'");
    }
    // TEST
    try {
        valve.invoke(request, response);
    } catch (IOException ex) {
    //Ignore
    } catch (ServletException ex) {
    //Ignore
    }
    // VERIFY
    if (!allowed && auth) {
        assertEquals(msg.toString(), OK, response.getStatus());
        assertEquals(msg.toString(), "invalid", request.getHeader("authorization"));
    } else {
        assertEquals(msg.toString(), expected, response.getStatus());
    }
}
Also used : Context(org.apache.catalina.Context) StandardContext(org.apache.catalina.core.StandardContext) Connector(org.apache.catalina.connector.Connector) Request(org.apache.catalina.connector.Request) IOException(java.io.IOException) Response(org.apache.catalina.connector.Response) ServletException(javax.servlet.ServletException) StandardContext(org.apache.catalina.core.StandardContext)

Example 44 with Connector

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

the class Http2TestBase method enableHttp2.

protected void enableHttp2(long maxConcurrentStreams) {
    Connector connector = getTomcatInstance().getConnector();
    Http2Protocol http2Protocol = new Http2Protocol();
    // Short timeouts for now. May need to increase these for CI systems.
    http2Protocol.setReadTimeout(2000);
    http2Protocol.setKeepAliveTimeout(5000);
    http2Protocol.setWriteTimeout(2000);
    http2Protocol.setMaxConcurrentStreams(maxConcurrentStreams);
    connector.addUpgradeProtocol(http2Protocol);
}
Also used : Connector(org.apache.catalina.connector.Connector)

Example 45 with Connector

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

the class ConnectorCreateRule method begin.

// --------------------------------------------------------- Public Methods
/**
     * Process the beginning of this element.
     *
     * @param namespace the namespace URI of the matching element, or an
     *   empty string if the parser is not namespace aware or the element has
     *   no namespace
     * @param name the local name if the parser is namespace aware, or just
     *   the element name otherwise
     * @param attributes The attribute list for this element
     */
@Override
public void begin(String namespace, String name, Attributes attributes) throws Exception {
    Service svc = (Service) digester.peek();
    Executor ex = null;
    if (attributes.getValue("executor") != null) {
        ex = svc.getExecutor(attributes.getValue("executor"));
    }
    Connector con = new Connector(attributes.getValue("protocol"));
    if (ex != null) {
        setExecutor(con, ex);
    }
    String sslImplementationName = attributes.getValue("sslImplementationName");
    if (sslImplementationName != null) {
        setSSLImplementationName(con, sslImplementationName);
    }
    digester.push(con);
}
Also used : Connector(org.apache.catalina.connector.Connector) Executor(org.apache.catalina.Executor) Service(org.apache.catalina.Service)

Aggregations

Connector (org.apache.catalina.connector.Connector)70 Test (org.junit.Test)16 Service (org.apache.catalina.Service)15 File (java.io.File)12 Tomcat (org.apache.catalina.startup.Tomcat)11 Properties (java.util.Properties)8 Context (org.apache.catalina.Context)7 HashMap (java.util.HashMap)6 Engine (org.apache.catalina.Engine)6 SSLHostConfig (org.apache.tomcat.util.net.SSLHostConfig)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 StandardService (org.apache.catalina.core.StandardService)5 URI (java.net.URI)4 Executor (org.apache.catalina.Executor)4 LifecycleException (org.apache.catalina.LifecycleException)4 Server (org.apache.catalina.Server)4 Http2Protocol (org.apache.coyote.http2.Http2Protocol)4 ObjectName (javax.management.ObjectName)3