Search in sources :

Example 16 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project spring-boot by spring-projects.

the class SampleTomcatApplicationTests method testTimeout.

@Test
public void testTimeout() throws Exception {
    ServletWebServerApplicationContext context = (ServletWebServerApplicationContext) this.applicationContext;
    TomcatWebServer embeddedServletContainer = (TomcatWebServer) context.getWebServer();
    ProtocolHandler protocolHandler = embeddedServletContainer.getTomcat().getConnector().getProtocolHandler();
    int timeout = ((AbstractProtocol<?>) protocolHandler).getConnectionTimeout();
    assertThat(timeout).isEqualTo(5000);
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractProtocol(org.apache.coyote.AbstractProtocol) TomcatWebServer(org.springframework.boot.web.embedded.tomcat.TomcatWebServer) ServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project spring-boot by spring-projects.

the class TomcatServletWebServerFactory method customizeSsl.

private void customizeSsl(Connector connector) {
    ProtocolHandler handler = connector.getProtocolHandler();
    Assert.state(handler instanceof AbstractHttp11JsseProtocol, "To use SSL, the connector's protocol handler must be an " + "AbstractHttp11JsseProtocol subclass");
    configureSsl((AbstractHttp11JsseProtocol<?>) handler, getSsl());
    connector.setScheme("https");
    connector.setSecure(true);
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol)

Example 18 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project spring-boot by spring-projects.

the class TomcatServletWebServerFactory method customizeCompression.

private void customizeCompression(Connector connector) {
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof AbstractHttp11Protocol) {
        AbstractHttp11Protocol<?> protocol = (AbstractHttp11Protocol<?>) handler;
        Compression compression = getCompression();
        protocol.setCompression("on");
        protocol.setCompressionMinSize(compression.getMinResponseSize());
        protocol.setCompressableMimeType(StringUtils.arrayToCommaDelimitedString(compression.getMimeTypes()));
        if (getCompression().getExcludedUserAgents() != null) {
            protocol.setNoCompressionUserAgents(StringUtils.arrayToCommaDelimitedString(getCompression().getExcludedUserAgents()));
        }
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Compression(org.springframework.boot.web.server.Compression) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol)

Example 19 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project apollo by ctripcorp.

the class TomcatContainerCustomizer method customize.

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
        return;
    }
    if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
        return;
    }
    TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
    tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {

        @Override
        public void customize(Connector connector) {
            ProtocolHandler handler = connector.getProtocolHandler();
            if (handler instanceof Http11NioProtocol) {
                Http11NioProtocol http = (Http11NioProtocol) handler;
                int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT));
                http.setBacklog(acceptCount);
                logger.info("Setting tomcat accept count to {}", acceptCount);
            }
        }
    });
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Connector(org.apache.catalina.connector.Connector) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer)

Example 20 with ProtocolHandler

use of org.apache.coyote.ProtocolHandler in project tomcat by apache.

the class ManagerServlet method sslReload.

protected void sslReload(PrintWriter writer, String tlsHostName, StringManager smClient) {
    Connector[] connectors = getConnectors();
    boolean found = false;
    for (Connector connector : connectors) {
        if (Boolean.TRUE.equals(connector.getProperty("SSLEnabled"))) {
            ProtocolHandler protocol = connector.getProtocolHandler();
            if (protocol instanceof AbstractHttp11Protocol<?>) {
                AbstractHttp11Protocol<?> http11Protoocol = (AbstractHttp11Protocol<?>) protocol;
                if (tlsHostName == null || tlsHostName.length() == 0) {
                    found = true;
                    http11Protoocol.reloadSslHostConfigs();
                } else {
                    SSLHostConfig[] sslHostConfigs = http11Protoocol.findSslHostConfigs();
                    for (SSLHostConfig sslHostConfig : sslHostConfigs) {
                        // comparison as host names are case insensitive.
                        if (sslHostConfig.getHostName().equalsIgnoreCase(tlsHostName)) {
                            found = true;
                            http11Protoocol.reloadSslHostConfig(tlsHostName);
                        }
                    }
                }
            }
        }
    }
    if (found) {
        if (tlsHostName == null || tlsHostName.length() == 0) {
            writer.println(smClient.getString("managerServlet.sslReloadAll"));
        } else {
            writer.println(smClient.getString("managerServlet.sslReload", tlsHostName));
        }
    } else {
        writer.println(smClient.getString("managerServlet.sslReloadFail"));
    }
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) Connector(org.apache.catalina.connector.Connector) SSLHostConfig(org.apache.tomcat.util.net.SSLHostConfig) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol)

Aggregations

ProtocolHandler (org.apache.coyote.ProtocolHandler)27 AbstractProtocol (org.apache.coyote.AbstractProtocol)8 Connector (org.apache.catalina.connector.Connector)7 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)7 Tomcat (org.apache.catalina.startup.Tomcat)5 AbstractHttp11JsseProtocol (org.apache.coyote.http11.AbstractHttp11JsseProtocol)5 SocketException (java.net.SocketException)4 Service (org.apache.catalina.Service)4 SSLException (javax.net.ssl.SSLException)3 File (java.io.File)2 Executor (java.util.concurrent.Executor)2 ObjectName (javax.management.ObjectName)2 Context (org.apache.catalina.Context)2 Engine (org.apache.catalina.Engine)2 Http11AprProtocol (org.apache.coyote.http11.Http11AprProtocol)2 Http11NioProtocol (org.apache.coyote.http11.Http11NioProtocol)2 Http11Protocol (org.apache.coyote.http11.Http11Protocol)2 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)2 ThreadPoolExecutor (org.apache.tomcat.util.threads.ThreadPoolExecutor)2 Test (org.junit.jupiter.api.Test)2