private void customizeMaxHttpPostSize( JettyEmbeddedServletContainerFactory factory, final int maxHttpPostSize) { factory.addServerCustomizers( new JettyServerCustomizer() { @Override public void customize(Server server) { setHandlerMaxHttpPostSize(maxHttpPostSize, server.getHandlers()); } private void setHandlerMaxHttpPostSize(int maxHttpPostSize, Handler... handlers) { for (Handler handler : handlers) { if (handler instanceof ContextHandler) { ((ContextHandler) handler).setMaxFormContentSize(maxHttpPostSize); } else if (handler instanceof HandlerWrapper) { setHandlerMaxHttpPostSize( maxHttpPostSize, ((HandlerWrapper) handler).getHandler()); } else if (handler instanceof HandlerCollection) { setHandlerMaxHttpPostSize( maxHttpPostSize, ((HandlerCollection) handler).getHandlers()); } } } }); }
void customizeJetty( final ServerProperties serverProperties, JettyEmbeddedServletContainerFactory factory) { factory.setUseForwardHeaders(serverProperties.getOrDeduceUseForwardHeaders()); if (this.acceptors != null) { factory.setAcceptors(this.acceptors); } if (this.selectors != null) { factory.setSelectors(this.selectors); } if (serverProperties.getMaxHttpHeaderSize() > 0) { customizeMaxHttpHeaderSize(factory, serverProperties.getMaxHttpHeaderSize()); } if (serverProperties.getMaxHttpPostSize() > 0) { customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize()); } if (serverProperties.getConnectionTimeout() != null) { customizeConnectionTimeout(factory, serverProperties.getConnectionTimeout()); } }
private void customizeConnectionTimeout( JettyEmbeddedServletContainerFactory factory, final int connectionTimeout) { factory.addServerCustomizers( new JettyServerCustomizer() { @Override public void customize(Server server) { for (org.eclipse.jetty.server.Connector connector : server.getConnectors()) { if (connector instanceof AbstractConnector) { ((AbstractConnector) connector).setIdleTimeout(connectionTimeout); } } } }); }
private void customizeMaxHttpHeaderSize( JettyEmbeddedServletContainerFactory factory, final int maxHttpHeaderSize) { factory.addServerCustomizers( new JettyServerCustomizer() { @Override public void customize(Server server) { for (org.eclipse.jetty.server.Connector connector : server.getConnectors()) { try { for (ConnectionFactory connectionFactory : connector.getConnectionFactories()) { if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) { customize((HttpConfiguration.ConnectionFactory) connectionFactory); } } } catch (NoSuchMethodError ex) { customizeOnJetty8(connector, maxHttpHeaderSize); } } } private void customize(HttpConfiguration.ConnectionFactory factory) { HttpConfiguration configuration = factory.getHttpConfiguration(); configuration.setRequestHeaderSize(maxHttpHeaderSize); configuration.setResponseHeaderSize(maxHttpHeaderSize); } private void customizeOnJetty8( org.eclipse.jetty.server.Connector connector, int maxHttpHeaderSize) { try { connector .getClass() .getMethod("setRequestHeaderSize", int.class) .invoke(connector, maxHttpHeaderSize); connector .getClass() .getMethod("setResponseHeaderSize", int.class) .invoke(connector, maxHttpHeaderSize); } catch (Exception ex) { throw new RuntimeException(ex); } } }); }
@Bean public EmbeddedServletContainerFactory containerFactory() { JettyEmbeddedServletContainerFactory factory = new JettyEmbeddedServletContainerFactory(0); factory.setContextPath(this.env.getProperty("context")); return factory; }