diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/.gitignore b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/.gitignore new file mode 100644 index 000000000000..b83d22266ac8 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/pom.xml b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/pom.xml new file mode 100644 index 000000000000..6d510cfe409b --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + + org.springframework.boot + spring-boot-samples + 1.2.1.BUILD-SNAPSHOT + + spring-boot-sample-tomcat7-jsp-jar + jar + Spring Boot Tomcat 7 JSP Sample (JAR) + Spring Boot Tomcat 7 JSP Sample (JAR) + http://projects.spring.io/spring-boot/ + + Pivotal Software, Inc. + http://www.spring.io + + + ${basedir}/../.. + / + 7.0.56 + 3.0.1 + 1.7 + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.apache.tomcat.embed + tomcat-embed-jasper + provided + + + javax.servlet + jstl + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + + + diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/java/sample/jsp/SampleTomcat7JspApplication.java b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/java/sample/jsp/SampleTomcat7JspApplication.java new file mode 100644 index 000000000000..e51a0d067504 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/java/sample/jsp/SampleTomcat7JspApplication.java @@ -0,0 +1,36 @@ +/* + * 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.jsp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class SampleTomcat7JspApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(SampleTomcat7JspApplication.class); + } + + public static void main(String[] args) throws Exception { + SpringApplication.run(SampleTomcat7JspApplication.class, args); + } + +} diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/java/sample/jsp/WelcomeController.java b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/java/sample/jsp/WelcomeController.java new file mode 100644 index 000000000000..03d439caa3ca --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/java/sample/jsp/WelcomeController.java @@ -0,0 +1,39 @@ +/* + * 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.jsp; + +import java.util.Date; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +public class WelcomeController { + + @Value("${application.message:Hello World}") + private String message = "Hello World"; + + @RequestMapping("/") + public String welcome(Map model) { + model.put("time", new Date()); + model.put("message", this.message); + return "welcome"; + } + +} diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/META-INF/resources/jsp/helloworld.jsp b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/META-INF/resources/jsp/helloworld.jsp new file mode 100644 index 000000000000..ea216b1491bd --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/META-INF/resources/jsp/helloworld.jsp @@ -0,0 +1,14 @@ + + + + + + + + Testing JSP + <%="Hello World at " + System.currentTimeMillis() + + " milli seconds "%> + + + \ No newline at end of file diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/META-INF/resources/jsp/welcome.jsp b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/META-INF/resources/jsp/welcome.jsp new file mode 100644 index 000000000000..1d07b9a85b08 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/META-INF/resources/jsp/welcome.jsp @@ -0,0 +1,10 @@ + + + + + + + <%="Hello World"%> + + + diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/application.properties b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/application.properties new file mode 100644 index 000000000000..fe3a30bbfac8 --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/main/resources/application.properties @@ -0,0 +1,3 @@ +spring.view.prefix: /jsp/ +spring.view.suffix: .jsp +application.message: Hello Phil diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/test/java/sample/jsp/SampleWebJspApplicationTests.java new file mode 100644 index 000000000000..32fe704433ed --- /dev/null +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp-jar/src/test/java/sample/jsp/SampleWebJspApplicationTests.java @@ -0,0 +1,60 @@ +/* + * 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.jsp; + +import org.junit.Test; +import org.junit.Ignore; +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; +import static org.junit.Assert.assertTrue; + +/** + * Basic integration tests for JSP application. + * + * @author Phillip Webb + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = SampleTomcat7JspApplication.class) +@WebAppConfiguration +@IntegrationTest("server.port:0") +@DirtiesContext +public class SampleWebJspApplicationTests { + + @Value("${local.server.port}") + private int port; + + @Test + @Ignore + public void testJspWithEl() throws Exception { + ResponseEntity entity = new TestRestTemplate().getForEntity( + "http://localhost:" + this.port, String.class); + assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertTrue("Wrong body:\n" + entity.getBody(), + entity.getBody().contains("/resources/text.txt")); + } + +}