org.apache.coyote.http11.Http11NioProtocol Java Examples

The following examples show how to use org.apache.coyote.http11.Http11NioProtocol. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TomcatConfig.java    From enhanced-pet-clinic with Apache License 2.0 6 votes vote down vote up
private Connector createSslConnector() {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	try {
		connector.setScheme("https");
		connector.setSecure(true);
		connector.setPort(tlsPort);

		File keystore = getKeyStoreFile();
		File truststore = keystore;

		protocol.setSSLEnabled(true);
		protocol.setKeystoreFile(keystore.getAbsolutePath());
		protocol.setKeystorePass(sslKeystorePassword);
		protocol.setTruststoreFile(truststore.getAbsolutePath());
		protocol.setTruststorePass(sslKeystorePassword);
		protocol.setKeyAlias(sslKeystoreAlias);
		return connector;
	} catch (IOException ex) {
		throw new IllegalStateException(
				"can't access keystore: [" + "keystore" + "] or truststore: [" + "keystore" + "]", ex);
	}
}
 
Example #2
Source File: TomcatWebSocketTestServer.java    From bearchoke with Apache License 2.0 6 votes vote down vote up
public TomcatWebSocketTestServer(int port) {

		this.port = port;

		Connector connector = new Connector(Http11NioProtocol.class.getName());
        connector.setPort(this.port);

        File baseDir = createTempDir("tomcat");
        String baseDirPath = baseDir.getAbsolutePath();

		this.tomcatServer = new Tomcat();
		this.tomcatServer.setBaseDir(baseDirPath);
		this.tomcatServer.setPort(this.port);
        this.tomcatServer.getService().addConnector(connector);
        this.tomcatServer.setConnector(connector);
	}
 
