Search in sources :

Example 11 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project spring-boot-examples by ityouknow.

the class FastDFSApplication method tomcatEmbedded.

// Tomcat large file upload connection reset
@Bean
public TomcatEmbeddedServletContainerFactory tomcatEmbedded() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
    });
    return tomcat;
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) SpringBootApplication(org.springframework.boot.autoconfigure.SpringBootApplication) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Example 12 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project metasfresh-webui-api by metasfresh.

the class WebRestApiApplication method servletContainerCustomizer.

@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(final ConfigurableEmbeddedServletContainer servletContainer) {
            final TomcatEmbeddedServletContainerFactory tomcatContainerFactory = (TomcatEmbeddedServletContainerFactory) servletContainer;
            tomcatContainerFactory.addConnectorCustomizers(new TomcatConnectorCustomizer() {

                @Override
                public void customize(final Connector connector) {
                    final AbstractHttp11Protocol<?> httpProtocol = (AbstractHttp11Protocol<?>) connector.getProtocolHandler();
                    httpProtocol.setCompression("on");
                    httpProtocol.setCompressionMinSize(256);
                    final String mimeTypes = httpProtocol.getCompressibleMimeType();
                    final String mimeTypesWithJson = mimeTypes + "," + MediaType.APPLICATION_JSON_VALUE + ",application/javascript";
                    httpProtocol.setCompressibleMimeType(mimeTypesWithJson);
                }
            });
        }
    };
}
Also used : Connector(org.apache.catalina.connector.Connector) ConfigurableEmbeddedServletContainer(org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) TomcatConnectorCustomizer(org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer) EmbeddedServletContainerCustomizer(org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer) AbstractHttp11Protocol(org.apache.coyote.http11.AbstractHttp11Protocol) Bean(org.springframework.context.annotation.Bean)

Example 13 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project account-identity by cryptofiat.

the class AccountMapperApplication method servletContainer.

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    if (tomcatAjpEnabled) {
        Connector ajpConnector = new Connector("AJP/1.3");
        ajpConnector.setProtocol("AJP/1.3");
        ajpConnector.setPort(ajpPort);
        ajpConnector.setSecure(false);
        ajpConnector.setAllowTrace(false);
        ajpConnector.setScheme("http");
        tomcat.addAdditionalTomcatConnectors(ajpConnector);
    }
    return tomcat;
}
Also used : Connector(org.apache.catalina.connector.Connector) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) Bean(org.springframework.context.annotation.Bean)

Example 14 with TomcatEmbeddedServletContainerFactory

use of org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory in project nzbhydra2 by theotherp.

the class HydraEmbeddedServletContainer method customize.

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
        // Is the case in tests
        return;
    }
    TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) container;
    containerFactory.addContextValves(new ValveBase() {

        @Override
        public void invoke(Request request, Response response) throws IOException, ServletException {
            int originalPort = -1;
            final String forwardedPort = request.getHeader("X-Forwarded-Port");
            if (forwardedPort != null) {
                try {
                    originalPort = request.getServerPort();
                    request.setServerPort(Integer.valueOf(forwardedPort));
                } catch (final NumberFormatException e) {
                    logger.debug("ignoring forwarded port {}", forwardedPort);
                }
            }
            final MessageBytes serverNameMB = request.getCoyoteRequest().serverName();
            String originalServerName = null;
            String forwardedHost = request.getHeader("X-Forwarded-Host");
            if (forwardedHost == null) {
                forwardedHost = request.getHeader("host");
            }
            if (forwardedHost != null) {
                int colonIndex = forwardedHost.indexOf(":");
                if (colonIndex > -1) {
                    if (originalPort == -1) {
                        originalPort = request.getServerPort();
                    }
                    request.setServerPort(Integer.valueOf(forwardedHost.substring(colonIndex + 1)));
                    forwardedHost = forwardedHost.substring(0, colonIndex);
                }
                originalServerName = serverNameMB.getString();
                serverNameMB.setString(forwardedHost);
            }
            Boolean originallySecure = null;
            final String forwardedProto = request.getHeader("X-Forwarded-Proto");
            if (forwardedProto != null) {
                originallySecure = request.isSecure();
                request.setSecure(forwardedProto.equalsIgnoreCase("https"));
            }
            try {
                getNext().invoke(request, response);
            } finally {
                if (originallySecure != null) {
                    request.setSecure(originallySecure);
                }
                if (forwardedHost != null) {
                    serverNameMB.setString(originalServerName);
                }
                if (forwardedPort != null) {
                    request.setServerPort(originalPort);
                }
            }
        }
    });
    ((TomcatEmbeddedServletContainerFactory) container).addContextCustomizers(context -> context.setMapperContextRootRedirectEnabled(true));
}
Also used : Response(org.apache.catalina.connector.Response) ServletException(javax.servlet.ServletException) TomcatEmbeddedServletContainerFactory(org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory) Request(org.apache.catalina.connector.Request) MessageBytes(org.apache.tomcat.util.buf.MessageBytes) ValveBase(org.apache.catalina.valves.ValveBase) IOException(java.io.IOException)

Aggregations

TomcatEmbeddedServletContainerFactory (org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory)14 Bean (org.springframework.context.annotation.Bean)11 Connector (org.apache.catalina.connector.Connector)6 TomcatConnectorCustomizer (org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer)4 Context (org.apache.catalina.Context)3 AbstractHttp11Protocol (org.apache.coyote.http11.AbstractHttp11Protocol)3 SecurityCollection (org.apache.tomcat.util.descriptor.web.SecurityCollection)3 SecurityConstraint (org.apache.tomcat.util.descriptor.web.SecurityConstraint)3 SpringApplication (org.springframework.boot.SpringApplication)2 SpringBootApplication (org.springframework.boot.autoconfigure.SpringBootApplication)2 ConsumerContextConfig (com.dell.cpsd.service.common.client.context.ConsumerContextConfig)1 IOException (java.io.IOException)1 Base64 (java.util.Base64)1 ServletException (javax.servlet.ServletException)1 Request (org.apache.catalina.connector.Request)1 Response (org.apache.catalina.connector.Response)1 CombinedRealm (org.apache.catalina.realm.CombinedRealm)1 RealmBase (org.apache.catalina.realm.RealmBase)1 ValveBase (org.apache.catalina.valves.ValveBase)1 ProtocolHandler (org.apache.coyote.ProtocolHandler)1