From 0b36ba97b3cf82e1c3c7b181a73fada62329808a Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 30 Sep 2015 16:24:20 -0700 Subject: [PATCH] Polish order --- .../autoconfigure/web/ServerProperties.java | 242 +++++++++--------- 1 file changed, 123 insertions(+), 119 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index 0974871eaaf..b0c9a813c80 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -91,20 +91,21 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord */ private String displayName = "application"; - private Session session = new Session(); - - @NestedConfigurationProperty - private Ssl ssl; - /** * Path of the main dispatcher servlet. */ @NotNull private String servletPath = "/"; - private final Tomcat tomcat = new Tomcat(); + /** + * ServletContext parameters. + */ + private final Map contextParameters = new HashMap(); - private final Undertow undertow = new Undertow(); + private Session session = new Session(); + + @NestedConfigurationProperty + private Ssl ssl; @NestedConfigurationProperty private Compression compression = new Compression(); @@ -112,53 +113,53 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord @NestedConfigurationProperty private JspServlet jspServlet; - /** - * ServletContext parameters. - */ - private final Map contextParameters = new HashMap(); + private final Tomcat tomcat = new Tomcat(); + + private final Undertow undertow = new Undertow(); @Override public int getOrder() { return 0; } - public Tomcat getTomcat() { - return this.tomcat; - } - - public Undertow getUndertow() { - return this.undertow; - } - - public Compression getCompression() { - return this.compression; - } - - public String getContextPath() { - return this.contextPath; - } - - public void setContextPath(String contextPath) { - this.contextPath = cleanContextPath(contextPath); - } - - private String cleanContextPath(String contextPath) { - if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) { - return contextPath.substring(0, contextPath.length() - 1); + @Override + public void customize(ConfigurableEmbeddedServletContainer container) { + if (getPort() != null) { + container.setPort(getPort()); } - return contextPath; - } - - public String getDisplayName() { - return this.displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public String getServletPath() { - return this.servletPath; + if (getAddress() != null) { + container.setAddress(getAddress()); + } + if (getContextPath() != null) { + container.setContextPath(getContextPath()); + } + if (getDisplayName() != null) { + container.setDisplayName(getDisplayName()); + } + if (getSession().getTimeout() != null) { + container.setSessionTimeout(getSession().getTimeout()); + } + container.setPersistSession(getSession().isPersistent()); + if (getSsl() != null) { + container.setSsl(getSsl()); + } + if (getJspServlet() != null) { + container.setJspServlet(getJspServlet()); + } + if (getCompression() != null) { + container.setCompression(getCompression()); + } + if (container instanceof TomcatEmbeddedServletContainerFactory) { + getTomcat() + .customizeTomcat((TomcatEmbeddedServletContainerFactory) container); + } + if (container instanceof UndertowEmbeddedServletContainerFactory) { + getUndertow().customizeUndertow( + (UndertowEmbeddedServletContainerFactory) container); + } + container.addInitializers(new SessionConfiguringInitializer(this.session)); + container.addInitializers(new InitParameterConfiguringServletContextInitializer( + getContextParameters())); } public String getServletMapping() { @@ -174,6 +175,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord return this.servletPath + "/*"; } + public String getPath(String path) { + String prefix = getServletPrefix(); + if (!path.startsWith("/")) { + path = "/" + path; + } + return prefix + path; + } + public String getServletPrefix() { String result = this.servletPath; if (result.contains("*")) { @@ -185,8 +194,26 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord return result; } - public void setServletPath(String servletPath) { - this.servletPath = servletPath; + public String[] getPathsArray(Collection paths) { + String[] result = new String[paths.size()]; + int i = 0; + for (String path : paths) { + result[i++] = getPath(path); + } + return result; + } + + public String[] getPathsArray(String[] paths) { + String[] result = new String[paths.length]; + int i = 0; + for (String path : paths) { + result[i++] = getPath(path); + } + return result; + } + + public void setLoader(String value) { + // no op to support Tomcat running as a traditional container (not embedded) } public Integer getPort() { @@ -205,6 +232,41 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord this.address = address; } + public String getContextPath() { + return this.contextPath; + } + + public void setContextPath(String contextPath) { + this.contextPath = cleanContextPath(contextPath); + } + + private String cleanContextPath(String contextPath) { + if (StringUtils.hasText(contextPath) && contextPath.endsWith("/")) { + return contextPath.substring(0, contextPath.length() - 1); + } + return contextPath; + } + + public String getDisplayName() { + return this.displayName; + } + + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + public String getServletPath() { + return this.servletPath; + } + + public void setServletPath(String servletPath) { + this.servletPath = servletPath; + } + + public Map getContextParameters() { + return this.contextParameters; + } + /** * Get the session timeout. * @return the session timeout @@ -230,6 +292,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord return this.session; } + public void setSession(Session session) { + this.session = session; + } + public Ssl getSsl() { return this.ssl; } @@ -238,6 +304,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord this.ssl = ssl; } + public Compression getCompression() { + return this.compression; + } + public JspServlet getJspServlet() { return this.jspServlet; } @@ -246,78 +316,12 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord this.jspServlet = jspServlet; } - public Map getContextParameters() { - return this.contextParameters; - } - - public void setLoader(String value) { - // no op to support Tomcat running as a traditional container (not embedded) - } - - @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - if (getPort() != null) { - container.setPort(getPort()); - } - if (getAddress() != null) { - container.setAddress(getAddress()); - } - if (getContextPath() != null) { - container.setContextPath(getContextPath()); - } - if (getDisplayName() != null) { - container.setDisplayName(getDisplayName()); - } - if (getSession().getTimeout() != null) { - container.setSessionTimeout(getSession().getTimeout()); - } - container.setPersistSession(getSession().isPersistent()); - if (getSsl() != null) { - container.setSsl(getSsl()); - } - if (getJspServlet() != null) { - container.setJspServlet(getJspServlet()); - } - if (getCompression() != null) { - container.setCompression(getCompression()); - } - if (container instanceof TomcatEmbeddedServletContainerFactory) { - getTomcat() - .customizeTomcat((TomcatEmbeddedServletContainerFactory) container); - } - if (container instanceof UndertowEmbeddedServletContainerFactory) { - getUndertow().customizeUndertow( - (UndertowEmbeddedServletContainerFactory) container); - } - container.addInitializers(new SessionConfiguringInitializer(this.session)); - container.addInitializers(new InitParameterConfiguringServletContextInitializer( - getContextParameters())); - } - - public String[] getPathsArray(Collection paths) { - String[] result = new String[paths.size()]; - int i = 0; - for (String path : paths) { - result[i++] = getPath(path); - } - return result; - } - - public String[] getPathsArray(String[] paths) { - String[] result = new String[paths.length]; - int i = 0; - for (String path : paths) { - result[i++] = getPath(path); - } - return result; + public Tomcat getTomcat() { + return this.tomcat; } - public String getPath(String path) { - String prefix = getServletPrefix(); - if (!path.startsWith("/")) { - path = "/" + path; - } - return prefix + path; + public Undertow getUndertow() { + return this.undertow; } public static class Session {