org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory Java Examples

The following examples show how to use org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory. 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: WebServerSecurityConfig.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> servletContainerCustomizer() {
    return factory -> factory.addConnectorCustomizers(connector -> {
        AbstractHttp11Protocol abstractProtocol = (AbstractHttp11Protocol<?>) connector.getProtocolHandler();
        abstractProtocol.setUseServerCipherSuitesOrder(true);
    });
}
 
Example #4
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 #5
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 #6
Source File: LayuiAdminStartUp.java    From layui-admin with MIT License 6 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addInitializers(new ServletContextInitializer(){
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            XmlWebApplicationContext context = new XmlWebApplicationContext();
            context.setConfigLocations(new String[]{"classpath:applicationContext-springmvc.xml"});
            DispatcherServlet dispatcherServlet = new DispatcherServlet(context);
            ServletRegistration.Dynamic dispatcher = servletContext
                    .addServlet("dispatcher", dispatcherServlet);

            dispatcher.setLoadOnStartup(1);
            dispatcher.addMapping("/");
        }
    });
    tomcat.setContextPath("/manager");
    tomcat.addTldSkipPatterns("xercesImpl.jar","xml-apis.jar","serializer.jar");
    tomcat.setPort(port);

    return tomcat;
}
 
Example #7
Source File: WebFragmentRegistrationBean.java    From joinfaces with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(ConfigurableServletWebServerFactory factory) {

	if (factory instanceof TomcatServletWebServerFactory) {
		((TomcatServletWebServerFactory) factory).addContextCustomizers(new TomcatListenerAdder(this.listeners));
	}
	else if (factory instanceof JettyServletWebServerFactory) {
		((JettyServletWebServerFactory) factory).addConfigurations(new JettyListenerAdder(this.listeners));
	}
	else if (factory instanceof UndertowServletWebServerFactory) {
		((UndertowServletWebServerFactory) factory).addDeploymentInfoCustomizers(new UndertowListenerAdder(this.listeners));
	}
	else {
		log.warn("Unkown WebServerFactory implementation: {}", factory.getClass());
		factory.addInitializers(servletContext -> this.listeners.forEach(servletContext::addListener));
	}

	factory.addInitializers(servletContext -> this.contextParams.forEach(servletContext::setInitParameter));

	this.errorPages.forEach(factory::addErrorPages);
}
 
Example #8
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 #9
Source File: HomeController.java    From odo with Apache License 2.0 6 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() throws Exception {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

    int apiPort = Utils.getSystemPort(Constants.SYS_API_PORT);
    factory.setPort(apiPort);
    factory.getSession().setTimeout(Duration.ofMinutes(10));
    factory.setContextPath("/testproxy");
    baseDirectory = new File("./tmp");
    factory.setBaseDirectory(baseDirectory);
    List<TomcatConnectorCustomizer> cs = new ArrayList();
    cs.add(tomcatConnectorCustomizers());
    factory.setTomcatConnectorCustomizers(cs);

    if (Utils.getEnvironmentOptionValue(Constants.SYS_LOGGING_DISABLED) != null) {
        HistoryService.getInstance().disableHistory();
    }
    return factory;
}
 
Example #10
Source File: CorsConfig.java    From DrivingAgency 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 #11
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 #12
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 #13
Source File: WebXmlSpringBoot.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
    return new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
        }
    };
}
 
Example #14
Source File: TomcatAutoConfigurationTest.java    From joinfaces with Apache License 2.0 5 votes vote down vote up
@Test
public void customize() {
	TomcatServletWebServerFactory tomcatFactory = new TomcatServletWebServerFactory();

	this.tomcatAutoConfiguration.jsfTomcatFactoryCustomizer().customize(tomcatFactory);

	assertThat(tomcatFactory.getTomcatContextCustomizers())
		.isNotEmpty();
}
 
Example #15
Source File: SleuthBenchmarkingSpringApp.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer(
		@Value("${server.port:0}") int serverPort) {
	log.info("Starting container at port [" + serverPort + "]");
	return new TomcatServletWebServerFactory(
			serverPort == 0 ? SocketUtils.findAvailableTcpPort() : serverPort);
}
 
Example #16
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 #17
Source File: JsonRpcConfiguration.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory tomcatContainerFactory() {
 TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
  factory.setTomcatContextCustomizers(
      Arrays.asList(new TomcatContextCustomizer[] { tomcatContextCustomizer() }));
  return factory;
}
 
