Search in sources :

Example 21 with ProtocolHandler

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

the class SslConnectorCustomizer method customize.

@Override
public void customize(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, this.ssl, this.sslStoreProvider);
    connector.setScheme("https");
    connector.setSecure(true);
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractHttp11JsseProtocol(org.apache.coyote.http11.AbstractHttp11JsseProtocol)

Example 22 with ProtocolHandler

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

the class TomcatServletWebServerFactoryTests method tomcatProtocolHandlerCanBeCustomized.

@Test
void tomcatProtocolHandlerCanBeCustomized() {
    TomcatServletWebServerFactory factory = getFactory();
    TomcatProtocolHandlerCustomizer<AbstractHttp11Protocol<?>> customizer = (protocolHandler) -> protocolHandler.setProcessorCache(250);
    factory.addProtocolHandlerCustomizers(customizer);
    Tomcat tomcat = getTomcat(factory);
    Connector connector = ((TomcatWebServer) this.webServer).getServiceConnectors().get(tomcat.getService())[0];
    AbstractHttp11Protocol<?> protocolHandler = (AbstractHttp11Protocol<?>) connector.getProtocolHandler();
    assertThat(protocolHandler.getProcessorCache()).isEqualTo(250);
}
Also used : Arrays(java.util.Arrays) URISyntaxException(java.net.URISyntaxException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NoHttpResponseException(org.apache.http.NoHttpResponseException) NamingException(javax.naming.NamingException) ServletException(jakarta.servlet.ServletException) LifecycleListener(org.apache.catalina.LifecycleListener) ByteArrayResource(org.springframework.core.io.ByteArrayResource) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) Future(java.util.concurrent.Future) Locale(java.util.Locale) Duration(java.time.Duration) Map(java.util.Map) LifecycleState(org.apache.catalina.LifecycleState) PortInUseException(org.springframework.boot.web.server.PortInUseException) RestTemplate(org.springframework.web.client.RestTemplate) AprLifecycleListener(org.apache.catalina.core.AprLifecycleListener) InitialContext(javax.naming.InitialContext) JspServlet(org.apache.jasper.servlet.JspServlet) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) SessionIdGenerator(org.apache.catalina.SessionIdGenerator) AbstractServletWebServerFactoryTests(org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests) FileSystemUtils(org.springframework.util.FileSystemUtils) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) HttpEntity(org.springframework.http.HttpEntity) JarScanFilter(org.apache.tomcat.JarScanFilter) Mockito.inOrder(org.mockito.Mockito.inOrder) ServletContext(jakarta.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) Awaitility(org.awaitility.Awaitility) HttpClients(org.apache.http.impl.client.HttpClients) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) LifecycleEvent(org.apache.catalina.LifecycleEvent) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) WebServerException(org.springframework.boot.web.server.WebServerException) Valve(org.apache.catalina.Valve) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) HashMap(java.util.HashMap) Dynamic(jakarta.servlet.ServletRegistration.Dynamic) Connector(org.apache.catalina.connector.Connector) AtomicReference(java.util.concurrent.atomic.AtomicReference) SocketException(java.net.SocketException) CharsetMapper(org.apache.catalina.util.CharsetMapper) ThrowingCallable(org.assertj.core.api.ThrowableAssert.ThrowingCallable) ArgumentCaptor(org.mockito.ArgumentCaptor) Charset(java.nio.charset.Charset) Shutdown(org.springframework.boot.web.server.Shutdown) HttpClient(org.apache.http.client.HttpClient) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Service(org.apache.catalina.Service) RemoteIpValve(org.apache.catalina.valves.RemoteIpValve) InOrder(org.mockito.InOrder) JarScanType(org.apache.tomcat.JarScanType) MultiValueMap(org.springframework.util.MultiValueMap) BDDMockito.then(org.mockito.BDDMockito.then) IOException(java.io.IOException) Context(org.apache.catalina.Context) HttpServlet(jakarta.servlet.http.HttpServlet) File(java.io.File) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) Tomcat(org.apache.catalina.startup.Tomcat) HttpStatus(org.springframework.http.HttpStatus) AfterEach(org.junit.jupiter.api.AfterEach) Container(org.apache.catalina.Container) ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractServletWebServerFactory(org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) HttpResponse(org.apache.http.HttpResponse) StandardWrapper(org.apache.catalina.core.StandardWrapper) ResponseEntity(org.springframework.http.ResponseEntity) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) CapturedOutput(org.springframework.boot.testsupport.system.CapturedOutput) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Connector(org.apache.catalina.connector.Connector) Tomcat(org.apache.catalina.startup.Tomcat) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Test(org.junit.jupiter.api.Test)

Example 23 with ProtocolHandler

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

the class TomcatWebServerFactoryCustomizer method customizeMinThreads.

@SuppressWarnings("rawtypes")
private void customizeMinThreads(ConfigurableTomcatWebServerFactory factory, int minSpareThreads) {
    factory.addConnectorCustomizers((connector) -> {
        ProtocolHandler handler = connector.getProtocolHandler();
        if (handler instanceof AbstractProtocol) {
            AbstractProtocol protocol = (AbstractProtocol) handler;
            protocol.setMinSpareThreads(minSpareThreads);
        }
    });
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractProtocol(org.apache.coyote.AbstractProtocol)

Example 24 with ProtocolHandler

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

the class TomcatWebServerFactoryCustomizer method customizeConnectionTimeout.

private void customizeConnectionTimeout(ConfigurableTomcatWebServerFactory factory, Duration connectionTimeout) {
    factory.addConnectorCustomizers((connector) -> {
        ProtocolHandler handler = connector.getProtocolHandler();
        if (handler instanceof AbstractProtocol) {
            AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
            protocol.setConnectionTimeout((int) connectionTimeout.toMillis());
        }
    });
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractProtocol(org.apache.coyote.AbstractProtocol)

Example 25 with ProtocolHandler

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

the class TomcatWebServerFactoryCustomizer method customizeMaxConnections.

private void customizeMaxConnections(ConfigurableTomcatWebServerFactory factory, int maxConnections) {
    factory.addConnectorCustomizers((connector) -> {
        ProtocolHandler handler = connector.getProtocolHandler();
        if (handler instanceof AbstractProtocol) {
            AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
            protocol.setMaxConnections(maxConnections);
        }
    });
}
Also used : ProtocolHandler(org.apache.coyote.ProtocolHandler) AbstractProtocol(org.apache.coyote.AbstractProtocol)

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