org.springframework.boot.context.embedded.ServletContextInitializer Java Examples

The following examples show how to use org.springframework.boot.context.embedded.ServletContextInitializer. 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: NettyEmbeddedServletContainerFactory.java    From spring-boot-starter-netty with Apache License 2.0 6 votes vote down vote up
@Override
public EmbeddedServletContainer getEmbeddedServletContainer(ServletContextInitializer... initializers) {
    ClassLoader parentClassLoader = resourceLoader != null ? resourceLoader.getClassLoader() : ClassUtils.getDefaultClassLoader();
    Package nettyPackage = Bootstrap.class.getPackage();
    String title = nettyPackage.getImplementationTitle();
    String version = nettyPackage.getImplementationVersion();
    logger.info("Running with " + title + " " + version);
    NettyEmbeddedContext context = new NettyEmbeddedContext(getContextPath(), new URLClassLoader(new URL[]{}, parentClassLoader), SERVER_INFO);
    if (isRegisterDefaultServlet()) {
        logger.warn("This container does not support a default servlet");
    }
    if (isRegisterJspServlet()) {
        logger.warn("This container does not support a JSP servlet");
    }
    for (ServletContextInitializer initializer : initializers) {
        try {
            initializer.onStartup(context);
        } catch (ServletException e) {
            throw new RuntimeException(e);
        }
    }
    int port = getPort() > 0 ? getPort() : new Random().nextInt(65535 - 1024) + 1024;
    InetSocketAddress address = new InetSocketAddress(port);
    logger.info("Server initialized with port: " + port);
    return new NettyEmbeddedServletContainer(address, context);
}
 
Example #2
Source File: LightAdminBootApplication.java    From lightadmin-springboot with Apache License 2.0 6 votes vote down vote up
/**
 * public void onStartup(ServletContext servletContext) throws ServletException {
 * LightAdmin.configure(servletContext)
 * .basePackage("org.lightadmin.boot.administration")
 * .baseUrl("/admin")
 * .security(false)
 * .backToSiteUrl("http://lightadmin.org");
 * super.onStartup(servletContext);
 * }
 */

/* Used for running in "embedded" mode */
@Bean
public ServletContextInitializer servletContextInitializer() {
    return new ServletContextInitializer() {
        @Override
        public void onStartup(ServletContext servletContext) throws ServletException {
            LightAdmin.configure(servletContext)
                    .basePackage("org.lightadmin.boot.administration")
                    .baseUrl("/admin")
                    .security(true)
                    .backToSiteUrl("http://lightadmin.org");

            new LightAdminWebApplicationInitializer().onStartup(servletContext);
        }
    };
}
 
Example #3
Source File: AppLauncher.java    From VulnerableJavaWebApplication with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Bean
public ServletContextInitializer servletContextInitializer() {
	return new ServletContextInitializer() {
		@Override
		public void onStartup(ServletContext servletContext) throws ServletException {
			servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE));
			SessionCookieConfig sessionCookieConfig = servletContext.getSessionCookieConfig();
			sessionCookieConfig.setHttpOnly(true);
		}
	};

}