Java Code Examples for org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#addAdditionalTomcatConnectors()

The following examples show how to use org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#addAdditionalTomcatConnectors() . 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: HttpsConfiguration.java    From nbp with Apache License 2.0 7 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(redirectConnector());
    return tomcat;
}
 
Example 2
Source File: TomcatHttpConfig.java    From Java-API-Test-Examples with Apache License 2.0 7 votes vote down vote up
/**
 * 配置内置的Servlet容器工厂为Tomcat
 * @return
 */
@Bean
public ServletWebServerFactory servletContainer() {
	TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
		@Override
		protected void postProcessContext(Context context) {
			SecurityConstraint securityConstraint = new SecurityConstraint();
			securityConstraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			securityConstraint.addCollection(collection);
			context.addConstraint(securityConstraint);
		}
	};
	//添加配置信息,主要是Http的配置信息
	tomcat.addAdditionalTomcatConnectors(redirectConnector());
	return tomcat;
}
 
Example 3
Source File: HttpsConfig.java    From spring-boot-demo with MIT License 6 votes vote down vote up
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(connector);
    return tomcat;
}
 
Example 4
Source File: HttpsServerConfig.java    From micro-service with MIT License 6 votes vote down vote up
@Bean
    public ConfigurableServletWebServerFactory configurableServletWebServerFactory() {

        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.setSsl(getSsl());
        factory.setPort(8443);
        factory.addAdditionalTomcatConnectors(getHttpConnector());

        factory.addContextCustomizers(context -> {
            addSecurityConstraint(context);
        });

//        factory.addConnectorCustomizers(connector -> {
//            connector.setAllowTrace(true);
//        });

        return factory;
    }
 
Example 5
Source File: CustomConfig.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
@Bean
TomcatServletWebServerFactory tomcatServletWebServerFactory() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint constraint = new SecurityConstraint();
            constraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            constraint.addCollection(collection);
            context.addConstraint(constraint);
        }
    };
    factory.addAdditionalTomcatConnectors(createTomcatConnector());
    return factory;
}
 
Example 6
Source File: MaxKeySslConfig.java    From MaxKey with Apache License 2.0 6 votes vote down vote up
@Bean
public TomcatServletWebServerFactory tomcatServletWebServerFactory(Connector connector) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(connector);
    return tomcat;
}
 
Example 7
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 8
Source File: TomcatConfiguration.java    From odata with Apache License 2.0 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    if (Boolean.parseBoolean(httpsModeFlag)) {
        tomcat.addAdditionalTomcatConnectors(createSslConnector());
    }
    return tomcat;
}
 
Example 9
Source File: WebServerService.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public ServletWebServerFactory servletContainer() {
	TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
  Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
  connector.setScheme("http");
  connector.setPort(getAppHttpPort());

  tomcat.addAdditionalTomcatConnectors(connector);
  return tomcat;
}
 
Example 10
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 11
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 12
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 13
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 14
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 15
Source File: WebConfiguration.java    From Spring-Boot-2.0-Cookbook-Second-Edition with MIT License 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 16
Source File: WebAnno.java    From webanno with Apache License 2.0 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory servletContainer()
{
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    if (ajpPort > 0) {
        Connector ajpConnector = new Connector(PROTOCOL);
        ajpConnector.setPort(ajpPort);
        ajpConnector.setAttribute("secretRequired", ajpSecretRequired);
        ajpConnector.setAttribute("secret", ajpSecret);
        ajpConnector.setAttribute("address", ajpAddress);
        factory.addAdditionalTomcatConnectors(ajpConnector);
    }
    return factory;
}
 
Example 17
Source File: TomcatConfig.java    From singleton with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(ServerProperties serverProperties) {
	TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
	tomcat.addConnectorCustomizers(new VIPTomcatConnectionCustomizer(serverProperties));
	if (serverProperties.getServerScheme().equalsIgnoreCase(ConstantsTomcat.HTTP_HTTPS) ||
			serverProperties.getServerScheme().equalsIgnoreCase(ConstantsTomcat.HTTPS_HTTP)) {
		tomcat.addAdditionalTomcatConnectors(initiateHttpsConnector(serverProperties));
	}
	return tomcat;
}
 
Example 18
Source File: TomcatConfig.java    From singleton with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(ServerProperties serverProperties) {
	TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
	tomcat.addConnectorCustomizers(new VIPTomcatConnectionCustomizer(serverProperties));
	if (serverProperties.getServerScheme().equalsIgnoreCase(ConstantsTomcat.HTTP_HTTPS) ||
			serverProperties.getServerScheme().equalsIgnoreCase(ConstantsTomcat.HTTPS_HTTP)) {
		tomcat.addAdditionalTomcatConnectors(initiateHttpsConnector(serverProperties));
	}
	return tomcat;
}
 
Example 19
Source File: Http2Https.java    From springBoot with MIT License 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory servletContainerFactory() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            //设置安全性约束
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            //设置约束条件
            SecurityCollection collection = new SecurityCollection();
            //拦截所有请求
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    //设置将分配给通过此连接器接收到的请求的方案
    connector.setScheme("http");

    //true: http使用http, https使用https;
    //false: http重定向到https;
    connector.setSecure(false);

    //设置监听请求的端口号,这个端口不能其他已经在使用的端口重复,否则会报错
    connector.setPort(httpPort);

    //重定向端口号(非SSL到SSL)
    connector.setRedirectPort(sslPort);

    tomcat.addAdditionalTomcatConnectors(connector);
    return tomcat;
}
 
Example 20
Source File: TomcatConfig.java    From macrozheng with Apache License 2.0 4 votes vote down vote up
@Bean
public TomcatServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createStandardConnector()); // 添加http
    return tomcat;
}