Java Code Examples for org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer

The following examples show how to use org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer. 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: flair-engine   Source File: WebConfigurer.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Customize the Servlet engine: Mime types, the document root, the cache.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);
    // When running in an IDE or with ./mvnw spring-boot:run, set location of the static web assets.
    setLocationForStaticAssets(container);

    /*
     * Enable HTTP/2 for Undertow - https://twitter.com/ankinson/status/829256167700492288
     * HTTP/2 requires HTTPS, so HTTP requests will fallback to HTTP/1.1.
     * See the JHipsterProperties class and your application-*.yml configuration files
     * for more information.
     */
    if (jHipsterProperties.getHttp().getVersion().equals(JHipsterProperties.Http.Version.V_2_0) &&
        container instanceof UndertowEmbeddedServletContainerFactory) {

        ((UndertowEmbeddedServletContainerFactory) container)
            .addBuilderCustomizers(builder ->
                builder.setServerOption(UndertowOptions.ENABLE_HTTP2, true));
    }
}
 
Example 2
Source Project: spring-boot-inside   Source File: TomcatConfiguration.java    License: MIT License 6 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer staticResourceCustomizer() {
	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			if (container instanceof TomcatEmbeddedServletContainerFactory) {
				((TomcatEmbeddedServletContainerFactory) container)
						.addContextCustomizers(new TomcatContextCustomizer() {
							@Override
							public void customize(Context context) {
								context.addLifecycleListener(new StaticResourceConfigurer(context));
							}
						});
			}
		}

	};
}
 
Example 3
Source Project: karate   Source File: TomcatConfig.java    License: MIT License 6 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer cookieProcessorCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                TomcatEmbeddedServletContainerFactory factory = (TomcatEmbeddedServletContainerFactory) container;
                factory.addContextCustomizers(new TomcatContextCustomizer() {
                    @Override
                    public void customize(Context context) {
                        context.setCookieProcessor(new LegacyCookieProcessor());
                    }                        
                });
            }
        }

    };
}
 
Example 4
@Bean
public EmbeddedServletContainerCustomizer staticResourceCustomizer() {
	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			if (container instanceof TomcatEmbeddedServletContainerFactory) {
				((TomcatEmbeddedServletContainerFactory) container)
						.addContextCustomizers(new TomcatContextCustomizer() {
							@Override
							public void customize(Context context) {
								context.addLifecycleListener(new StaticResourceConfigurer(context));
							}
						});
			}
		}

	};
}
 
Example 5
Source Project: tinker-manager   Source File: WebAppConfig.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
        return new EmbeddedServletContainerCustomizer() {
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container) {
                ErrorPage page404 = new ErrorPage(HttpStatus.NOT_FOUND,"/404");
                container.addErrorPages(page404);
            }
        };
//        return (container -> {
//            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
//            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
//            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");
//
//            container.addErrorPages(error401Page, error404Page, error500Page);
//        });
    }
 