Example #3
Source File: HttpProxyContainer.java    From odo with Apache License 2.0 6 votes vote down vote up
private Connector createSslConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    final int httpsPort = Utils.getSystemPort(Constants.SYS_HTTPS_PORT);
    try {
        File keyStore = com.groupon.odo.proxylib.Utils.copyResourceToLocalFile("tomcat.ks", "tomcat.ks");
        connector.setScheme("https");
        connector.setSecure(true);
        connector.setPort(httpsPort);
        protocol.setSSLEnabled(true);
        protocol.setSslProtocol("TLS");
        protocol.setKeystoreFile(keyStore.getAbsolutePath());
        protocol.setKeystorePass("changeit");
        return connector;
    } catch (IOException ex) {
        throw new IllegalStateException("can't access keystore: [" + "keystore"
                                            + "] or truststore: [" + "keystore" + "]", ex);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #4
Source File: TomcatConfig.java    From tailstreamer with MIT License 6 votes vote down vote up
private Connector createSslConnector() {
    if (sslConfig == null) {
        throw new IllegalStateException("SSL configuration not specified");
    }

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    connector.setScheme("https");
    connector.setSecure(true);
    connector.setPort(sslConfig.getPort());
    protocol.setSSLEnabled(sslConfig.isEnable());
    protocol.setKeystoreFile(sslConfig.getKeystore());
    protocol.setKeystorePass(sslConfig.getKeystorePassword());
    protocol.setKeyAlias(sslConfig.getKeyAlias());

    logger.info(String.format("Initializing SSL connector on port %d", sslConfig.getPort()));
    return connector;
}
 
Example #5
Source File: BrokerApplication.java    From WeEvent with Apache License 2.0 6 votes vote down vote up
@Bean
public ConfigurableServletWebServerFactory configurableServletWebServerFactory() {
    log.info("custom TomcatServletWebServerFactory");

    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    factory.setProtocol(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);

    factory.addConnectorCustomizers((connector) -> {
                // default max connections = 10000
                // default connection timeout = 20000
                // default max accept count = 100
                // default max worker thread = 200
                connector.setEnableLookups(false);
                connector.setAllowTrace(false);

                Http11NioProtocol http11NioProtocol = (Http11NioProtocol) connector.getProtocolHandler();
                http11NioProtocol.setKeepAliveTimeout(60000);
                http11NioProtocol.setMaxKeepAliveRequests(10000);
                http11NioProtocol.setDisableUploadTimeout(true);
                http11NioProtocol.setTcpNoDelay(true);
            }
    );

    return factory;
}
 
Example #6
Source File: TomcatOnlyApplication.java    From spring-graalvm-native with Apache License 2.0 6 votes vote down vote up
public static void main(String... args) throws Exception {
	Registry.disableRegistry();
	tomcatBase.mkdir();
	docBase.mkdir();
	serverBase.mkdir();

	Tomcat tomcat = new Tomcat();
	tomcat.setBaseDir(serverBase.getAbsolutePath());
	Connector connector = new Connector(Http11NioProtocol.class.getName());
	connector.setPort(8080);
	tomcat.setConnector(connector);

	Context context = tomcat.addContext("", docBase.getAbsolutePath());
	tomcat.addServlet(context, HelloFromTomcatServlet.class.getSimpleName(), new HelloFromTomcatServlet());
	context.addServletMappingDecoded("/*", HelloFromTomcatServlet.class.getSimpleName());
	tomcat.getHost().setAutoDeploy(false);
	tomcat.start();
}
 
Example #7
Source File: TomcatConfig.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * create the https additional connection for tomcat
 */
private Connector initiateHttpsConnector(ServerProperties serverProperties) {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	connector.setScheme(ConstantsTomcat.HTTPS);
	connector.setPort(serverProperties.getServerPort());
	connector.setSecure(true);
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	protocol.setSSLEnabled(true);
	protocol.setKeystoreFile(serverProperties.getHttpsKeyStore());
	protocol.setKeystorePass(serverProperties.getHttpsKeyStorePassword());
	protocol.setKeystoreType(serverProperties.getHttpsKeyStoreType());
	protocol.setKeyPass(serverProperties.getHttpsKeyPassword());
	protocol.setKeyAlias(serverProperties.getHttpsKeyAlias());
	protocol.setMaxHttpHeaderSize(serverProperties.getMaxHttpHeaderSize());
	connector.setRedirectPort(ConstantsTomcat.REDIRECT_PORT);
	connector.setAllowTrace(serverProperties.isAllowTrace());
	return connector;
}
 
Example #8
Source File: TomcatConfig.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * create the https additional connection for tomcat
 */
private Connector initiateHttpsConnector(ServerProperties serverProperties) {
	Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
	connector.setScheme(ConstantsTomcat.HTTPS);
	connector.setPort(serverProperties.getServerPort());
	connector.setSecure(true);
	Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
	protocol.setSSLEnabled(true);
	protocol.setKeystoreFile(serverProperties.getHttpsKeyStore());
	protocol.setKeystorePass(serverProperties.getHttpsKeyStorePassword());
	protocol.setKeystoreType(serverProperties.getHttpsKeyStoreType());
	protocol.setKeyPass(serverProperties.getHttpsKeyPassword());
	protocol.setKeyAlias(serverProperties.getHttpsKeyAlias());
	protocol.setMaxHttpHeaderSize(serverProperties.getMaxHttpHeaderSize());
	connector.setRedirectPort(ConstantsTomcat.REDIRECT_PORT);
	connector.setAllowTrace(serverProperties.isAllowTrace());
	return connector;
}
 
Example #9
Source File: EmbeddedTomcatConfig.java    From blog with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void customize(ConfigurableServletWebServerFactory factory) {
	((TomcatServletWebServerFactory) factory).addConnectorCustomizers(new TomcatConnectorCustomizer() {
		@Override
		public void customize(Connector connector) {
			Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
			protocol.setMaxConnections(200);
			protocol.setMaxThreads(200);
			protocol.setSelectorTimeout(3000);
			protocol.setSessionTimeout(3000);
			protocol.setConnectionTimeout(3000);

			connector.setPort(8888);
		}
	});
}
 
Example #10
Source File: TomcatWebSocketTestServer.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void setup() {
	this.port = SocketUtils.findAvailableTcpPort();

	Connector connector = new Connector(Http11NioProtocol.class.getName());
	connector.setPort(this.port);

	File baseDir = createTempDir("tomcat");
	String baseDirPath = baseDir.getAbsolutePath();

	this.tomcatServer = new Tomcat();
	this.tomcatServer.setBaseDir(baseDirPath);
	this.tomcatServer.setPort(this.port);
	this.tomcatServer.getService().addConnector(connector);
	this.tomcatServer.setConnector(connector);
}
 
Example #11
Source File: TomcatConfiguration.java    From odata with Apache License 2.0 6 votes vote down vote up
private Connector createSslConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    try {
        File keystore = new ClassPathResource(keystorePath).getFile();
        connector.setScheme(HTTPS_SCHEME);
        connector.setSecure(true);
        connector.setPort(Integer.parseInt(httpsPort));
        protocol.setSSLEnabled(true);
        protocol.setKeystoreFile(keystore.getAbsolutePath());
        protocol.setKeystorePass(keystorePasswd);
        protocol.setTruststoreFile(keystore.getAbsolutePath());
        protocol.setTruststorePass(truststorePasswd);
        protocol.setKeyAlias(keyAlias);
        return connector;
    } catch (IOException ex) {
        throw new IllegalStateException("cant access keystore: [" + "keystore"
                + "] or truststore: [" + "keystore" + "]", ex);
    }
}
 
