Run some tests against Tomcat 7.x. Mainly to test Servlet 3.0.1 compatibility. See s-c-netflix issue #1447
This commit is contained in:
1
pom.xml
1
pom.xml
@@ -52,6 +52,7 @@
|
||||
<module>zuul-config-discovery</module>
|
||||
<module>zuul-proxy</module>
|
||||
<module>zuul-proxy-eureka</module>
|
||||
<module>tomcat-7.x</module>
|
||||
</modules>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
131
tomcat-7.x/pom.xml
Normal file
131
tomcat-7.x/pom.xml
Normal file
@@ -0,0 +1,131 @@
|
||||
<?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>
|
||||
|
||||
<groupId>org.springframework.cloud.sample</groupId>
|
||||
<artifactId>spring-cloud-sample-tomcat-7.x</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.4.1.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<start-class>demo.TomcatApp</start-class>
|
||||
<java.version>1.7</java.version>
|
||||
<spring-cloud.version>Camden.BUILD-SNAPSHOT</spring-cloud.version>
|
||||
<tomcat.version>7.0.59</tomcat.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zuul</artifactId>
|
||||
</dependency>
|
||||
<!-- Needed to force Boot to use Tomcat 7 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat</groupId>
|
||||
<artifactId>tomcat-juli</artifactId>
|
||||
<version>${tomcat.version}</version>
|
||||
</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>
|
||||
<!--skip deploy (this is just a test module) -->
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/libs-snapshot-local</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/release</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>spring-snapshots</id>
|
||||
<name>Spring Snapshots</name>
|
||||
<url>https://repo.spring.io/libs-snapshot-local</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-milestones</id>
|
||||
<name>Spring Milestones</name>
|
||||
<url>https://repo.spring.io/libs-milestone-local</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
<pluginRepository>
|
||||
<id>spring-releases</id>
|
||||
<name>Spring Releases</name>
|
||||
<url>https://repo.spring.io/release</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
|
||||
</project>
|
||||
48
tomcat-7.x/src/main/java/demo/TomcatApp.java
Normal file
48
tomcat-7.x/src/main/java/demo/TomcatApp.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package demo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.netflix.ribbon.RibbonClient;
|
||||
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.netflix.loadbalancer.BaseLoadBalancer;
|
||||
import com.netflix.loadbalancer.ILoadBalancer;
|
||||
import com.netflix.loadbalancer.Server;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableZuulProxy
|
||||
@RestController
|
||||
@RibbonClient(name = "self", configuration = TomcatApp.SelfRibbonClientConfiguration.class)
|
||||
public class TomcatApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TomcatApp.class, args);
|
||||
}
|
||||
|
||||
@RequestMapping("/good")
|
||||
public String good(@RequestParam(required = false) String value) {
|
||||
return "GOOD" + (value == null ? "" : " " + value) + "!";
|
||||
}
|
||||
|
||||
// Load balancer with fixed server list for "hello" pointing to example.com
|
||||
@Configuration
|
||||
class SelfRibbonClientConfiguration {
|
||||
|
||||
@Bean
|
||||
public ILoadBalancer ribbonLoadBalancer() {
|
||||
//because of this, it doesn't use eureka to lookup the server,
|
||||
// but the classpath is tested
|
||||
BaseLoadBalancer balancer = new BaseLoadBalancer();
|
||||
balancer.setServersList(Arrays.asList(new Server("localhost", 1234)));
|
||||
return balancer;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
15
tomcat-7.x/src/main/resources/application.yml
Normal file
15
tomcat-7.x/src/main/resources/application.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
zuul:
|
||||
routes:
|
||||
self:
|
||||
path: /self/**
|
||||
example:
|
||||
path: /goodurl/**
|
||||
url: http://localhost:1234/good
|
||||
set-content-length: true
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: zuul-app
|
||||
server:
|
||||
port: 1234
|
||||
|
||||
37
tomcat-7.x/src/test/java/demo/TomcatAppTests.java
Normal file
37
tomcat-7.x/src/test/java/demo/TomcatAppTests.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package demo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
@RunWith(SpringRunner.class)
|
||||
public class TomcatAppTests {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
|
||||
@Test
|
||||
public void ribbonTest() throws Exception {
|
||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("/self/good", String.class);
|
||||
assertThat(responseEntity.getBody(), is("GOOD!"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendResponseTest() throws Exception {
|
||||
ResponseEntity<String> responseEntity = restTemplate.getForEntity("/goodurl", String.class);
|
||||
assertThat(responseEntity.getBody(), is("GOOD!"));
|
||||
assertThat(responseEntity.getHeaders().get("Content-Length").get(0), is("5"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user