diff --git a/spring-boot-samples/pom.xml b/spring-boot-samples/pom.xml index 54d0c854f3d..b206944b9fa 100644 --- a/spring-boot-samples/pom.xml +++ b/spring-boot-samples/pom.xml @@ -87,6 +87,7 @@ spring-boot-sample-undertow spring-boot-sample-undertow-ssl spring-boot-sample-velocity + spring-boot-sample-war spring-boot-sample-web-freemarker spring-boot-sample-web-groovy-templates spring-boot-sample-web-method-security diff --git a/spring-boot-samples/spring-boot-sample-war/pom.xml b/spring-boot-samples/spring-boot-sample-war/pom.xml new file mode 100644 index 00000000000..959bf51486e --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-war/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.2.7.BUILD-SNAPSHOT + + spring-boot-sample-war + war + Spring Boot War Sample + Spring Boot War Sample + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + / + + + + + org.springframework.boot + spring-boot-starter + + + javax.servlet + javax.servlet-api + provided + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + tomcat + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + + + jetty + + + org.springframework.boot + spring-boot-starter-jetty + provided + + + + + undertow + + + org.springframework.boot + spring-boot-starter-undertow + provided + + + + + diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java b/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java new file mode 100644 index 00000000000..fc4732ca35b --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/MyController.java @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2015 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.war; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MyController { + + @RequestMapping("/") + public String hello() { + return "Hello World!"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java b/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java new file mode 100644 index 00000000000..6336f74d455 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-war/src/main/java/sample/war/SampleWarApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright 2012-2015 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.war; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +/** + * Sample WAR application + */ +@SpringBootApplication +public class SampleWarApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(SampleWarApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-war/src/main/webapp/webapp.txt b/spring-boot-samples/spring-boot-sample-war/src/main/webapp/webapp.txt new file mode 100644 index 00000000000..8df12e9d878 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-war/src/main/webapp/webapp.txt @@ -0,0 +1 @@ +Hello WebApp diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java index 67c9be044bc..ce01efc5c3a 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactory.java @@ -95,6 +95,10 @@ public abstract class AbstractEmbeddedServletContainerFactory return null; } + private File getWarFileDocumentRoot() { + return getArchiveFileDocumentRoot(".war"); + } + private File getArchiveFileDocumentRoot(String extension) { File file = getCodeSourceArchive(); if (this.logger.isDebugEnabled()) { @@ -107,10 +111,6 @@ public abstract class AbstractEmbeddedServletContainerFactory return null; } - private File getWarFileDocumentRoot() { - return getArchiveFileDocumentRoot(".war"); - } - private File getCommonDocumentRoot() { for (String commonDocRoot : COMMON_DOC_ROOTS) { File root = new File(commonDocRoot); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java index 53eca72cd6f..a77ce77ff07 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java @@ -64,7 +64,6 @@ import io.undertow.server.HttpHandler; import io.undertow.server.handlers.accesslog.AccessLogHandler; import io.undertow.server.handlers.accesslog.AccessLogReceiver; import io.undertow.server.handlers.accesslog.DefaultAccessLogReceiver; -import io.undertow.server.handlers.resource.ClassPathResourceManager; import io.undertow.server.handlers.resource.FileResourceManager; import io.undertow.server.handlers.resource.Resource; import io.undertow.server.handlers.resource.ResourceChangeListener; @@ -372,10 +371,12 @@ public class UndertowEmbeddedServletContainerFactory private void configureAccessLog(DeploymentInfo deploymentInfo) { deploymentInfo.addInitialHandlerChainWrapper(new HandlerWrapper() { + @Override public HttpHandler wrap(HttpHandler handler) { return createAccessLogHandler(handler); } + }); } @@ -433,10 +434,7 @@ public class UndertowEmbeddedServletContainerFactory if (root != null && root.isFile()) { return new JarResourcemanager(root); } - if (this.resourceLoader != null) { - return new ClassPathResourceManager(this.resourceLoader.getClassLoader(), ""); - } - return new ClassPathResourceManager(getClass().getClassLoader(), ""); + return ResourceManager.EMPTY_RESOURCE_MANAGER; } private void configureErrorPages(DeploymentInfo servletBuilder) { diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java index f6b2934cf73..12274fb3dce 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java @@ -513,6 +513,17 @@ public abstract class AbstractEmbeddedServletContainerFactoryTests { assertThat(getJspServlet(), is(nullValue())); } + @Test + public void cannotReadClassPathFiles() throws Exception { + AbstractEmbeddedServletContainerFactory factory = getFactory(); + this.container = factory + .getEmbeddedServletContainer(exampleServletRegistration()); + this.container.start(); + ClientHttpResponse response = getClientResponse( + getLocalUrl("/org/springframework/boot/SpringApplication.class")); + assertThat(response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND)); + } + private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore) { return getSsl(clientAuth, keyPassword, keyStore, null); }