Example #12
Source File: ServletContainerConfiguration.java    From haven-platform with Apache License 2.0 6 votes vote down vote up
/**
 * Configures ssl connector
 *
 * @return
 */
Connector createSslConnector() {
    log.info("About to start ssl connector at port {} with {} keystoreFile", tlsPort, keystoreFile);
    final String absoluteKeystoreFile = new File(keystoreFile).getAbsolutePath();

    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setPort(tlsPort);
    connector.setSecure(true);
    connector.setScheme("https");

    Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();
    proto.setSSLEnabled(true);
    proto.setKeystoreFile(absoluteKeystoreFile);
    proto.setKeystorePass(keystorePass);
    proto.setKeystoreType("PKCS12");
    proto.setSslProtocol("TLSv1.2");
    proto.setKeyAlias("tomcat");
    return connector;
}
 
Example #13
Source File: MBeanUtils.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service)
    throws Exception {

    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol)handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol)handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol)handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol)handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol)handler).getName();
    }
    ObjectName query = new ObjectName(
            domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for(ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
 
Example #14
Source File: TomcatServerFactory.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
static int getLocalPort(Tomcat tomcat) {
    Service[] services = tomcat.getServer().findServices();
    for (Service service : services) {
        for (Connector connector : service.findConnectors()) {
            ProtocolHandler protocolHandler = connector.getProtocolHandler();
            if (protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
                return connector.getLocalPort();
            }
        }
    }
    return 0;
}
 
Example #15
Source File: HttpsConfiguration.java    From spring-boot with Apache License 2.0 5 votes vote down vote up
public Connector createSslConnector() {

        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();

        connector.setPort(properties.getPort());
        connector.setScheme("https");
        connector.setSecure(true);
        protocol.setSSLEnabled(true);
        protocol.setClientAuth("false");
        protocol.setSSLProtocol("TLSv1+TLSv1.1+TLSv1.2");
        protocol.setKeystoreFile(properties.getKeystoreFile());
        protocol.setKeystorePass(properties.getKeystorePassword());
        return connector;
    }
 
Example #16
Source File: MBeanUtils.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Deregister the MBean for this
 * <code>Connector</code> object.
 *
 * @param connector The Connector to be managed
 *
 * @exception Exception if an MBean cannot be deregistered
 * @deprecated  Unused. Will be removed in Tomcat 8.0.x
 */
@Deprecated
static void destroyMBean(Connector connector, Service service)
    throws Exception {

    // domain is engine name
    String domain = service.getContainer().getName();
    if (domain == null)
        domain = mserver.getDefaultDomain();
    ObjectName oname = createObjectName(domain, connector);
    if( mserver.isRegistered( oname ))  {
        mserver.unregisterMBean(oname);
    }
    // Unregister associated request processor
    String worker = null;
    ProtocolHandler handler = connector.getProtocolHandler();
    if (handler instanceof Http11Protocol) {
        worker = ((Http11Protocol)handler).getName();
    } else if (handler instanceof Http11NioProtocol) {
        worker = ((Http11NioProtocol)handler).getName();
    } else if (handler instanceof Http11AprProtocol) {
        worker = ((Http11AprProtocol)handler).getName();
    } else if (handler instanceof AjpProtocol) {
        worker = ((AjpProtocol)handler).getName();
    } else if (handler instanceof AjpAprProtocol) {
        worker = ((AjpAprProtocol)handler).getName();
    }
    ObjectName query = new ObjectName(
            domain + ":type=RequestProcessor,worker=" + worker + ",*");
    Set<ObjectName> results = mserver.queryNames(query, null);
    for(ObjectName result : results) {
        mserver.unregisterMBean(result);
    }
}
 
Example #17
Source File: BootServletContainerCustomizer.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
		if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                (connector) -> {
                	//connector 本身默认是 2 mb
                	connector.setMaxPostSize(FileUtils.parseSize(multipartProperties.getMaxRequestSize()));
                	Http11NioProtocol handler = (Http11NioProtocol)connector.getProtocolHandler();
                	if(tomcatProperties.getBacklog()!=-1){
                		//socket 连接队列大小
//                		handler.setBacklog(tomcatProperties.getBacklog());
                		handler.setAcceptCount(tomcatProperties.getAcceptCount());
                	}
                	if(tomcatProperties.getMaxConnections()!=-1){
                		//最大连接数,默认10000
                		handler.setMaxConnections(tomcatProperties.getMaxConnections());
                	}
                	if(tomcatProperties.getConnectionTimeout()!=-1){
                		handler.setConnectionTimeout(tomcatProperties.getConnectionTimeout());
                	}
                	if(tomcatProperties.getConnectionUploadTimeout()>0){
                		//为true,则上传文件时使用connectionTimeout, 为false,则使用connectionUploadTimeout
                		handler.setDisableUploadTimeout(false);
                		handler.setConnectionUploadTimeout(tomcatProperties.getConnectionUploadTimeout());
                	}
                	connector.setAsyncTimeout(tomcatProperties.getAsyncTimeout());
                }
            );
        }
		/*if(container instanceof TomcatEmbeddedServletContainerFactory){
			TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
			tomcat.addContextCustomizers(context->{
				context.setReloadable(true);
			});
		}*/
	}
 
