Skip to content

Commit

Permalink
Add Tomcat 7 and Jetty 8 samples
Browse files Browse the repository at this point in the history
Switch the Tomcat 8 and Jetty 9 samples to Tomcat 7 and Jetty 8. Since
Tomcat 8 and Jetty 9 are now the default versions the previous samples
are no longer relevant, however, we do need integration tests to check
that we remain compatible with Tomcat 7 and Jetty 8.

See spring-projectsgh-1832
  • Loading branch information
philwebb committed Nov 6, 2014
1 parent b6bacd5 commit 9d4ada7
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 18 deletions.
5 changes: 3 additions & 2 deletions spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<module>spring-boot-sample-jersey</module>
<module>spring-boot-sample-jersey1</module>
<module>spring-boot-sample-jetty</module>
<module>spring-boot-sample-jetty9</module>
<module>spring-boot-sample-jetty8</module>
<module>spring-boot-sample-jta-atomikos</module>
<module>spring-boot-sample-jta-bitronix</module>
<module>spring-boot-sample-jta-jndi</module>
Expand All @@ -51,10 +51,11 @@
<module>spring-boot-sample-secure</module>
<module>spring-boot-sample-servlet</module>
<module>spring-boot-sample-simple</module>
<module>spring-boot-sample-tomcat-jsp</module>
<module>spring-boot-sample-tomcat-ssl</module>
<module>spring-boot-sample-tomcat</module>
<module>spring-boot-sample-tomcat-multi-connectors</module>
<module>spring-boot-sample-tomcat8-jsp</module>
<module>spring-boot-sample-tomcat7-jsp</module>
<module>spring-boot-sample-traditional</module>
<module>spring-boot-sample-velocity</module>
<module>spring-boot-sample-web-freemarker</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@
<artifactId>spring-boot-samples</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-jetty9</artifactId>
<name>Spring Boot Jetty Sample</name>
<description>Spring Boot Jetty 9 Sample</description>
<artifactId>spring-boot-sample-jetty8</artifactId>
<name>Spring Boot Jetty 8 Sample</name>
<description>Spring Boot Jetty 8 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>
<jetty.version>9.2.3.v20140905</jetty.version>
<servlet-api.version>3.1.0</servlet-api.version>
<jetty.version>8.1.15.v20140411</jetty.version>
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
<servlet-api.version>3.0.1</servlet-api.version>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SampleJetty9Application {
public class SampleJetty8Application {

public static void main(String[] args) throws Exception {
SpringApplication.run(SampleJetty9Application.class, args);
SpringApplication.run(SampleJetty8Application.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleJetty9Application.class)
@SpringApplicationConfiguration(classes = SampleJetty8Application.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@DirtiesContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<artifactId>spring-boot-samples</artifactId>
<version>1.2.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-tomcat8-jsp</artifactId>
<artifactId>spring-boot-sample-tomcat-jsp</artifactId>
<packaging>war</packaging>
<name>Spring Boot Tomcat 8 JSP Sample</name>
<description>Spring Boot Tomcat 8 JSP Sample</description>
<name>Spring Boot Tomcat JSP Sample</name>
<description>Spring Boot Tomcat JSP Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
Expand All @@ -19,7 +19,8 @@
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
<tomcat.version>8.0.8</tomcat.version>
<tomcat.version>7.0.56</tomcat.version>
<servlet-api.version>3.0.1</servlet-api.version>
<java.version>1.7</java.version>
</properties>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SampleTomcatJspApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SampleTomcatJspApplication.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(SampleTomcatJspApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.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 = SampleTomcatJspApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@DirtiesContext
public class SampleWebJspApplicationTests {

@Value("${local.server.port}")
private int port;

@Test
public void testJspWithEl() throws Exception {
ResponseEntity<String> 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"));
}

}
66 changes: 66 additions & 0 deletions spring-boot-samples/spring-boot-sample-tomcat7-jsp/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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-tomcat7-jsp</artifactId>
<packaging>war</packaging>
<name>Spring Boot Tomcat 7 JSP Sample</name>
<description>Spring Boot Tomcat 7 JSP 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>
<m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>
<tomcat.version>7.0.56</tomcat.version>
<servlet-api.version>3.0.1</servlet-api.version>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class SampleTomcat8JspApplication extends SpringBootServletInitializer {
public class SampleTomcat7JspApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SampleTomcat8JspApplication.class);
return application.sources(SampleTomcat7JspApplication.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(SampleTomcat8JspApplication.class, args);
SpringApplication.run(SampleTomcat7JspApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -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<String, Object> model) {
model.put("time", new Date());
model.put("message", this.message);
return "welcome";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring.view.prefix: /WEB-INF/jsp/
spring.view.suffix: .jsp
application.message: Hello Phil
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html lang="en">

<body>
<c:url value="/resources/text.txt" var="url"/>
<spring:url value="/resources/text.txt" htmlEscape="true" var="springUrl" />
Spring URL: ${springUrl} at ${time}
<br>
JSTL URL: ${url}
<br>
Message: ${message}
</body>

</html>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* @author Phillip Webb
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleTomcat8JspApplication.class)
@SpringApplicationConfiguration(classes = SampleTomcat7JspApplication.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
@DirtiesContext
Expand Down

0 comments on commit 9d4ada7

Please sign in to comment.