Browse Source

Polish order

pull/4022/merge
Phillip Webb 10 years ago
parent
commit
0b36ba97b3
  1. 242
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

242
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

@ -91,20 +91,21 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord @@ -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<String, String> contextParameters = new HashMap<String, String>();
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 @@ -112,53 +113,53 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord
@NestedConfigurationProperty
private JspServlet jspServlet;
/**
* ServletContext parameters.
*/
private final Map<String, String> contextParameters = new HashMap<String, String>();
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 @@ -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 @@ -185,8 +194,26 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord
return result;
}
public void setServletPath(String servletPath) {
this.servletPath = servletPath;
public String[] getPathsArray(Collection<String> 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 @@ -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<String, String> getContextParameters() {
return this.contextParameters;
}
/**
* Get the session timeout.
* @return the session timeout
@ -230,6 +292,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord @@ -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 @@ -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 @@ -246,78 +316,12 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer, Ord
this.jspServlet = jspServlet;
}
public Map<String, String> 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<String> 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 {

Loading…
Cancel
Save