Example #18
Source File: TomcatConnectorBean.java    From amazon-echo-ha-bridge with Apache License 2.0 5 votes vote down vote up
private Connector createConnector(int portNumber) {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
    connector.setScheme("http");
    connector.setPort(portNumber);
    return connector;
}
 
Example #19
Source File: OAuth2SecurityConfiguration.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
@Bean
  EmbeddedServletContainerCustomizer containerCustomizer(
          @Value("${keystore.file:src/main/resources/private/keystore}") String keystoreFile,
          @Value("${keystore.pass:changeit}") final String keystorePass) throws Exception {

// If you were going to reuse this class in another
// application, this is one of the key sections that you
// would want to change
  	
      final String absoluteKeystoreFile = new File(keystoreFile).getAbsolutePath();

      return new EmbeddedServletContainerCustomizer () {

	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                    new TomcatConnectorCustomizer() {
						@Override
						public void customize(Connector connector) {
							connector.setPort(8443);
	                        connector.setSecure(true);
	                        connector.setScheme("https");

	                        Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();
	                        proto.setSSLEnabled(true);
	                        proto.setKeystoreFile(absoluteKeystoreFile);
	                        proto.setKeystorePass(keystorePass);
	                        proto.setKeystoreType("JKS");
	                        proto.setKeyAlias("tomcat");
						}
                    });
    
	}
      };
  }
 
Example #20
Source File: ContainerConfiguration.java    From spring-boot-security-example with MIT License 5 votes vote down vote up
@Bean
EmbeddedServletContainerCustomizer containerCustomizer(
        @Value("${keystore.file}") String keystoreFile,
        @Value("${server.port}") final String serverPort,
        @Value("${keystore.pass}") final String keystorePass)
        throws Exception {

    // This is boiler plate code to setup https on embedded Tomcat
    // with Spring Boot:

    final String absoluteKeystoreFile = new File(keystoreFile)
            .getAbsolutePath();

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(connector -> {
                connector.setPort(Integer.parseInt(serverPort));
                connector.setSecure(true);
                connector.setScheme("https");

                Http11NioProtocol proto = (Http11NioProtocol) connector
                        .getProtocolHandler();
                proto.setSSLEnabled(true);

                proto.setKeystoreFile(absoluteKeystoreFile);
                proto.setKeystorePass(keystorePass);
                proto.setKeystoreType("JKS");
                proto.setKeyAlias("tomcat");
            });
        }
    };
}
 
Example #21
Source File: TomcatWebSocketTestServer.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void setup() {
	Connector connector = new Connector(Http11NioProtocol.class.getName());
	connector.setPort(0);

	File baseDir = createTempDir("tomcat");
	String baseDirPath = baseDir.getAbsolutePath();

	this.tomcatServer = new Tomcat();
	this.tomcatServer.setBaseDir(baseDirPath);
	this.tomcatServer.setPort(0);
	this.tomcatServer.getService().addConnector(connector);
	this.tomcatServer.setConnector(connector);
}
 
