Java Code Examples for org.springframework.boot.web.servlet.server.ServletWebServerFactory

The following examples show how to use org.springframework.boot.web.servlet.server.ServletWebServerFactory. These examples are extracted from open source projects. 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 Project: Java-API-Test-Examples   Source File: TomcatHttpConfig.java    License: Apache License 2.0 6 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 2
Source Project: nbp   Source File: HttpsConfiguration.java    License: Apache License 2.0 6 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 3
Source Project: layui-admin   Source File: LayuiAdminStartUp.java    License: 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 4
Source Project: odo   Source File: HomeController.java    License: 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 5
Source Project: WeBASE-Collect-Bee   Source File: WebasebeeApplication.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 配置tomcat
 *
 * @return
 */
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addConnectorCustomizers(gracefulShutdown());
    return tomcat;
}
 
Example 6
Source Project: singleton   Source File: TomcatConfig.java    License: 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 7
Source Project: singleton   Source File: TomcatConfig.java    License: 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 8
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 9
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 10
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 11
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 12
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 13
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 14
@Bean
public ServletWebServerFactory servletContainer(TomcatSslConnectorProperties properties) {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createSslConnector(properties));
    tomcat.setSessionTimeout(Duration.ofMinutes(1));
    return tomcat;
}
 
Example 15
/**
 *  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 16
/**
 * 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 17
Source Project: api-layer   Source File: TomcatConfiguration.java    License: 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 18
Source Project: api-layer   Source File: TomcatConfiguration.java    License: 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 19
Source Project: danyuan-application   Source File: App.java    License: 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 20
@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 21
Source Project: kurento-java   Source File: WebServerService.java    License: 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 22
Source Project: sk-admin   Source File: SkApplication.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ServletWebServerFactory webServerFactory() {
    TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
    fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
    return fa;
}
 
Example 23
Source Project: staffjoy   Source File: TestConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addConnectorCustomizers(connector -> connector.setAllowTrace(true));
    return tomcat;
}
 
Example 24
Source Project: yshopmall   Source File: AppRun.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ServletWebServerFactory webServerFactory() {
    TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
    fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
    return fa;
}
 
Example 25
@Bean
public ServletWebServerFactory webServerFactory() {
    return new TomcatServletWebServerFactory("/ws", 0);
}
 
Example 26
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.addAdditionalTomcatConnectors(createStandardConnector());
    return tomcat;
}
 
Example 27
Source Project: ambari-logsearch   Source File: LogSearchServletConfig.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ServletWebServerFactory webServerFactory() {
  return new JettyServletWebServerFactory();
}
 
Example 28
Source Project: eladmin   Source File: AppRun.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ServletWebServerFactory webServerFactory() {
    TomcatServletWebServerFactory fa = new TomcatServletWebServerFactory();
    fa.addConnectorCustomizers(connector -> connector.setProperty("relaxedQueryChars", "[]{}"));
    return fa;
}
 
Example 29
Source Project: api-layer   Source File: TomcatConfiguration.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
    tomcat.setProtocol(TomcatServletWebServerFactory.DEFAULT_PROTOCOL);
    return tomcat;
}
 
Example 30
Source Project: pulsar-manager   Source File: EmbeddedTomcatCustomizer.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ServletWebServerFactory servletContainer() {
    log.info("Starting servletContainer");
    return new TomcatServletWebServerFactory() {
        @Override
        protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
            try {
                log.info("Catalina base is " + tomcat.getServer().getCatalinaBase().getAbsolutePath());
                File lib = new File("lib").getAbsoluteFile();
                if (lib.isDirectory()) {
                    File bkvmWar = searchWar(lib, "bkvm", ".war");
                    if (bkvmWar != null) {
                        File configFile = new File("bkvm.conf");
                        log.info("looking for BKVM configuration file at " + configFile.getAbsolutePath());
                        if (configFile.isFile()) {
                            Properties props = new Properties();
                            try (FileReader reader = new FileReader(configFile)) {
                                props.load(reader);
                            }
                            boolean bkvmEnabled = Boolean.parseBoolean(props.getProperty("bkvm.enabled", "false"));
                            log.info("Read bkvm.enabled = {}", bkvmEnabled);
                            if (bkvmEnabled) {
                                System.setProperty("bookkeeper.visual.manager.config.path", configFile.getAbsolutePath());
                                File file = new File(tomcat.getServer().getCatalinaBase(), "/webapps");
                                log.info("Tomcat Webapps directory is " + file.getAbsolutePath());
                                file.mkdirs();
                                File bkvmDirectory = new File(file, "bkvm");
                                log.info("Deploying BKVM to " + bkvmDirectory.getAbsolutePath());
                                unZip(bkvmWar, bkvmDirectory);
                                Context context = tomcat.addWebapp("/bkvm", bkvmDirectory.getAbsolutePath());
                                WebappLoader loader = new WebappLoader(Thread.currentThread().getContextClassLoader());
                                context.setLoader(loader);
                            }
                        }
                    }
                }
                return super.getTomcatWebServer(tomcat);
            } catch (IOException | ServletException ex) {
                throw new RuntimeException(ex);
            }
        }

    };
}