Example #18
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 #19
Source File: WebServerConfig.java    From NettyReverseProxy with Apache License 2.0 5 votes vote down vote up
/**
 * tomcat配置
 */
@Bean
public TomcatServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    factory.getSession().setTimeout(Duration.ofMinutes(10));
    factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
            httpProtocol.setCompression("on");
            httpProtocol.setCompressibleMimeType("text/html,text/xml,text/plain,application/json,application/xml");
        }
    });
    return factory;
}
 
Example #20
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 #21
Source File: FileUploadApplication.java    From parker with MIT License 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory tomcatEmbedded() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addConnectorCustomizers((TomcatConnectorCustomizer) connector -> {
        if ((connector.getProtocolHandler() instanceof AbstractHttp11Protocol<?>)) {
            //-1 means unlimited
            ((AbstractHttp11Protocol<?>) connector.getProtocolHandler()).setMaxSwallowSize(-1);
        }
    });
    return tomcat;
}
 
Example #22
Source File: BootStrap.java    From MyBlog with Apache License 2.0 5 votes vote down vote up
/*********************************************************************************************************/
    // 设置内嵌tomcat,我还是习惯在yml配置,下面那种方式设置的不全,是内嵌服务器的通用配置
    // implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>
//    @Bean
    public ConfigurableServletWebServerFactory webServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.setPort(9000);
        return factory;
    }
 
Example #23
Source File: WebXmlSpringBoot.java    From sitemonitoring-production with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
    return new TomcatServletWebServerFactory() {
        @Override
        protected void postProcessContext(Context context) {
            ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
        }
    };
}
 
Example #24
Source File: App.java    From danyuan-application with Apache License 2.0 5 votes vote down vote up
public ServletWebServerFactory servletContainer() {
	TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
		@Override
		protected void postProcessContext(org.apache.catalina.Context context) {
			SecurityConstraint constraint = new SecurityConstraint();
			constraint.setUserConstraint("CONFIDENTIAL");
			SecurityCollection collection = new SecurityCollection();
			collection.addPattern("/*");
			constraint.addCollection(collection);
			context.addConstraint(constraint);
		}
	};
	tomcat.addAdditionalTomcatConnectors(createHTTPConnector());
	return tomcat;
}
 
Example #25
Source File: ServletConfig.java    From EasyReport with Apache License 2.0 5 votes vote down vote up
@Bean
public ConfigurableServletWebServerFactory containerCustomizer() {
    TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();

    factory.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/customError/401"));
    factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/customError/403"));
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/customError/404"));
    factory.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/customError"));
    return factory;
}
 
Example #26
Source File: TomcatConfiguration.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
    System.setProperty("org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH", "true");
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.setProtocol(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
    return tomcat;
}
 
Example #27
Source File: TomcatConfiguration.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.setProtocol(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
    return tomcat;
}
 
Example #28
Source File: ProductSvcShedLoadConfig.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/**
 * It is used to register the tomcat valve with the tomcat container.
 * 
 * @return embeddedTomcat
 */
@Bean
@ConditionalOnClass({ Servlet.class, Tomcat.class })
public ServletWebServerFactory servletContainerWithSemaphoreRateLimiterValve() {
	TomcatServletWebServerFactory embeddedTomcat = new TomcatServletWebServerFactory();
	embeddedTomcat.addEngineValves(new ProductShedLoadSemaphoreValve(shedLoad));
	return embeddedTomcat;
}
 
Example #29
Source File: CustomerSvcShedLoadConfig.java    From cloud-espm-cloud-native with Apache License 2.0 5 votes vote down vote up
/**
 *  It is used to register the tomcat valve with the tomcat container.
 *  
 * @return embeddedTomcat
 */
@Bean
public ServletWebServerFactory servletContainerWithSemaphoreRateLimiterValve() {
	TomcatServletWebServerFactory embeddedTomcat = new TomcatServletWebServerFactory();
	embeddedTomcat.addEngineValves(new CustomerShedLoadSemaphoreValve(shedLoad));
	return embeddedTomcat;
}
 
Example #30
Source File: JeecgApplication.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
* tomcat-embed-jasper引用后提示jar找不到的问题
*/
@Bean
public TomcatServletWebServerFactory tomcatFactory() {
 return new TomcatServletWebServerFactory() {
  @Override
  protected void postProcessContext(Context context) {
   ((StandardJarScanner) context.getJarScanner()).setScanManifest(false);
  }
 };
}