5 changed files with 753 additions and 753 deletions
@ -1,41 +1,41 @@
@@ -1,41 +1,41 @@
|
||||
<?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-core</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>io.undertow</groupId> |
||||
<artifactId>undertow-servlet</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.jboss.spec.javax.servlet</groupId> |
||||
<artifactId>jboss-servlet-api_3.1_spec</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>javax.servlet</groupId> |
||||
<artifactId>javax.servlet-api</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
<?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-core</artifactId> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>io.undertow</groupId> |
||||
<artifactId>undertow-servlet</artifactId> |
||||
<exclusions> |
||||
<exclusion> |
||||
<groupId>org.jboss.spec.javax.servlet</groupId> |
||||
<artifactId>jboss-servlet-api_3.1_spec</artifactId> |
||||
</exclusion> |
||||
</exclusions> |
||||
</dependency> |
||||
<dependency> |
||||
<groupId>javax.servlet</groupId> |
||||
<artifactId>javax.servlet-api</artifactId> |
||||
</dependency> |
||||
</dependencies> |
||||
</project> |
||||
|
||||
@ -1,3 +1,3 @@
@@ -1,3 +1,3 @@
|
||||
Manifest-Version: 1.0 |
||||
Class-Path: |
||||
|
||||
Manifest-Version: 1.0 |
||||
Class-Path: |
||||
|
||||
|
||||
@ -1,107 +1,107 @@
@@ -1,107 +1,107 @@
|
||||
/* |
||||
* 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 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; |
||||
|
||||
/** |
||||
* {@link EmbeddedServletContainer} that can be used to control an embedded Undertow |
||||
* server. Typically this class should be created using |
||||
* {@link UndertowEmbeddedServletContainerFactory} and not directly. |
||||
* |
||||
* @author Ivan Sopov |
||||
* @author Andy Wilkinson |
||||
* @since 1.2.0 |
||||
* @see UndertowEmbeddedServletContainer |
||||
*/ |
||||
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 (this.undertow == null) { |
||||
try { |
||||
HttpHandler servletHandler = this.manager.start(); |
||||
if (StringUtils.isEmpty(this.contextPath)) { |
||||
this.builder.setHandler(servletHandler); |
||||
} |
||||
else { |
||||
PathHandler pathHandler = Handlers.path().addPrefixPath( |
||||
this.contextPath, servletHandler); |
||||
this.builder.setHandler(pathHandler); |
||||
} |
||||
this.undertow = this.builder.build(); |
||||
} |
||||
catch (ServletException ex) { |
||||
throw new EmbeddedServletContainerException( |
||||
"Unable to start embdedded Undertow", ex); |
||||
} |
||||
} |
||||
this.undertow.start(); |
||||
this.started = true; |
||||
} |
||||
|
||||
@Override |
||||
public synchronized void stop() throws EmbeddedServletContainerException { |
||||
if (this.started) { |
||||
this.started = false; |
||||
this.undertow.stop(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getPort() { |
||||
return this.port; |
||||
} |
||||
|
||||
/* |
||||
* 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 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; |
||||
|
||||
/** |
||||
* {@link EmbeddedServletContainer} that can be used to control an embedded Undertow |
||||
* server. Typically this class should be created using |
||||
* {@link UndertowEmbeddedServletContainerFactory} and not directly. |
||||
* |
||||
* @author Ivan Sopov |
||||
* @author Andy Wilkinson |
||||
* @since 1.2.0 |
||||
* @see UndertowEmbeddedServletContainer |
||||
*/ |
||||
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 (this.undertow == null) { |
||||
try { |
||||
HttpHandler servletHandler = this.manager.start(); |
||||
if (StringUtils.isEmpty(this.contextPath)) { |
||||
this.builder.setHandler(servletHandler); |
||||
} |
||||
else { |
||||
PathHandler pathHandler = Handlers.path().addPrefixPath( |
||||
this.contextPath, servletHandler); |
||||
this.builder.setHandler(pathHandler); |
||||
} |
||||
this.undertow = this.builder.build(); |
||||
} |
||||
catch (ServletException ex) { |
||||
throw new EmbeddedServletContainerException( |
||||
"Unable to start embdedded Undertow", ex); |
||||
} |
||||
} |
||||
this.undertow.start(); |
||||
this.started = true; |
||||
} |
||||
|
||||
@Override |
||||
public synchronized void stop() throws EmbeddedServletContainerException { |
||||
if (this.started) { |
||||
this.started = false; |
||||
this.undertow.stop(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public int getPort() { |
||||
return this.port; |
||||
} |
||||
|
||||
} |
||||
File diff suppressed because it is too large
Load Diff
@ -1,96 +1,96 @@
@@ -1,96 +1,96 @@
|
||||
/* |
||||
* 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 org.springframework.boot.context.embedded.undertow; |
||||
|
||||
import io.undertow.Undertow.Builder; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
import org.junit.Test; |
||||
import org.mockito.InOrder; |
||||
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; |
||||
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests; |
||||
import org.springframework.boot.context.embedded.ErrorPage; |
||||
import org.springframework.boot.context.embedded.ExampleServlet; |
||||
import org.springframework.boot.context.embedded.ServletRegistrationBean; |
||||
import org.springframework.http.HttpStatus; |
||||
|
||||
import static org.hamcrest.Matchers.equalTo; |
||||
import static org.junit.Assert.assertThat; |
||||
import static org.mockito.Matchers.anyObject; |
||||
import static org.mockito.Mockito.inOrder; |
||||
import static org.mockito.Mockito.mock; |
||||
|
||||
/** |
||||
* Tests for {@link UndertowEmbeddedServletContainerFactory} and |
||||
* {@link UndertowEmbeddedServletContainer} . |
||||
* |
||||
* @author Ivan Sopov |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public class UndertowEmbeddedServletContainerFactoryTests extends |
||||
AbstractEmbeddedServletContainerFactoryTests { |
||||
|
||||
@Override |
||||
protected UndertowEmbeddedServletContainerFactory getFactory() { |
||||
return new UndertowEmbeddedServletContainerFactory(0); |
||||
} |
||||
|
||||
@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(getLocalUrl("/hello")), equalTo("Hello World")); |
||||
assertThat(getResponse(getLocalUrl("/not-found")), equalTo("Hello World")); |
||||
} |
||||
|
||||
@Test |
||||
public void setNullUndertowBuilderCustomizersThrows() { |
||||
UndertowEmbeddedServletContainerFactory factory = getFactory(); |
||||
this.thrown.expect(IllegalArgumentException.class); |
||||
this.thrown.expectMessage("undertowBuilderCustomizers must not be null"); |
||||
factory.setUndertowBuilderCustomizers(null); |
||||
} |
||||
|
||||
@Test |
||||
public void addNullContextCustomizersThrows() { |
||||
UndertowEmbeddedServletContainerFactory factory = getFactory(); |
||||
this.thrown.expect(IllegalArgumentException.class); |
||||
this.thrown.expectMessage("undertowBuilderCustomizers must not be null"); |
||||
factory.addUndertowBuilderCustomizers((UndertowBuilderCustomizer[]) null); |
||||
} |
||||
|
||||
@Test |
||||
public void builderCustomizers() throws Exception { |
||||
UndertowEmbeddedServletContainerFactory factory = getFactory(); |
||||
UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4]; |
||||
for (int i = 0; i < customizers.length; i++) { |
||||
customizers[i] = mock(UndertowBuilderCustomizer.class); |
||||
} |
||||
factory.setUndertowBuilderCustomizers(Arrays.asList(customizers[0], |
||||
customizers[1])); |
||||
factory.addUndertowBuilderCustomizers(customizers[2], customizers[3]); |
||||
this.container = factory.getEmbeddedServletContainer(); |
||||
InOrder ordered = inOrder((Object[]) customizers); |
||||
for (UndertowBuilderCustomizer customizer : customizers) { |
||||
ordered.verify(customizer).customize((Builder) anyObject()); |
||||
} |
||||
} |
||||
} |
||||
/* |
||||
* 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 org.springframework.boot.context.embedded.undertow; |
||||
|
||||
import io.undertow.Undertow.Builder; |
||||
|
||||
import java.util.Arrays; |
||||
|
||||
import org.junit.Test; |
||||
import org.mockito.InOrder; |
||||
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactory; |
||||
import org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests; |
||||
import org.springframework.boot.context.embedded.ErrorPage; |
||||
import org.springframework.boot.context.embedded.ExampleServlet; |
||||
import org.springframework.boot.context.embedded.ServletRegistrationBean; |
||||
import org.springframework.http.HttpStatus; |
||||
|
||||
import static org.hamcrest.Matchers.equalTo; |
||||
import static org.junit.Assert.assertThat; |
||||
import static org.mockito.Matchers.anyObject; |
||||
import static org.mockito.Mockito.inOrder; |
||||
import static org.mockito.Mockito.mock; |
||||
|
||||
/** |
||||
* Tests for {@link UndertowEmbeddedServletContainerFactory} and |
||||
* {@link UndertowEmbeddedServletContainer} . |
||||
* |
||||
* @author Ivan Sopov |
||||
* @author Andy Wilkinson |
||||
*/ |
||||
public class UndertowEmbeddedServletContainerFactoryTests extends |
||||
AbstractEmbeddedServletContainerFactoryTests { |
||||
|
||||
@Override |
||||
protected UndertowEmbeddedServletContainerFactory getFactory() { |
||||
return new UndertowEmbeddedServletContainerFactory(0); |
||||
} |
||||
|
||||
@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(getLocalUrl("/hello")), equalTo("Hello World")); |
||||
assertThat(getResponse(getLocalUrl("/not-found")), equalTo("Hello World")); |
||||
} |
||||
|
||||
@Test |
||||
public void setNullUndertowBuilderCustomizersThrows() { |
||||
UndertowEmbeddedServletContainerFactory factory = getFactory(); |
||||
this.thrown.expect(IllegalArgumentException.class); |
||||
this.thrown.expectMessage("undertowBuilderCustomizers must not be null"); |
||||
factory.setUndertowBuilderCustomizers(null); |
||||
} |
||||
|
||||
@Test |
||||
public void addNullContextCustomizersThrows() { |
||||
UndertowEmbeddedServletContainerFactory factory = getFactory(); |
||||
this.thrown.expect(IllegalArgumentException.class); |
||||
this.thrown.expectMessage("undertowBuilderCustomizers must not be null"); |
||||
factory.addUndertowBuilderCustomizers((UndertowBuilderCustomizer[]) null); |
||||
} |
||||
|
||||
@Test |
||||
public void builderCustomizers() throws Exception { |
||||
UndertowEmbeddedServletContainerFactory factory = getFactory(); |
||||
UndertowBuilderCustomizer[] customizers = new UndertowBuilderCustomizer[4]; |
||||
for (int i = 0; i < customizers.length; i++) { |
||||
customizers[i] = mock(UndertowBuilderCustomizer.class); |
||||
} |
||||
factory.setUndertowBuilderCustomizers(Arrays.asList(customizers[0], |
||||
customizers[1])); |
||||
factory.addUndertowBuilderCustomizers(customizers[2], customizers[3]); |
||||
this.container = factory.getEmbeddedServletContainer(); |
||||
InOrder ordered = inOrder((Object[]) customizers); |
||||
for (UndertowBuilderCustomizer customizer : customizers) { |
||||
ordered.verify(customizer).customize((Builder) anyObject()); |
||||
} |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue