Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
c501b889
Commit
c501b889
authored
Nov 14, 2014
by
sopov.ivan
Committed by
Andy Wilkinson
Nov 18, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for using Undertow as an embedded container
See gh-1779
parent
21115f29
Changes
27
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
1215 additions
and
7 deletions
+1215
-7
.gitignore
.gitignore
+2
-1
pom.xml
spring-boot-autoconfigure/pom.xml
+5
-0
EmbeddedServletContainerAutoConfiguration.java
...figure/web/EmbeddedServletContainerAutoConfiguration.java
+19
-0
ServerProperties.java
...ingframework/boot/autoconfigure/web/ServerProperties.java
+67
-1
MultipartAutoConfigurationTests.java
...ot/autoconfigure/web/MultipartAutoConfigurationTests.java
+79
-1
ServerPropertiesAutoConfigurationTests.java
...configure/web/ServerPropertiesAutoConfigurationTests.java
+40
-3
pom.xml
spring-boot-dependencies/pom.xml
+11
-0
pom.xml
spring-boot-samples/pom.xml
+2
-0
pom.xml
spring-boot-samples/spring-boot-sample-undertow-ssl/pom.xml
+53
-0
SampleUndertowSslApplication.java
...in/java/sample/undertow/SampleUndertowSslApplication.java
+29
-0
HelloWorldService.java
.../main/java/sample/undertow/service/HelloWorldService.java
+32
-0
SampleController.java
...l/src/main/java/sample/undertow/web/SampleController.java
+37
-0
application.properties
...le-undertow-ssl/src/main/resources/application.properties
+4
-0
sample.jks
...ng-boot-sample-undertow-ssl/src/main/resources/sample.jks
+0
-0
SampleUndertowSslApplicationTests.java
...va/sample/undertow/SampleUndertowSslApplicationTests.java
+72
-0
pom.xml
spring-boot-samples/spring-boot-sample-undertow/pom.xml
+48
-0
SampleUndertowApplication.java
.../main/java/sample/undertow/SampleUndertowApplication.java
+29
-0
HelloWorldService.java
.../main/java/sample/undertow/service/HelloWorldService.java
+32
-0
SampleController.java
...w/src/main/java/sample/undertow/web/SampleController.java
+37
-0
SampleUndertowApplicationTests.java
.../java/sample/undertow/SampleUndertowApplicationTests.java
+56
-0
pom.xml
spring-boot-starters/pom.xml
+1
-0
pom.xml
spring-boot-starters/spring-boot-starter-undertow/pom.xml
+27
-0
pom.xml
spring-boot/pom.xml
+5
-0
UndertowEmbeddedServletContainer.java
...t/embedded/undertow/UndertowEmbeddedServletContainer.java
+77
-0
UndertowEmbeddedServletContainerFactory.java
...ded/undertow/UndertowEmbeddedServletContainerFactory.java
+396
-0
EmbeddedServletContainerMvcIntegrationTests.java
...embedded/EmbeddedServletContainerMvcIntegrationTests.java
+21
-1
UndertowEmbeddedServletContainerFactoryTests.java
...ndertow/UndertowEmbeddedServletContainerFactoryTests.java
+34
-0
No files found.
.gitignore
View file @
c501b889
...
...
@@ -8,6 +8,7 @@
.classpath
.project
.settings
.metadata
bin
build
lib/
...
...
@@ -28,4 +29,4 @@ overridedb.*
*.iws
.idea
*.jar
.DS_Store
\ No newline at end of file
.DS_Store
spring-boot-autoconfigure/pom.xml
View file @
c501b889
...
...
@@ -160,6 +160,11 @@
<artifactId>
jetty-webapp
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
io.undertow
</groupId>
<artifactId>
undertow-servlet
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.freemarker
</groupId>
<artifactId>
freemarker
</artifactId>
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/EmbeddedServletContainerAutoConfiguration.java
View file @
c501b889
...
...
@@ -16,6 +16,8 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
io.undertow.Undertow
;
import
javax.servlet.Servlet
;
import
org.apache.catalina.startup.Tomcat
;
...
...
@@ -37,6 +39,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomi
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -87,6 +90,22 @@ public class EmbeddedServletContainerAutoConfiguration {
}
}
/**
* Nested configuration if Undertow is being used.
*/
@Configuration
@ConditionalOnClass
({
Servlet
.
class
,
Undertow
.
class
})
@ConditionalOnMissingBean
(
value
=
EmbeddedServletContainerFactory
.
class
,
search
=
SearchStrategy
.
CURRENT
)
public
static
class
EmbeddedUndertow
{
@Bean
public
UndertowEmbeddedServletContainerFactory
undertowEmbeddedServletContainerFactory
()
{
return
new
UndertowEmbeddedServletContainerFactory
();
}
}
/**
* Registers a {@link EmbeddedServletContainerCustomizerBeanPostProcessor}. Registered
...
...
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java
View file @
c501b889
...
...
@@ -40,6 +40,7 @@ import org.springframework.boot.context.embedded.Ssl;
import
org.springframework.boot.context.embedded.tomcat.TomcatConnectorCustomizer
;
import
org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
import
org.springframework.boot.context.properties.NestedConfigurationProperty
;
import
org.springframework.util.StringUtils
;
...
...
@@ -71,6 +72,8 @@ 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
>();
...
...
@@ -78,6 +81,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
return
this
.
tomcat
;
}
public
Undertow
getUndertow
()
{
return
this
.
undertow
;
}
public
String
getContextPath
()
{
return
this
.
contextPath
;
}
...
...
@@ -179,7 +186,10 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
getTomcat
()
.
customizeTomcat
((
TomcatEmbeddedServletContainerFactory
)
container
);
}
if
(
container
instanceof
UndertowEmbeddedServletContainerFactory
)
{
getUndertow
().
customizeUndertow
(
(
UndertowEmbeddedServletContainerFactory
)
container
);
}
container
.
addInitializers
(
new
InitParameterConfiguringServletContextInitializer
(
getContextParameters
()));
}
...
...
@@ -210,6 +220,62 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
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
;
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfigurationTests.java
View file @
c501b889
...
...
@@ -16,6 +16,10 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
web
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
javax.servlet.MultipartConfigElement
;
import
org.junit.After
;
...
...
@@ -25,10 +29,16 @@ import org.junit.rules.ExpectedException;
import
org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.core.env.PropertySource
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.client.ClientHttpRequest
;
import
org.springframework.http.client.ClientHttpResponse
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
...
...
@@ -71,10 +81,11 @@ public class MultipartAutoConfigurationTests {
}
@Test
public
void
containerWithNothing
()
{
public
void
containerWithNothing
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
ContainerWithNothing
.
class
,
BaseConfiguration
.
class
);
DispatcherServlet
servlet
=
this
.
context
.
getBean
(
DispatcherServlet
.
class
);
verify404
();
assertNotNull
(
servlet
.
getMultipartResolver
());
assertThat
(
this
.
context
.
getBeansOfType
(
StandardServletMultipartResolver
.
class
)
.
size
(),
equalTo
(
1
));
...
...
@@ -112,6 +123,32 @@ public class MultipartAutoConfigurationTests {
}
}
@Test
public
void
containerWithNoMultipartUndertowConfiguration
()
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
ContainerWithNoMultipartUndertow
.
class
,
BaseConfiguration
.
class
);
DispatcherServlet
servlet
=
this
.
context
.
getBean
(
DispatcherServlet
.
class
);
verifyServletWorks
();
assertNotNull
(
servlet
.
getMultipartResolver
());
assertThat
(
this
.
context
.
getBeansOfType
(
StandardServletMultipartResolver
.
class
)
.
size
(),
equalTo
(
1
));
assertThat
(
this
.
context
.
getBeansOfType
(
MultipartResolver
.
class
).
size
(),
equalTo
(
1
));
}
@Configuration
public
static
class
ContainerWithNoMultipartUndertow
{
@Bean
UndertowEmbeddedServletContainerFactory
containerFactory
()
{
return
new
UndertowEmbeddedServletContainerFactory
();
}
@Bean
WebController
controller
()
{
return
new
WebController
();
}
}
@Test
public
void
containerWithNoMultipartTomcatConfiguration
()
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
...
...
@@ -148,6 +185,16 @@ public class MultipartAutoConfigurationTests {
verifyServletWorks
();
}
@Test
public
void
containerWithAutomatedMultipartUndertowConfiguration
()
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
ContainerWithEverythingUndertow
.
class
,
BaseConfiguration
.
class
);
this
.
context
.
getBean
(
MultipartConfigElement
.
class
);
verifyServletWorks
();
assertSame
(
this
.
context
.
getBean
(
DispatcherServlet
.
class
).
getMultipartResolver
(),
this
.
context
.
getBean
(
StandardServletMultipartResolver
.
class
));
}
@Test
public
void
containerWithMultipartConfigDisabled
()
{
...
...
@@ -178,6 +225,16 @@ public class MultipartAutoConfigurationTests {
not
(
instanceOf
(
StandardServletMultipartResolver
.
class
)));
}
private
void
verify404
()
throws
Exception
{
HttpComponentsClientHttpRequestFactory
requestFactory
=
new
HttpComponentsClientHttpRequestFactory
();
ClientHttpRequest
request
=
requestFactory
.
createRequest
(
new
URI
(
"http://localhost:"
+
this
.
context
.
getEmbeddedServletContainer
().
getPort
()
+
"/"
),
HttpMethod
.
GET
);
ClientHttpResponse
response
=
request
.
execute
();
assertEquals
(
HttpStatus
.
NOT_FOUND
,
response
.
getStatusCode
());
}
private
void
verifyServletWorks
()
{
RestTemplate
restTemplate
=
new
RestTemplate
();
assertEquals
(
"Hello"
,
restTemplate
.
getForObject
(
"http://localhost:"
...
...
@@ -256,6 +313,27 @@ public class MultipartAutoConfigurationTests {
}
@Configuration
@EnableWebMvc
public
static
class
ContainerWithEverythingUndertow
{
@Bean
MultipartConfigElement
multipartConfigElement
()
{
return
new
MultipartConfigElement
(
""
);
}
@Bean
UndertowEmbeddedServletContainerFactory
containerFactory
()
{
return
new
UndertowEmbeddedServletContainerFactory
();
}
@Bean
WebController
webController
()
{
return
new
WebController
();
}
}
public
static
class
ContainerWithCustomMultipartResolver
{
@Bean
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesAutoConfigurationTests.java
View file @
c501b889
...
...
@@ -32,6 +32,7 @@ import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomi
import
org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.ApplicationContextException
;
import
org.springframework.context.annotation.Bean
;
...
...
@@ -97,9 +98,9 @@ public class ServerPropertiesAutoConfigurationTests {
}
@Test
public
void
customizeWithContainerFactory
()
throws
Exception
{
public
void
customizeWith
Jetty
ContainerFactory
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
CustomContainerConfig
.
class
,
this
.
context
.
register
(
Custom
Jetty
ContainerConfig
.
class
,
ServerPropertiesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
...
...
@@ -111,6 +112,22 @@ public class ServerPropertiesAutoConfigurationTests {
// factory should take precedence...
assertEquals
(
3000
,
containerFactory
.
getPort
());
}
@Test
public
void
customizeWithUndertowContainerFactory
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
();
this
.
context
.
register
(
CustomUndertowContainerConfig
.
class
,
ServerPropertiesAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
.
refresh
();
containerFactory
=
this
.
context
.
getBean
(
AbstractEmbeddedServletContainerFactory
.
class
);
ServerProperties
server
=
this
.
context
.
getBean
(
ServerProperties
.
class
);
assertNotNull
(
server
);
assertEquals
(
3000
,
containerFactory
.
getPort
());
}
@Test
public
void
customizeTomcatWithCustomizer
()
throws
Exception
{
...
...
@@ -154,7 +171,7 @@ public class ServerPropertiesAutoConfigurationTests {
}
@Configuration
protected
static
class
CustomContainerConfig
{
protected
static
class
Custom
Jetty
ContainerConfig
{
@Bean
public
EmbeddedServletContainerFactory
containerFactory
()
{
...
...
@@ -169,6 +186,26 @@ public class ServerPropertiesAutoConfigurationTests {
}
}
@Configuration
protected
static
class
CustomUndertowContainerConfig
{
@Bean
public
EmbeddedServletContainerFactory
containerFactory
()
{
UndertowEmbeddedServletContainerFactory
factory
=
new
UndertowEmbeddedServletContainerFactory
();
factory
.
setPort
(
3000
);
return
factory
;
}
@Bean
public
EmbeddedServletContainerCustomizerBeanPostProcessor
embeddedServletContainerCustomizerBeanPostProcessor
()
{
return
new
EmbeddedServletContainerCustomizerBeanPostProcessor
();
}
}
@Configuration
protected
static
class
CustomizeConfig
{
...
...
spring-boot-dependencies/pom.xml
View file @
c501b889
...
...
@@ -130,6 +130,7 @@
<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>
...
...
@@ -289,6 +290,11 @@
<artifactId>
spring-boot-starter-jta-bitronix
</artifactId>
<version>
1.2.0.BUILD-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-undertow
</artifactId>
<version>
1.2.0.BUILD-SNAPSHOT
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-log4j
</artifactId>
...
...
@@ -701,6 +707,11 @@
<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>
...
...
spring-boot-samples/pom.xml
View file @
c501b889
...
...
@@ -59,6 +59,8 @@
<module>
spring-boot-sample-tomcat-multi-connectors
</module>
<module>
spring-boot-sample-tomcat7-jsp
</module>
<module>
spring-boot-sample-traditional
</module>
<module>
spring-boot-sample-undertow
</module>
<module>
spring-boot-sample-undertow-ssl
</module>
<module>
spring-boot-sample-velocity
</module>
<module>
spring-boot-sample-web-freemarker
</module>
<module>
spring-boot-sample-web-groovy-templates
</module>
...
...
spring-boot-samples/spring-boot-sample-undertow-ssl/pom.xml
0 → 100644
View file @
c501b889
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-samples
</artifactId>
<version>
1.2.0.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-sample-undertow-ssl
</artifactId>
<name>
Spring Boot Undertow SSL Sample
</name>
<description>
Spring Boot Undertow SSL Sample
</description>
<url>
http://projects.spring.io/spring-boot/
</url>
<organization>
<name>
Pivotal Software, Inc.
</name>
<url>
http://www.spring.io
</url>
</organization>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-undertow
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/SampleUndertowSslApplication.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
SampleUndertowSslApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleUndertowSslApplication
.
class
,
args
);
}
}
spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/service/HelloWorldService.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
.
service
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
@Component
public
class
HelloWorldService
{
@Value
(
"${name:World}"
)
private
String
name
;
public
String
getHelloMessage
()
{
return
"Hello "
+
this
.
name
;
}
}
spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/java/sample/undertow/web/SampleController.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
.
web
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
sample.undertow.service.HelloWorldService
;
@Controller
public
class
SampleController
{
@Autowired
private
HelloWorldService
helloWorldService
;
@RequestMapping
(
"/"
)
@ResponseBody
public
String
helloWorld
()
{
return
this
.
helloWorldService
.
getHelloMessage
();
}
}
spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/application.properties
0 → 100644
View file @
c501b889
server.port
=
8443
server.ssl.key-store
=
classpath:sample.jks
server.ssl.key-store-password
=
secret
server.ssl.key-password
=
password
\ No newline at end of file
spring-boot-samples/spring-boot-sample-undertow-ssl/src/main/resources/sample.jks
0 → 100644
View file @
c501b889
File added
spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/SampleUndertowSslApplicationTests.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLContextBuilder
;
import
org.apache.http.conn.ssl.TrustSelfSignedStrategy
;
import
org.apache.http.impl.client.HttpClients
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.IntegrationTest
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* Basic integration tests for demo application.
*
* @author Dave Syer
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleUndertowSslApplication
.
class
)
@WebAppConfiguration
@IntegrationTest
(
"server.port:0"
)
@DirtiesContext
public
class
SampleUndertowSslApplicationTests
{
@Value
(
"${local.server.port}"
)
private
int
port
;
@Test
public
void
testHome
()
throws
Exception
{
SSLConnectionSocketFactory
socketFactory
=
new
SSLConnectionSocketFactory
(
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustSelfSignedStrategy
()).
build
());
HttpClient
httpClient
=
HttpClients
.
custom
().
setSSLSocketFactory
(
socketFactory
)
.
build
();
TestRestTemplate
testRestTemplate
=
new
TestRestTemplate
();
((
HttpComponentsClientHttpRequestFactory
)
testRestTemplate
.
getRequestFactory
())
.
setHttpClient
(
httpClient
);
ResponseEntity
<
String
>
entity
=
testRestTemplate
.
getForEntity
(
"https://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertEquals
(
"Hello World"
,
entity
.
getBody
());
}
}
spring-boot-samples/spring-boot-sample-undertow/pom.xml
0 → 100644
View file @
c501b889
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-samples
</artifactId>
<version>
1.2.0.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-sample-undertow
</artifactId>
<name>
Spring Boot Undertow Sample
</name>
<description>
Spring Boot Undertow Sample
</description>
<url>
http://projects.spring.io/spring-boot/
</url>
<organization>
<name>
Pivotal Software, Inc.
</name>
<url>
http://www.spring.io
</url>
</organization>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-undertow
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/SampleUndertowApplication.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
@SpringBootApplication
public
class
SampleUndertowApplication
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
SpringApplication
.
run
(
SampleUndertowApplication
.
class
,
args
);
}
}
spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/service/HelloWorldService.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
.
service
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
@Component
public
class
HelloWorldService
{
@Value
(
"${name:World}"
)
private
String
name
;
public
String
getHelloMessage
()
{
return
"Hello "
+
this
.
name
;
}
}
spring-boot-samples/spring-boot-sample-undertow/src/main/java/sample/undertow/web/SampleController.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
.
web
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
sample.undertow.service.HelloWorldService
;
@Controller
public
class
SampleController
{
@Autowired
private
HelloWorldService
helloWorldService
;
@RequestMapping
(
"/"
)
@ResponseBody
public
String
helloWorld
()
{
return
this
.
helloWorldService
.
getHelloMessage
();
}
}
spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java
0 → 100644
View file @
c501b889
/*
* Copyright 2012-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
sample
.
undertow
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.IntegrationTest
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
/**
* Basic integration tests for demo application.
*
* @author Ivan Sopov
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SampleUndertowApplication
.
class
)
@WebAppConfiguration
@IntegrationTest
(
"server.port:0"
)
@DirtiesContext
public
class
SampleUndertowApplicationTests
{
@Value
(
"${local.server.port}"
)
private
int
port
;
@Test
public
void
testHome
()
throws
Exception
{
ResponseEntity
<
String
>
entity
=
new
TestRestTemplate
().
getForEntity
(
"http://localhost:"
+
this
.
port
,
String
.
class
);
assertEquals
(
HttpStatus
.
OK
,
entity
.
getStatusCode
());
assertEquals
(
"Hello World"
,
entity
.
getBody
());
}
}
spring-boot-starters/pom.xml
View file @
c501b889
...
...
@@ -56,6 +56,7 @@
<module>
spring-boot-starter-test
</module>
<module>
spring-boot-starter-thymeleaf
</module>
<module>
spring-boot-starter-tomcat
</module>
<module>
spring-boot-starter-undertow
</module>
<module>
spring-boot-starter-velocity
</module>
<module>
spring-boot-starter-web
</module>
<module>
spring-boot-starter-websocket
</module>
...
...
spring-boot-starters/spring-boot-starter-undertow/pom.xml
0 → 100644
View file @
c501b889
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starters
</artifactId>
<version>
1.2.0.BUILD-SNAPSHOT
</version>
</parent>
<artifactId>
spring-boot-starter-undertow
</artifactId>
<name>
Spring Boot Undertow Starter
</name>
<description>
Spring Boot Undertow Starter
</description>
<url>
http://projects.spring.io/spring-boot/
</url>
<organization>
<name>
Pivotal Software, Inc.
</name>
<url>
http://www.spring.io
</url>
</organization>
<properties>
<main.basedir>
${basedir}/../..
</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>
io.undertow
</groupId>
<artifactId>
undertow-servlet
</artifactId>
</dependency>
</dependencies>
</project>
spring-boot/pom.xml
View file @
c501b889
...
...
@@ -129,6 +129,11 @@
<artifactId>
jetty-util
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
io.undertow
</groupId>
<artifactId>
undertow-servlet
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
org.hibernate
</groupId>
<artifactId>
hibernate-entitymanager
</artifactId>
...
...
spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainer.java
0 → 100644
View file @
c501b889
package
org
.
springframework
.
boot
.
context
.
embedded
.
undertow
;
import
io.undertow.Handlers
;
import
io.undertow.Undertow
;
import
io.undertow.Undertow.Builder
;
import
io.undertow.server.HttpHandler
;
import
io.undertow.server.handlers.PathHandler
;
import
io.undertow.servlet.api.DeploymentManager
;
import
javax.servlet.ServletException
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainer
;
import
org.springframework.boot.context.embedded.EmbeddedServletContainerException
;
import
org.springframework.util.StringUtils
;
/**
* @author Ivan Sopov
*/
public
class
UndertowEmbeddedServletContainer
implements
EmbeddedServletContainer
{
private
final
DeploymentManager
manager
;
private
final
Builder
builder
;
private
final
String
contextPath
;
private
final
int
port
;
private
final
boolean
autoStart
;
private
Undertow
undertow
;
private
boolean
started
=
false
;
public
UndertowEmbeddedServletContainer
(
Builder
builder
,
DeploymentManager
manager
,
String
contextPath
,
int
port
,
boolean
autoStart
)
{
this
.
builder
=
builder
;
this
.
manager
=
manager
;
this
.
contextPath
=
contextPath
;
this
.
port
=
port
;
this
.
autoStart
=
autoStart
;
}
@Override
public
synchronized
void
start
()
throws
EmbeddedServletContainerException
{
if
(!
this
.
autoStart
)
{
return
;
}
if
(
undertow
==
null
)
{
try
{
HttpHandler
servletHandler
=
manager
.
start
();
if
(
StringUtils
.
isEmpty
(
contextPath
))
{
builder
.
setHandler
(
servletHandler
);
}
else
{
PathHandler
pathHandler
=
Handlers
.
path
().
addPrefixPath
(
contextPath
,
servletHandler
);
builder
.
setHandler
(
pathHandler
);
}
undertow
=
builder
.
build
();
}
catch
(
ServletException
ex
)
{
throw
new
EmbeddedServletContainerException
(
"Unable to start embdedded Undertow"
,
ex
);
}
}
undertow
.
start
();
started
=
true
;
}
@Override
public
synchronized
void
stop
()
throws
EmbeddedServletContainerException
{
if
(
started
)
{
started
=
false
;
undertow
.
stop
();
}
}
@Override
public
int
getPort
()
{
return
port
;
}
}
\ No newline at end of file
spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java
0 → 100644
View file @
c501b889
This diff is collapsed.
Click to expand it.
spring-boot/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerMvcIntegrationTests.java
View file @
c501b889
...
...
@@ -24,6 +24,7 @@ import org.junit.Test;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
;
import
org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
...
...
@@ -68,7 +69,7 @@ public class EmbeddedServletContainerMvcIntegrationTests {
TomcatConfig
.
class
);
doTest
(
this
.
context
,
"/hello"
);
}
@Test
public
void
jetty
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
...
...
@@ -76,6 +77,16 @@ public class EmbeddedServletContainerMvcIntegrationTests {
doTest
(
this
.
context
,
"/hello"
);
}
@Test
public
void
undertow
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
UndertowConfig
.
class
);
doTest
(
this
.
context
,
"/hello"
);
}
@Test
public
void
advancedConfig
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigEmbeddedWebApplicationContext
(
...
...
@@ -117,6 +128,15 @@ public class EmbeddedServletContainerMvcIntegrationTests {
return
new
JettyEmbeddedServletContainerFactory
(
0
);
}
}
@Configuration
@Import
(
Config
.
class
)
public
static
class
UndertowConfig
{
@Bean
public
EmbeddedServletContainerFactory
containerFactory
()
{
return
new
UndertowEmbeddedServletContainerFactory
(
0
);
}
}
@Configuration
@EnableWebMvc
...
...
spring-boot/src/test/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactoryTests.java
0 → 100644
View file @
c501b889
package
org
.
springframework
.
boot
.
context
.
embedded
.
undertow
;
import
org.junit.Test
;
import
org.springframework.boot.context.embedded.*
;
import
org.springframework.http.HttpStatus
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
/**
* Tests for {@link org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory} and
* {@link org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer}.
*
* @author Ivan Sopov
*/
public
class
UndertowEmbeddedServletContainerFactoryTests
extends
AbstractEmbeddedServletContainerFactoryTests
{
@Override
protected
UndertowEmbeddedServletContainerFactory
getFactory
()
{
return
new
UndertowEmbeddedServletContainerFactory
();
}
@Test
public
void
errorPage404
()
throws
Exception
{
AbstractEmbeddedServletContainerFactory
factory
=
getFactory
();
factory
.
addErrorPages
(
new
ErrorPage
(
HttpStatus
.
NOT_FOUND
,
"/hello"
));
this
.
container
=
factory
.
getEmbeddedServletContainer
(
new
ServletRegistrationBean
(
new
ExampleServlet
(),
"/hello"
));
this
.
container
.
start
();
assertThat
(
getResponse
(
"http://localhost:8080/hello"
),
equalTo
(
"Hello World"
));
assertThat
(
getResponse
(
"http://localhost:8080/not-found"
),
equalTo
(
"Hello World"
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment