Search in sources :

Example 46 with Connector

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

the class TestHttp2Limits method doTestCookieLimit.

private void doTestCookieLimit(int cookieCount, int maxCookieCount, int failMode) throws Exception {
    enableHttp2();
    Connector connector = getTomcatInstance().getConnector();
    connector.setMaxCookieCount(maxCookieCount);
    configureAndStartWebApplication();
    openClientConnection();
    doHttpUpgrade();
    sendClientPreface();
    validateHttp2InitialResponse();
    output.setTraceBody(true);
    byte[] frameHeader = new byte[9];
    ByteBuffer headersPayload = ByteBuffer.allocate(8192);
    List<String[]> customHeaders = new ArrayList<>();
    for (int i = 0; i < cookieCount; i++) {
        customHeaders.add(new String[] { "Cookie", "a" + cookieCount + "=b" + cookieCount });
    }
    populateHeadersPayload(headersPayload, customHeaders, "/cookie");
    populateFrameHeader(frameHeader, 0, headersPayload.limit(), headersPayload.limit(), 3);
    writeFrame(frameHeader, headersPayload);
    switch(failMode) {
        case 0:
            {
                parser.readFrame(true);
                parser.readFrame(true);
                parser.readFrame(true);
                System.out.println(output.getTrace());
                Assert.assertEquals(getCookieResponseTrace(3, cookieCount), output.getTrace());
                break;
            }
        case 1:
            {
                // Check status is 500
                parser.readFrame(true);
                Assert.assertTrue(output.getTrace(), output.getTrace().startsWith("3-HeadersStart\n3-Header-[:status]-[500]"));
                output.clearTrace();
                // Check EOS followed by reset is next
                parser.readFrame(true);
                parser.readFrame(true);
                Assert.assertEquals("3-EndOfStream\n3-RST-[2]\n", output.getTrace());
                break;
            }
        default:
            {
                Assert.fail("Unknown failure mode specified");
            }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 47 with Connector

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

the class TestHttp2Section_6_8 method testGoawayIgnoreNewStreams.

@Test
public void testGoawayIgnoreNewStreams() throws Exception {
    setPingAckDelayMillis(PNG_ACK_DELAY_MS);
    // HTTP2 upgrade - need longer timeouts for this test
    Connector connector = getTomcatInstance().getConnector();
    Http2Protocol http2Protocol = new Http2Protocol();
    // Short timeouts for now. May need to increase these for CI systems.
    http2Protocol.setReadTimeout(5000);
    http2Protocol.setKeepAliveTimeout(10000);
    http2Protocol.setWriteTimeout(5000);
    http2Protocol.setMaxConcurrentStreams(200);
    connector.addUpgradeProtocol(http2Protocol);
    configureAndStartWebApplication();
    openClientConnection();
    doHttpUpgrade();
    sendClientPreface();
    validateHttp2InitialResponse();
    Thread.sleep(PNG_ACK_DELAY_MS + TIMING_MARGIN_MS);
    getTomcatInstance().getConnector().pause();
    // Go away
    parser.readFrame(true);
    Assert.assertEquals("0-Goaway-[2147483647]-[0]-[null]", output.getTrace());
    output.clearTrace();
    // Should be processed
    sendSimpleGetRequest(3);
    Thread.sleep(PNG_ACK_DELAY_MS + TIMING_MARGIN_MS);
    // Should be ignored
    sendSimpleGetRequest(5);
    parser.readFrame(true);
    parser.readFrame(true);
    Assert.assertEquals(getSimpleResponseTrace(3), output.getTrace());
    output.clearTrace();
    // Finally the go away frame
    parser.readFrame(true);
    Assert.assertEquals("0-Goaway-[3]-[0]-[null]", output.getTrace());
}
Also used : Connector(org.apache.catalina.connector.Connector) Test(org.junit.Test)

Example 48 with Connector

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

the class ConnectorMBean method setAttribute.

/**
     * Set the value of a specific attribute of this MBean.
     *
     * @param attribute The identification of the attribute to be set
     *  and the new value
     *
     * @exception AttributeNotFoundException if this attribute is not
     *  supported by this MBean
     * @exception MBeanException if the initializer of an object
     *  throws an exception
     * @exception ReflectionException if a Java reflection exception
     *  occurs when invoking the getter
     */
@Override
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException {
    // Validate the input parameters
    if (attribute == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute is null"), "Attribute is null");
    }
    String name = attribute.getName();
    Object value = attribute.getValue();
    if (name == null) {
        throw new RuntimeOperationsException(new IllegalArgumentException("Attribute name is null"), "Attribute name is null");
    }
    Connector connector = doGetManagedResource();
    IntrospectionUtils.setProperty(connector, name, String.valueOf(value));
}
Also used : Connector(org.apache.catalina.connector.Connector) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 49 with Connector

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

the class MBeanFactory method removeConnector.

/**
     * Remove an existing Connector.
     *
     * @param name MBean Name of the component to remove
     *
     * @exception Exception if a component cannot be removed
     */
public void removeConnector(String name) throws Exception {
    // Acquire a reference to the component to be removed
    ObjectName oname = new ObjectName(name);
    Service service = getService(oname);
    String port = oname.getKeyProperty("port");
    //String address = oname.getKeyProperty("address");
    Connector[] conns = service.findConnectors();
    for (int i = 0; i < conns.length; i++) {
        String connAddress = String.valueOf(conns[i].getProperty("address"));
        String connPort = "" + conns[i].getPort();
        // if (((address.equals("null")) &&
        if ((connAddress == null) && port.equals(connPort)) {
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
        // } else if (address.equals(connAddress))
        if (port.equals(connPort)) {
            // Remove this component from its parent component
            service.removeConnector(conns[i]);
            conns[i].destroy();
            break;
        }
    }
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

Example 50 with Connector

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

the class MBeanFactory method createConnector.

/**
     * Create a new Connector
     *
     * @param parent MBean Name of the associated parent component
     * @param address The IP address on which to bind
     * @param port TCP port number to listen on
     * @param isAjp Create a AJP/1.3 Connector
     * @param isSSL Create a secure Connector
     *
     * @exception Exception if an MBean cannot be created or registered
     */
private String createConnector(String parent, String address, int port, boolean isAjp, boolean isSSL) throws Exception {
    // Set the protocol in the constructor
    String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";
    Connector retobj = new Connector(protocol);
    if ((address != null) && (address.length() > 0)) {
        retobj.setProperty("address", address);
    }
    // Set port number
    retobj.setPort(port);
    // Set SSL
    retobj.setSecure(isSSL);
    retobj.setScheme(isSSL ? "https" : "http");
    // Add the new instance to its parent component
    // FIX ME - addConnector will fail
    ObjectName pname = new ObjectName(parent);
    Service service = getService(pname);
    service.addConnector(retobj);
    // Return the corresponding MBean name
    ObjectName coname = retobj.getObjectName();
    return (coname.toString());
}
Also used : Connector(org.apache.catalina.connector.Connector) StandardService(org.apache.catalina.core.StandardService) Service(org.apache.catalina.Service) ObjectName(javax.management.ObjectName)

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