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

The following examples show how to use org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer. 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: SystemBootAutoConfiguration.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * Customization servlet container configuring. </br>
 * 
 * @see {@link EmbeddedServletContainerAutoConfiguration}
 * 
 * @return
 */
@Bean
public EmbeddedServletContainerCustomizer customEmbeddedServletContainerCustomizer() {
	return container -> {
		// Tomcat container customization
		if (container instanceof TomcatEmbeddedServletContainerFactory) {
			TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
			tomcat.addConnectorCustomizers(connector -> {
				ProtocolHandler handler = connector.getProtocolHandler();
				if (handler instanceof AbstractProtocol) {
					AbstractProtocol<?> protocol = (AbstractProtocol<?>) handler;
					/**
					 * {@link org.apache.tomcat.util.net.NioEndpoint#startInternal()}
					 * {@link org.apache.tomcat.util.net.NioEndpoint#createExecutor()}
					 */
					protocol.setExecutor(customTomcatExecutor(protocol));
				}
			});
		} else {
			log.warn("Skip using custom servlet container, EmbeddedServletContainer: {}", container);
		}
	};

}
 
Example #2
Source File: Application.java    From spring-boot-spring-loaded-java8-example with Apache License 2.0 6 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return factory -> {
        TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) factory;
        containerFactory.setTomcatContextCustomizers(Arrays.asList(context -> {
            final PersistentManager persistentManager = new PersistentManager();
            final FileStore store = new FileStore();

            final String sessionDirectory = makeSessionDirectory();
            log.info("Writing sessions to " + sessionDirectory);
            store.setDirectory(sessionDirectory);

            persistentManager.setStore(store);
            context.setManager(persistentManager);
        }));
    };
}
 
Example #3
Source File: ProxiesAutoConfiguration.java    From booties with 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 #4
Source File: WebAppConfig.java    From tinker-manager with 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 #5
Source File: TomcatConfiguration.java    From spring-boot-inside with 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 #6
Source File: TomcatConfig.java    From karate with 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 #7
Source File: TomcatConfiguration.java    From spring-boot-fat-jar-jsp-sample with 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 #8
Source File: ServletContainerConfig.java    From portal-de-servicos with MIT License 6 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return servletContainer -> {
        addMimeMappingsForFonts(servletContainer);

        TomcatEmbeddedServletContainerFactory container = (TomcatEmbeddedServletContainerFactory) servletContainer;

        container.setRegisterJspServlet(false);

        container.addContextCustomizers(customizer -> customizer.addWelcomeFile("index.html"));
        container.addConnectorCustomizers(
                connector -> {
                    AbstractHttp11Protocol httpProtocol = (AbstractHttp11Protocol) connector.getProtocolHandler();
                    httpProtocol.setCompression("on");
                    httpProtocol.setCompressionMinSize(256);
                    httpProtocol.setCompressableMimeTypes(COMPRESSIBLE_MEDIA_TYPES);
                }
        );
    };
}
 
Example #9
Source File: AppConfiguration.java    From find with MIT License 6 votes vote down vote up
@SuppressWarnings("ReturnOfInnerClass")
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer(
    @Value("${server.tomcat.accesslog.pattern:combined}") final String pattern
) {

    return container -> {
        final ErrorPage error401Page = new ErrorPage(HttpStatus.UNAUTHORIZED, DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
        final ErrorPage error403Page = new ErrorPage(HttpStatus.FORBIDDEN, DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH);
        final ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, DispatcherServletConfiguration.NOT_FOUND_ERROR_PATH);
        final ErrorPage error500Page = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, DispatcherServletConfiguration.SERVER_ERROR_PATH);

        container.addErrorPages(error401Page, error403Page, error404Page, error500Page);

        if (StringUtils.isNotEmpty(pattern) && container instanceof TomcatEmbeddedServletContainerFactory) {
            final TomcatAccessLogValve accessLogValve = new TomcatAccessLogValve();
            accessLogValve.setPattern(pattern);
            ((TomcatEmbeddedServletContainerFactory) container).addEngineValves(accessLogValve);
        }
    };
}
 
Example #10
Source File: Application.java    From youkefu with 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 #11
Source File: AuthConfiguration.java    From haven-platform with Apache License 2.0 5 votes vote down vote up
@Bean
EmbeddedServletContainerCustomizer enableAuthUndertowContainerCustomizer() {
    return container -> {
        if(!(container instanceof UndertowEmbeddedServletContainerFactory)) {
            return;
        }
        UndertowEmbeddedServletContainerFactory factory = (UndertowEmbeddedServletContainerFactory) container;
        factory.addDeploymentInfoCustomizers(enableAuthUDICustomizer());
    };
}
 
Example #12
Source File: CustomizedConfig.java    From x-pipe with 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 #13
Source File: Application.java    From spring-boot-quickstart with 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 #14
Source File: WebConfig.java    From jee-universal-bms with 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 #15
Source File: ErrorPageConfig.java    From xxl-conf with 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 #16
Source File: OAuth2SecurityConfiguration.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
@Bean
  EmbeddedServletContainerCustomizer containerCustomizer(
          @Value("${keystore.file:src/main/resources/private/keystore}") String keystoreFile,
          @Value("${keystore.pass:changeit}") final String keystorePass) throws Exception {

// If you were going to reuse this class in another
// application, this is one of the key sections that you
// would want to change
  	
      final String absoluteKeystoreFile = new File(keystoreFile).getAbsolutePath();

      return new EmbeddedServletContainerCustomizer () {

	@Override
	public void customize(ConfigurableEmbeddedServletContainer container) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(
                    new TomcatConnectorCustomizer() {
						@Override
						public void customize(Connector connector) {
							connector.setPort(8443);
	                        connector.setSecure(true);
	                        connector.setScheme("https");

	                        Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler();
	                        proto.setSSLEnabled(true);
	                        proto.setKeystoreFile(absoluteKeystoreFile);
	                        proto.setKeystorePass(keystorePass);
	                        proto.setKeystoreType("JKS");
	                        proto.setKeyAlias("tomcat");
						}
                    });
    
	}
      };
  }
 
