/** * 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); /* * 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)); } }
@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()); } }); } } }; }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { logger.info("Customizing EmbeddedServlet"); Integer serverPort; { // setup the server port using the env vars String engineServerPortString = System.getenv().get(ENGINE_SERVER_PORT_KEY); if (engineServerPortString == null) { logger.error("FAILED to find env var [{}], will use defaults for engine server port", ENGINE_SERVER_PORT_KEY); serverPort = defaultServerPort; } else { logger.info("FOUND env var [{}], will use for engine server port", ENGINE_SERVER_PORT_KEY); serverPort = Integer.parseInt(engineServerPortString); } } logger.info("setting serverPort[{}]", serverPort); container.setPort(serverPort); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { 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; int acceptCount = Integer.parseInt(environment.getProperty(TOMCAT_ACCEPTOR_COUNT)); http.setBacklog(acceptCount); logger.info("Setting tomcat accept count to {}", acceptCount); } } }); }
@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); // }); }
@Bean public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = (TomcatEmbeddedServletContainerFactory) container; RedisSessionHandlerValve valve = new RedisSessionHandlerValve(); List<RedisSessionHandlerValve> valves = new ArrayList<RedisSessionHandlerValve>(); valves.add(0, valve); tomcatEmbeddedServletContainerFactory.setContextValves(valves); tomcatEmbeddedServletContainerFactory.setPort(28080); // Set the port of embeded tomcat as 28080 for default. System.out.println("Enterring EmbeddedServletContainerCustomizer.customize()..."); tomcatEmbeddedServletContainerFactory.addContextCustomizers( new ServletContainerCustomizer()); } } }; }
@Bean public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Value("${application.port}") private int embeddedServletContainerListenPort; @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = (TomcatEmbeddedServletContainerFactory) container; if (embeddedServletContainerListenPort <= 1024 || embeddedServletContainerListenPort > 65535) { throw new IllegalArgumentException("The value of \"application.port\" in the properties file is invalid."); } tomcatEmbeddedServletContainerFactory.setPort(embeddedServletContainerListenPort); } } }; }
@Bean public EmbeddedServletContainerCustomizer servletContainerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(final ConfigurableEmbeddedServletContainer servletContainer) { final TomcatEmbeddedServletContainerFactory tomcatContainerFactory = (TomcatEmbeddedServletContainerFactory)servletContainer; tomcatContainerFactory.addConnectorCustomizers(new TomcatConnectorCustomizer() { @Override public void customize(final Connector 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); } }); } }; }
/** * 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. File root; if (env.acceptsProfiles(Constants.SPRING_PROFILE_PRODUCTION)) { root = new File("build/www/"); } else { root = new File("src/main/webapp/"); } if (root.exists() && root.isDirectory()) { container.setDocumentRoot(root); } }
/** * 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); }<% } %> }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { if (this.managementServerProperties == null) { this.managementServerProperties = BeanFactoryUtils .beanOfTypeIncludingAncestors(this.beanFactory, ManagementServerProperties.class); this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors( this.beanFactory, ServerProperties.class); } // Customize as per the parent context first (so e.g. the access logs go to // the same place) this.server.customize(container); // Then reset the error pages container.setErrorPages(Collections.<ErrorPage>emptySet()); // and the context path container.setContextPath(""); // and add the management-specific bits container.setPort(this.managementServerProperties.getPort()); if (this.managementServerProperties.getSsl() != null) { container.setSsl(this.managementServerProperties.getSsl()); } container.setServerHeader(this.server.getServerHeader()); container.setAddress(this.managementServerProperties.getAddress()); container.addErrorPages(new ErrorPage(this.server.getError().getPath())); }
/** * Container customizer. Configures the embedded tomcat (e.g. post size) * * @return the embedded servlet container customizer * @throws Exception the exception */ @Bean public EmbeddedServletContainerCustomizer containerCustomizer( ) throws Exception { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container; tomcat.addConnectorCustomizers( new TomcatConnectorCustomizer() { @Override public void customize(Connector connector) { connector.setMaxPostSize(20000000);//20MB } } ); } } }; }
@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); }
/** * 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)); } }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { if (this.managementServerProperties == null) { this.managementServerProperties = BeanFactoryUtils .beanOfTypeIncludingAncestors(this.beanFactory, ManagementServerProperties.class); this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors( this.beanFactory, ServerProperties.class); } // Customize as per the parent context first (so e.g. the access logs go to // the same place) this.server.customize(container); // Then reset the error pages container.setErrorPages(Collections.<ErrorPage>emptySet()); // and the context path container.setContextPath(""); // and add the management-specific bits container.setPort(this.managementServerProperties.getPort()); container.setServerHeader(this.server.getServerHeader()); container.setAddress(this.managementServerProperties.getAddress()); container.addErrorPages(new ErrorPage(this.server.getError().getPath())); }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { if (this.managementServerProperties == null) { this.managementServerProperties = BeanFactoryUtils .beanOfTypeIncludingAncestors(this.beanFactory, ManagementServerProperties.class); this.server = BeanFactoryUtils.beanOfTypeIncludingAncestors( this.beanFactory, ServerProperties.class); } // Customize as per the parent context first (so e.g. the access logs go to // the same place) this.server.customize(container); // Then reset the error pages container.setErrorPages(Collections.<ErrorPage>emptySet()); // and add the management-specific bits container.setPort(this.managementServerProperties.getPort()); container.setAddress(this.managementServerProperties.getAddress()); container.addErrorPages(new ErrorPage(this.server.getError().getPath())); }
/** * 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"); mappings.add("svg", "image/svg+xml"); mappings.add("ttf", "application/x-font-ttf"); mappings.add("otf", "application/x-font-opentype"); mappings.add("woff", "application/font-woff"); mappings.add("woff2", "application/font-woff2"); mappings.add("eot", "application/vnd.ms-fontobject"); mappings.add("sfnt", "application/font-sfnt"); mappings.add("odt", "application/vnd.oasis.opendocument.text"); mappings.add("pdf", "application/pdf"); mappings.add("jpg", "image/jpeg"); mappings.add("jpeg", "image/jpeg"); mappings.add("png", "image/png"); mappings.add("gif", "image/gif"); container.setMimeMappings(mappings); }
@Bean public EmbeddedServletContainerCustomizer customizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container; TomcatContextCustomizer contextCustomizer = new TomcatContextCustomizer() { @Override public void customize(Context context) { context.setCookieProcessor(new LegacyCookieProcessor()); } }; tomcat.addContextCustomizers(contextCustomizer); } }; }
@Override public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) { final String absoluteKeystoreFile; try { absoluteKeystoreFile = keystoreFile.getFile().getAbsolutePath(); TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) configurableEmbeddedServletContainer; tomcat.addConnectorCustomizers( (connector) -> { connector.setPort(port); connector.setSecure(true); connector.setScheme("https"); Http11NioProtocol proto = (Http11NioProtocol) connector.getProtocolHandler(); proto.setSSLEnabled(true); proto.setKeystoreFile(absoluteKeystoreFile); proto.setKeystorePass(keystorePass); proto.setKeystoreType("PKCS12"); proto.setKeyAlias("tomcat"); } ); } catch (IOException e) { } }
@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); } } } }; }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { super.customize(container); container.addErrorPages(new ErrorPage(HttpStatus.UNAUTHORIZED, "/error/401")); container.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error/403")); container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error/404")); container.addErrorPages(new ErrorPage(HttpStatus.GONE, "/error/410")); container.addErrorPages(new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error")); container.setSessionTimeout(sessionTimeout, TimeUnit.MINUTES); }
@Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404.html"); container.addErrorPages(error404Page); } }; }
/** * 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); }
/** * 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); }
@Bean EmbeddedServletContainerCustomizer containerCustomizer() throws Exception { return (ConfigurableEmbeddedServletContainer container) -> { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container; tomcat.addConnectorCustomizers( (connector) -> { connector.setMaxPostSize(1000000000); // 1000 MB } ); } }; }
/** * Customize the Servlet engine: Mime types, the document root, the cache. */ @Override public void customize(ConfigurableEmbeddedServletContainer container) { MimeMappings mappings = new MimeMappings(MimeMappings.DEFAULT); mappings.add("html", "text/html;charset=utf-8"); 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); }
@Bean public EmbeddedServletContainerCustomizer containerCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { ErrorPage error = new ErrorPage("/error.html"); container.addErrorPages(error); } }; }
@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); }
@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); } }; }
@Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { TomcatEmbeddedServletContainerFactory containerFactory = (TomcatEmbeddedServletContainerFactory) container; //访问日志设置 LogbackValve logbackValve = new LogbackValve(); logbackValve.setQuiet(true); logbackValve.setFilename(logbackAccessFile); containerFactory.addContextValves(logbackValve); } }
@Bean public EmbeddedServletContainerCustomizer tomcatCustomizer() { return new EmbeddedServletContainerCustomizer() { @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (container instanceof TomcatEmbeddedServletContainerFactory) { ((TomcatEmbeddedServletContainerFactory) container) .addConnectorCustomizers(gracefulShutdown()); } } }; }
@Override public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) { if ("dev".equals(active)) { configurableEmbeddedServletContainer.setPort(tomcatServerPort); } else { configurableEmbeddedServletContainer.setPort(VIEW_SERVER_PORT); } }
@Override public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) { configurableEmbeddedServletContainer.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/error404")); configurableEmbeddedServletContainer.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/error403")); Compression compression = new Compression(); compression.setEnabled(true); compression.setMimeTypes(mimeTypes); configurableEmbeddedServletContainer.setCompression(compression); }
/** * 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); }