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;
}
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);
}
});
}
};
}
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;
}
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));
}
Aggregations