Example 6
/**
 * Set up Mime types and, if needed, set the document root.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);<% if (!skipClient) { %>

    // When running in an IDE or with <% if (buildTool == 'gradle') { %>./gradlew bootRun<% } else { %>./mvnw spring-boot:run<% } %>, set location of the static web assets.
    File root;
    if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) {
        root = new File("<%= CLIENT_DIST_DIR %>");
    } else {
        root = new File("<%= CLIENT_MAIN_SRC_DIR %>");
    }
    if (root.exists() && root.isDirectory()) {
        container.setDocumentRoot(root);
    }<% } %>
}
 
Example 7
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    KeystoreConfig cert = configureKeystore();
    if(cert == null) {
        log.debug("Ssl is not enabled due to no any configured keystore.");
        return;
    }
    String keystorePath = cert.getKeystore().getAbsolutePath();
    log.debug("Configure ssl with {} keystore.", keystorePath);
    Ssl ssl = new Ssl();
    ssl.setEnabled(true);
    ssl.setKeyStore(keystorePath);
    ssl.setKeyStorePassword(cert.getKeystorePassword());
    ssl.setKeyPassword(cert.getKeyPassword());
    container.setSsl(ssl);
}
 
Example 8
Source Project: booties   Source File: ProxiesAutoConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(final ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
                for (TomcatConnectorCustomizer customizer : tomcatConnectorCustomizers) {
                    tomcat.addConnectorCustomizers(customizer);
                }
            }
        }
    };
}
 
Example 9
Source Project: youkefu   Source File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
        	ErrorPage error = new ErrorPage("/error.html");
        	container.addErrorPages(error);
        }
    };
}
 
Example 10
Source Project: radar   Source File: TomcatContainerCustomizer.java    License: 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 11
Source Project: super-cloudops   Source File: WebCustomizerConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			container.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400.html"));
			container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html"));
			container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"));
		}
	};
}
 
Example 12
Source Project: yfs   Source File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
    clusterProperties.getStore().getNode().stream().forEach(clusterNode -> {
        if (clusterNode.getId().equals(clusterProperties.getLocal())) {
            configurableEmbeddedServletContainer.setPort(clusterNode.getHttp_port());
        }
    });
}
 
Example 13
Source Project: fiery   Source File: RagnarApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
    return (ConfigurableEmbeddedServletContainer container) -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                    (connector) -> {
                        connector.setMaxPostSize(1000000000); // 1000 MB
                    }
            );
        }
    };
}
 
Example 14
Source Project: MonitorClient   Source File: MonitorClientApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
       MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
       mappings.add("html", "text/html;charset=utf-8");
       configurableEmbeddedServletContainer.setMimeMappings(mappings );
	String Lport = IniUtil.getLport(System.getProperty("user.dir") + File.separator + "config/config.ini");
	configurableEmbeddedServletContainer.setPort(Integer.parseInt(Lport));
}
 
Example 15
Source Project: ProxyPool   Source File: ErrorPageConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    ErrorPage error400Page = new ErrorPage(HttpStatus.BAD_REQUEST, "/400.html");
    ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
    ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
    ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

    container.addErrorPages(error400Page, error401Page, error404Page, error500Page);
}
 
Example 16
Source Project: easyweb   Source File: WebConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500");
            container.addErrorPages(error404Page);
            container.addErrorPages(error500Page);
        }
    };
}
 
Example 17
Source Project: klask-io   Source File: WebConfigurer.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set up Mime types and, if needed, set the document root.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);

    // When running in an IDE or with ./mvnw spring-boot:run, set location of the static web assets.
    setLocationForStaticAssets(container);
}
 
Example 18
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            container.setPort(cmdLineResult.getPort());
        }
    };
}
 
Example 19
/**
 * Set up Mime types and, if needed, set the document root.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);
}
 
Example 20
/**
 * Set up Mime types and, if needed, set the document root.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);
}
 
Example 21
Source Project: gpmr   Source File: WebConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set up Mime types and, if needed, set the document root.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);

    // When running in an IDE or with ./gradlew bootRun, set location of the static web assets.
    setLocationForStaticAssets(container);
}
 
Example 22
Source Project: OpenIoE   Source File: WebConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set up Mime types and, if needed, set the document root.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);

    // When running in an IDE or with ./gradlew bootRun, set location of the static web assets.
    setLocationForStaticAssets(container);
}
 
Example 23
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
	MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
	mappings.add("woff", "application/font-woff");
	mappings.add("woff2", "application/font-woff2");
	mappings.add("ttf", "application/x-font-truetype");
	mappings.add("eot", "application/vnd.ms-fontobject");
	mappings.add("svg", "image/svg+xml");
	mappings.add("otf", "application/x-font-opentype");
	container.setMimeMappings(mappings);
}
 
Example 24
Source Project: x-pipe   Source File: CustomizedConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
	return new EmbeddedServletContainerCustomizer() {
		@Override
		public void customize(ConfigurableEmbeddedServletContainer container) {
			ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/401.html");
			
			container.addErrorPages(error401Page);
		}
	}; 
}
 
Example 25
Source Project: spring-boot-quickstart   Source File: Application.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, "/WEB-INF/views/error/401.jsp");
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/WEB-INF/views/error/404.jsp");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/WEB-INF/views/error/500.jsp");

            container.addErrorPages(error401Page, error404Page, error500Page);
        }
    };
}
 
Example 26
Source Project: jee-universal-bms   Source File: WebConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {

            ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN, "/403.html");
            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");
            ErrorPage error405Page = new ErrorPage(HttpStatus.METHOD_NOT_ALLOWED, "/405.html");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/500.html");

            container.addErrorPages(error403Page, error404Page, error405Page, error500Page);
        }
    };
}
 
Example 27
Source Project: portal-de-servicos   Source File: ServletContainerConfig.java    License: MIT License 5 votes vote down vote up
private void addMimeMappingsForFonts(ConfigurableEmbeddedServletContainer servletContainer) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    mappings.add("eot", "application/vnd.ms-fontobject");
    mappings.add("ttf", "application/font-sfnt");
    mappings.add("otf", "application/font-sfnt");
    mappings.add("woff", "application/font-woff");
    mappings.add("woff2", "application/font-woff");
    servletContainer.setMimeMappings(mappings);
}
 
Example 28
Source Project: xxl-conf   Source File: ErrorPageConfig.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        public void customize(ConfigurableEmbeddedServletContainer container) {

            ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/static/html/500.html");
            ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/static/html/500.html");

            container.addErrorPages(error404Page, error500Page);
        }
    };
}
 
Example 29
Source Project: angularjs-springboot-bookstore   Source File: WebConfigurer.java    License: MIT License 5 votes vote down vote up
/**
 * Set up Mime types.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);
}
 
Example 30
Source Project: ServiceCutter   Source File: WebConfigurer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set up Mime types.
 */
@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT);
    // IE issue, see https://github.com/jhipster/generator-jhipster/pull/711
    mappings.add("html", "text/html;charset=utf-8");
    // CloudFoundry issue, see https://github.com/cloudfoundry/gorouter/issues/64
    mappings.add("json", "text/html;charset=utf-8");
    container.setMimeMappings(mappings);
}