Example #22
Source File: TomcatWebSocketTestServer.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void setup() {
	Connector connector = new Connector(Http11NioProtocol.class.getName());
	connector.setPort(0);

	File baseDir = createTempDir("tomcat");
	String baseDirPath = baseDir.getAbsolutePath();

	this.tomcatServer = new Tomcat();
	this.tomcatServer.setBaseDir(baseDirPath);
	this.tomcatServer.setPort(0);
	this.tomcatServer.getService().addConnector(connector);
	this.tomcatServer.setConnector(connector);
}
 
Example #23
Source File: TomcatConfig.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
    TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
        tomcatFactory.addConnectorCustomizers(connector -> {
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        protocol.setKeepAliveTimeout(constantProperties.getKeepAliveTimeout()* 1000);
        protocol.setMaxKeepAliveRequests(constantProperties.getKeepAliveRequests());
    });
    return tomcatFactory;
}
 
Example #24
Source File: WebServerConfiguration.java    From youkefu with Apache License 2.0 5 votes vote down vote up
public void customize(Connector connector)  
{  
    Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();  
    //设置最大连接数
    protocol.setMaxConnections(maxthread!=null ? maxthread : 2000);  
    //设置最大线程数  
    protocol.setMaxThreads(maxconnection!=null ? maxconnection: 2000);  
    protocol.setConnectionTimeout(30000);  
}
 
Example #25
Source File: TomcatConfig.java    From WeBASE-Sign with Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerFactory createEmbeddedServletContainerFactory() {
    TomcatEmbeddedServletContainerFactory tomcatFactory = new TomcatEmbeddedServletContainerFactory();
    tomcatFactory.addConnectorCustomizers(connector -> {
        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
        protocol.setKeepAliveTimeout(10 * 1000);
        protocol.setMaxKeepAliveRequests(constantProperties.getKeepAliveRequests());
    });
    return tomcatFactory;
}
 
Example #26
Source File: TomcatConfig.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public ConfigurableServletWebServerFactory webServerFactory() {
	TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
	factory.addConnectorCustomizers(
			connector -> {
				Http11NioProtocol protocol =
						(Http11NioProtocol) connector.getProtocolHandler();
				protocol.setDisableUploadTimeout(false);
			}
	);
	return factory;
}
 
Example #27
Source File: AlipayGatewayServerBootstrap.java    From redis-distributed-lock with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector
            .getProtocolHandler();
    // 设置最大连接数
    protocol.setMaxConnections(2000);
    // 设置最大线程数
    protocol.setMaxThreads(2000);
    protocol.setConnectionTimeout(30000);
}
 
Example #28
Source File: TomcatContainerCustomizer.java    From radar with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
	MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
	mappings.add("woff", "application/x-font-woff");
	mappings.add("eot", "application/vnd.ms-fontobject");
	mappings.add("ttf", "application/x-font-ttf");
	container.setMimeMappings(mappings);

	if (!(container instanceof TomcatEmbeddedServletContainerFactory)) {
		return;
	}
	if (!environment.containsProperty(TOMCAT_ACCEPTOR_COUNT)) {
		return;
	}
	TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
	tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {

		@Override
		public void customize(Connector connector) {
			ProtocolHandler handler = connector.getProtocolHandler();
			if (handler instanceof Http11NioProtocol) {
				Http11NioProtocol http = (Http11NioProtocol) handler;
				acceptCount = soaConfig.getTomcatAcceptCount();
				soaConfig.registerChanged(() -> {
					if (acceptCount != soaConfig.getTomcatAcceptCount()) {
						acceptCount = soaConfig.getTomcatAcceptCount();
						http.setBacklog(acceptCount);
					}
				});
				http.setBacklog(acceptCount);
				logger.info("Setting tomcat accept count to {}", acceptCount);
			}
		}
	});
}
 
Example #29
Source File: Bootstrap.java    From lite-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector
            .getProtocolHandler();
    // 设置最大连接数
    protocol.setMaxConnections(2000);
    // 设置最大线程数
    protocol.setMaxThreads(2000);
    protocol.setConnectionTimeout(30000);
}
 
Example #30
Source File: Bootstrap.java    From lite-tracer with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(Connector connector) {
    Http11NioProtocol protocol = (Http11NioProtocol) connector
            .getProtocolHandler();
    // 设置最大连接数
    protocol.setMaxConnections(2000);
    // 设置最大线程数
    protocol.setMaxThreads(2000);
    protocol.setConnectionTimeout(30000);
}