Example #17
Source File: LightAdminBootApplication.java    From lightadmin-springboot with Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {

        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            if (container instanceof TomcatEmbeddedServletContainerFactory) {
                customizeTomcat((TomcatEmbeddedServletContainerFactory)container); 
            }
        }

        private void customizeTomcat(TomcatEmbeddedServletContainerFactory tomcatFactory) {
            tomcatFactory.addContextCustomizers(new TomcatContextCustomizer() {

                @Override
                public void customize(Context context) {
                    Container jsp = context.findChild("jsp");
                    if (jsp instanceof Wrapper) {
                        ((Wrapper)jsp).addInitParameter("development", "false");
                    }

                }

            });
        }

    };
}
 
Example #18
Source File: ContainerConfiguration.java    From spring-boot-security-example with MIT License 5 votes vote down vote up
@Bean
EmbeddedServletContainerCustomizer containerCustomizer(
        @Value("${keystore.file}") String keystoreFile,
        @Value("${server.port}") final String serverPort,
        @Value("${keystore.pass}") final String keystorePass)
        throws Exception {

    // This is boiler plate code to setup https on embedded Tomcat
    // with Spring Boot:

    final String absoluteKeystoreFile = new File(keystoreFile)
            .getAbsolutePath();

    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
            tomcat.addConnectorCustomizers(connector -> {
                connector.setPort(Integer.parseInt(serverPort));
                connector.setSecure(true);
                connector.setScheme("https");

                Http11NioProtocol proto = (Http11NioProtocol) connector
                        .getProtocolHandler();
                proto.setSSLEnabled(true);

                proto.setKeystoreFile(absoluteKeystoreFile);
                proto.setKeystorePass(keystorePass);
                proto.setKeystoreType("JKS");
                proto.setKeyAlias("tomcat");
            });
        }
    };
}
 
Example #19
Source File: WebCustomizerConfig.java    From super-cloudops with 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 #20
Source File: WebMvcConfig.java    From NoteBlog with MIT License 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return container -> {
        container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error?errorCode=404"));
        container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error?errorCode=500"));
        container.addErrorPages(new ErrorPage(Throwable.class, "/error?errorCode=500"));
    };
}
 
Example #21
Source File: WebRestApiApplication.java    From metasfresh-webui-api-legacy with GNU General Public License v3.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer servletContainerCustomizer()
{
	return servletContainer -> {
		final TomcatEmbeddedServletContainerFactory tomcatContainerFactory = (TomcatEmbeddedServletContainerFactory)servletContainer;
		tomcatContainerFactory.addConnectorCustomizers(connector -> {
			final AbstractHttp11Protocol<?> httpProtocol = (AbstractHttp11Protocol<?>)connector.getProtocolHandler();
			httpProtocol.setCompression("on");
			httpProtocol.setCompressionMinSize(256);
			final String mimeTypes = httpProtocol.getCompressibleMimeType();
			final String mimeTypesWithJson = mimeTypes + "," + MediaType.APPLICATION_JSON_VALUE + ",application/javascript";
			httpProtocol.setCompressibleMimeType(mimeTypesWithJson);
		});
	};
}
 
Example #22
Source File: WebConfig.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return container -> {
        if (config.getServer().getHost() != null) {
            try {
                container.setAddress(InetAddress.getByName(config.getServer().getHost()));
            } catch (UnknownHostException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        container.setPort(config.getServer().getPort());
        container.setSsl(config.getSsl());
    };
}
 
Example #23
Source File: SpringVueDemoApplication.java    From spring-vue-demo with MIT License 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

	return (container -> {
		ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html");

		container.addErrorPages(error404Page);
	});
}
 
Example #24
Source File: ShutdownConfig.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * 用于注入 connector
 *
 * @return
 */
@Bean
public EmbeddedServletContainerCustomizer tomcatCustomizer() {
    return container -> {
        if (container instanceof TomcatEmbeddedServletContainerFactory) {
            ((TomcatEmbeddedServletContainerFactory) container).addConnectorCustomizers(gracefulShutdown());
        }
    };
}
 
Example #25
Source File: WebConfig.java    From easyweb with 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 #26
Source File: RagnarApplication.java    From fiery with 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 #27
Source File: Application.java    From ethereum-secure-proxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new EmbeddedServletContainerCustomizer() {
        @Override
        public void customize(ConfigurableEmbeddedServletContainer container) {
            container.setPort(cmdLineResult.getPort());
        }
    };
}
 
Example #28
Source File: AdminApplication.java    From JavaQuarkBBS with Apache License 2.0 5 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {

    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 #29
Source File: Application.java    From onboard with Apache License 2.0 4 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
    return new OnboardCustomizer();
}
 
Example #30
Source File: Application.java    From blog-non-blocking-rest-service-with-spring-mvc with Apache License 2.0 4 votes vote down vote up
@Bean
public EmbeddedServletContainerCustomizer embeddedServletCustomizer(){
    return new MyEmbeddedServletContainerCustomizer();
}