Exemplo n.º 1
0
    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());
                }
              }
            }
          });
    }
Exemplo n.º 2
0
 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);
             }
           }
         }
       });
 }
Exemplo n.º 3
0
    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);
              }
            }
          });
    }