Skip to content

Commit

Permalink
Polish Undertow contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Nov 18, 2014
1 parent c501b88 commit 1864d79
Show file tree
Hide file tree
Showing 24 changed files with 604 additions and 264 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ overridedb.*
*.ipr
*.iws
.idea
*.jar
.DS_Store
*.jar
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
*
* @author Phillip Webb
* @author Dave Syer
* @author Ivan Sopov
*/
@Order(Ordered.HIGHEST_PRECEDENCE)
@Configuration
Expand Down Expand Up @@ -90,7 +91,7 @@ public JettyEmbeddedServletContainerFactory jettyEmbeddedServletContainerFactory
}

}

/**
* Nested configuration if Undertow is being used.
*/
Expand All @@ -105,7 +106,6 @@ public UndertowEmbeddedServletContainerFactory undertowEmbeddedServletContainerF
}

}


/**
* Registers a {@link EmbeddedServletContainerCustomizerBeanPostProcessor}. Registered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
* @author Dave Syer
* @author Stephane Nicoll
* @author Andy Wilkinson
* @author Ivan Sopov
*/
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = false)
public class ServerProperties implements EmbeddedServletContainerCustomizer {
Expand All @@ -72,7 +73,7 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
private String servletPath = "/";

private final Tomcat tomcat = new Tomcat();

private final Undertow undertow = new Undertow();

private final Map<String, String> contextParameters = new HashMap<String, String>();
Expand Down Expand Up @@ -220,62 +221,6 @@ public String getPath(String path) {
return prefix + path;
}

public static class Undertow {
private Integer bufferSize;
private Integer buffersPerRegion;
private Integer ioThreads;
private Integer workerThreads;
private Boolean directBuffers;

public Integer getBufferSize() {
return this.bufferSize;
}

public void setBufferSize(Integer bufferSize) {
this.bufferSize = bufferSize;
}

public Integer getBuffersPerRegion() {
return this.buffersPerRegion;
}

public void setBuffersPerRegion(Integer buffersPerRegion) {
this.buffersPerRegion = buffersPerRegion;
}

public Integer getIoThreads() {
return this.ioThreads;
}

public void setIoThreads(Integer ioThreads) {
this.ioThreads = ioThreads;
}

public Integer getWorkerThreads() {
return this.workerThreads;
}

public void setWorkerThreads(Integer workerThreads) {
this.workerThreads = workerThreads;
}

public Boolean getDirectBuffers() {
return this.directBuffers;
}

public void setDirectBuffers(Boolean directBuffers) {
this.directBuffers = directBuffers;
}

void customizeUndertow(UndertowEmbeddedServletContainerFactory factory) {
factory.setBufferSize(bufferSize);
factory.setBuffersPerRegion(buffersPerRegion);
factory.setIoThreads(ioThreads);
factory.setWorkerThreads(workerThreads);
factory.setDirectBuffers(directBuffers);
}
}

public static class Tomcat {

private String accessLogPattern;
Expand Down Expand Up @@ -462,4 +407,66 @@ public void customize(Connector connector) {

}

public static class Undertow {

private Integer bufferSize;

private Integer buffersPerRegion;

private Integer ioThreads;

private Integer workerThreads;

private Boolean directBuffers;

public Integer getBufferSize() {
return this.bufferSize;
}

public void setBufferSize(Integer bufferSize) {
this.bufferSize = bufferSize;
}

public Integer getBuffersPerRegion() {
return this.buffersPerRegion;
}

public void setBuffersPerRegion(Integer buffersPerRegion) {
this.buffersPerRegion = buffersPerRegion;
}

public Integer getIoThreads() {
return this.ioThreads;
}

public void setIoThreads(Integer ioThreads) {
this.ioThreads = ioThreads;
}

public Integer getWorkerThreads() {
return this.workerThreads;
}

public void setWorkerThreads(Integer workerThreads) {
this.workerThreads = workerThreads;
}

public Boolean getDirectBuffers() {
return this.directBuffers;
}

public void setDirectBuffers(Boolean directBuffers) {
this.directBuffers = directBuffers;
}

void customizeUndertow(UndertowEmbeddedServletContainerFactory factory) {
factory.setBufferSize(this.bufferSize);
factory.setBuffersPerRegion(this.buffersPerRegion);
factory.setIoThreads(this.ioThreads);
factory.setWorkerThreads(this.workerThreads);
factory.setDirectBuffers(this.directBuffers);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package org.springframework.boot.autoconfigure.web;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.servlet.MultipartConfigElement;

Expand Down Expand Up @@ -65,6 +63,7 @@
* @author Greg Turnquist
* @author Dave Syer
* @author Josh Long
* @author Ivan Sopov
*/
public class MultipartAutoConfigurationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* Tests for {@link ServerPropertiesAutoConfiguration}.
*
* @author Dave Syer
* @author Ivan Sopov
*/
public class ServerPropertiesAutoConfigurationTests {

Expand Down Expand Up @@ -112,8 +113,7 @@ public void customizeWithJettyContainerFactory() throws Exception {
// factory should take precedence...
assertEquals(3000, containerFactory.getPort());
}



@Test
public void customizeWithUndertowContainerFactory() throws Exception {
this.context = new AnnotationConfigEmbeddedWebApplicationContext();
Expand All @@ -127,7 +127,6 @@ public void customizeWithUndertowContainerFactory() throws Exception {
assertNotNull(server);
assertEquals(3000, containerFactory.getPort());
}


@Test
public void customizeTomcatWithCustomizer() throws Exception {
Expand Down Expand Up @@ -186,7 +185,7 @@ public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContai
}

}

@Configuration
protected static class CustomUndertowContainerConfig {

Expand All @@ -203,9 +202,6 @@ public EmbeddedServletContainerCustomizerBeanPostProcessor embeddedServletContai
}

}




@Configuration
protected static class CustomizeConfig {
Expand Down
17 changes: 11 additions & 6 deletions spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@
<thymeleaf-layout-dialect.version>1.2.7</thymeleaf-layout-dialect.version>
<thymeleaf-extras-data-attribute.version>1.3</thymeleaf-extras-data-attribute.version>
<tomcat.version>8.0.15</tomcat.version>
<undertow.version>1.1.0.Final</undertow.version>
<velocity.version>1.7</velocity.version>
<velocity-tools.version>2.0</velocity-tools.version>
<wsdl4j.version>1.6.3</wsdl4j.version>
<undertow.version>1.1.0.Final</undertow.version>
</properties>
<prerequisites>
<maven>3.0.2</maven>
Expand Down Expand Up @@ -540,6 +540,16 @@
<artifactId>metrics-servlets</artifactId>
<version>${dropwizard-metrics.version}</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>${undertow.version}</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${undertow.version}</version>
</dependency>
<dependency>
<groupId>javax.cache</groupId>
<artifactId>cache-api</artifactId>
Expand Down Expand Up @@ -707,11 +717,6 @@
<artifactId>tomcat-jsp-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-servlet</artifactId>
<version>${undertow.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions spring-boot-docs/src/main/asciidoc/cloud-deployment.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ for our starter REST application:

Spring Boot makes `-D` arguments available as properties accessible from a Spring
`Environment` instance. The `server.port` configuration property is fed to the embedded
Tomcat or Jetty instance which then uses it when it starts up. The `$PORT` environment
variable is assigned to us by the Heroku PaaS.
Tomcat, Jetty or Undertow instance which then uses it when it starts up. The `$PORT`
environment variable is assigned to us by the Heroku PaaS.

Heroku by default will use Java 1.6. This is fine as long as your Maven or Gradle build
is set to use the same version (Maven users can use the `java.version` property). If you
Expand Down
55 changes: 55 additions & 0 deletions spring-boot-docs/src/main/asciidoc/howto.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,61 @@ of ways. Or the nuclear option is to add your own `JettyEmbeddedServletContainer



[[howto-use-undertow-instead-of-tomcat]]
=== Use Undertow instead of Tomcat
Using Undertow instead of Tomcat is very similar to <<howto-use-jetty-instead-of-tomcat,
using Jetty instead of Tomcat>>. You need to exclude the Tomcat dependencies and include
the Undertow starter instead.

Example in Maven:

[source,xml,indent=0,subs="verbatim,quotes,attributes"]
----
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
----

Example in Gradle:

[source,groovy,indent=0,subs="verbatim,quotes,attributes"]
----
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:{spring-boot-version}")
compile("org.springframework.boot:spring-boot-starter-undertow:{spring-boot-version}")
// ...
}
----


[[howto-configure-undertow]]
=== Configure Undertow
Generally you can follow the advice from
_<<howto-discover-build-in-options-for-external-properties>>_ about
`@ConfigurationProperties` (`ServerProperties` and `ServerProperties.Undertow are the
main ones here), but also look at
`EmbeddedServletContainerCustomizer`. Once you have access to the
`UndertowEmbeddedServletContainerFactory` you can use an `UndertowBuilderCustomizer` to
modify Undertow's configuration to meet your needs. Or the nuclear option is to add your
own `UndertowEmbeddedServletContainerFactory`.



[[howto-use-tomcat-8]]
=== Use Tomcat 8
Tomcat 8 works with Spring Boot, but the default is to use Tomcat 7 (so we can support
Expand Down
Loading

0 comments on commit 1864d79

Please sign in to comment.