Updates tests for boot 2.3 and ilford (2020.0)

This commit is contained in:
spencergibb
2020-05-29 19:21:13 -04:00
parent eb28d61378
commit 859f8d988c
74 changed files with 62 additions and 2564 deletions

View File

@@ -63,6 +63,21 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-apache-client4</artifactId>
<version>1.19.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -4,3 +4,5 @@ spring:
server:
port: 7788
debug: true

View File

@@ -61,6 +61,10 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -1,24 +1,21 @@
package demo;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.loadbalancer.BaseLoadBalancer;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
/**
* @author Spencer Gibb
@@ -27,7 +24,7 @@ import com.netflix.loadbalancer.Server;
@EnableDiscoveryClient
@RestController
@EnableFeignClients
@RibbonClient(name = "hello", configuration = HelloRibbonClientConfiguration.class)
@LoadBalancerClient(name = "hello", configuration = HelloClientApplication.HelloClientConfiguration.class)
public class HelloClientApplication {
@Autowired
HelloClient client;
@@ -37,28 +34,34 @@ public class HelloClientApplication {
return client.hello();
}
@RequestMapping("/world")
public String world() {
return "hello world";
}
public static void main(String[] args) {
SpringApplication.run(HelloClientApplication.class, args);
}
@FeignClient("hello")
interface HelloClient {
@RequestMapping(value = "/", method = GET)
@RequestMapping(value = "/world", method = GET)
String hello();
}
}
// Load balancer with fixed server list for "hello" pointing to example.com
static class HelloClientConfiguration {
// Load balancer with fixed server list for "hello" pointing to example.com
@Configuration
class HelloRibbonClientConfiguration {
@Bean
@Lazy
public ServiceInstanceListSupplier myServiceInstanceListSupplier(Environment env) {
//because of this, it doesn't use eureka to lookup the server,
// but the classpath is tested
Integer port = env.getProperty("local.server.port", Integer.class);
return ServiceInstanceListSupplier.fixed(env)
.instance("localhost", port, "hello").build();
}
@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("example.com", 443)));
return balancer;
}
}

View File

@@ -1,20 +1,21 @@
package demo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
// We disable Hystrix because we are not concerned about testing circuit breakers in this
// test and it eliminates hystrix timeouts from messing with the request
@RunWith(SpringRunner.class)
@@ -22,7 +23,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@DirtiesContext
public class HelloClientApplicationTests {
@Value("${local.server.port}")
@LocalServerPort
int port;
@Test
@@ -31,7 +32,7 @@ public class HelloClientApplicationTests {
.getForEntity("http://localhost:" + port, String.class);
assertNotNull("response was null", response);
assertEquals("Wrong status code", HttpStatus.OK, response.getStatusCode());
assertTrue(response.getBody().contains("<html"));
assertThat(response.getBody()).isEqualTo("hello world");
}
}

View File

@@ -1,2 +0,0 @@
This project is a sample of a client application with Feign
that doesn't use Eureka but does use Hystrix.

View File

@@ -1,117 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-feign-hystrix</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-feign-hystrix</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -1,46 +0,0 @@
package demo;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@SpringBootApplication
@EnableFeignClients
public class FeignClientApplication {
@Bean
public ApplicationRunner runner(final UrlRestClient client) {
return new ApplicationRunner() {
@Override
public void run(ApplicationArguments args) throws Exception {
System.err.println(client.hello());
}
};
}
public static void main(String[] args) {
SpringApplication.run(FeignClientApplication.class, args);
}
}
@FeignClient(name = "example", url = "https://example.com", fallback=FallbackClient.class)
interface UrlRestClient {
@RequestMapping(value="/", method = RequestMethod.GET)
String hello();
}
@Component
class FallbackClient implements UrlRestClient {
@Override
public String hello() {
return "oops";
}
}

View File

@@ -1,35 +0,0 @@
/*
* 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
*
* https://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 demo;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
/**
* A test suite for probing weird ordering problems in the tests.
*
* @author Dave Syer
*/
@RunWith(Suite.class)
@SuiteClasses({ FeignClientApplicationTests.class,
FeignClientWithServerListApplicationTests.class })
@Ignore("Test suite for tracking order dependencies")
public class AdhocTestSuite {
}

View File

@@ -1,54 +0,0 @@
package demo;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import demo.FeignClientWithServerListApplicationTests.FallbackRestClient;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class FeignClientApplicationTests {
@Autowired
private UrlRestClient client;
@Configuration
@EnableAutoConfiguration
@EnableFeignClients
protected static class TestApplication {
@Bean
public FallbackClient fallback() {
return new FallbackClient();
}
@Bean
public FallbackRestClient fallbackRestClient() {
return new FallbackRestClient();
}
public static void main(String[] args) {
SpringApplication.run(FeignClientApplication.class, args);
}
}
@Test
public void clientConnects() {
assertTrue(client.hello().contains("<html"));
}
}

View File

@@ -1,71 +0,0 @@
package demo;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
//Increase hystrix timeout or else requests timeout on CI server
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"myexample.ribbon.listOfServers:example.com:443",
"myexample.ribbon.IsSecure:true",
"hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000"})
@DirtiesContext
public class FeignClientWithServerListApplicationTests {
@Autowired
private ServiceRestClient client;
@Test
public void clientConnects() {
assertTrue(client.hello().contains("<html"));
}
@Configuration
@EnableAutoConfiguration
@EnableFeignClients
protected static class TestApplication {
@Bean
public FallbackRestClient fallbackRestClient() {
return new FallbackRestClient();
}
@Bean
public FallbackClient fallback() {
return new FallbackClient();
}
public static void main(String[] args) {
SpringApplication.run(FeignClientApplication.class, args);
}
}
@FeignClient(value = "myexample", fallback = FallbackRestClient.class)
public static interface ServiceRestClient {
@RequestMapping(value="/", method=RequestMethod.GET)
String hello();
}
static class FallbackRestClient implements ServiceRestClient {
@Override
public String hello() {
return "fallback";
}
}
}

View File

@@ -43,7 +43,7 @@
</dependency>
<!-- <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<artifactId>spring-cloud-starter-loadbalancer</artifactId>
</dependency> -->
<dependency>
<groupId>org.springframework.boot</groupId>

View File

@@ -2,6 +2,7 @@ package demo;
import static org.junit.Assert.assertTrue;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,6 +31,7 @@ public class FeignClientWithServerListApplicationTests {
@Autowired
private RestClient client;
@Ignore // need s-c-lb config by properties
@Test
public void clientConnects() {
assertTrue(client.hello().contains("<html"));

View File

@@ -1 +0,0 @@
This project is a sample of using just the hystrix starter

View File

@@ -1,5 +0,0 @@
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"

View File

@@ -1,121 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-hystrix-amqp</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-hystrix-amqp</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rabbit</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>
<!--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/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -1,37 +0,0 @@
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableCircuitBreaker
@RestController
public class HystrixApplication {
@Bean
public MyService myService() {
return new MyService();
}
@Autowired
private MyService myService;
@RequestMapping("/")
public String ok() {
return myService.ok();
}
@RequestMapping("/fail")
public String fail() {
return myService.fail();
}
public static void main(String[] args) {
SpringApplication.run(HystrixApplication.class, args);
}
}

View File

@@ -1,23 +0,0 @@
package demo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
/**
* @author Spencer Gibb
*/
public class MyService {
@HystrixCommand(fallbackMethod = "fallback")
public String ok() {
return "OK";
}
@HystrixCommand(fallbackMethod = "fallback")
public String fail() {
throw new RuntimeException("fail now");
}
public String fallback() {
return "from the fallback";
}
}

View File

@@ -1,4 +0,0 @@
# This way you get to see the exceptions when the fallback is accessed
logging.level.com.netflix.hystrix.AbstractCommand: DEBUG
logging.level.org.springframework.integration: DEBUG
management.endpoints.web.exposure.include: *

View File

@@ -1,60 +0,0 @@
package demo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.net.URL;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class HystrixApplicationTests {
@LocalServerPort
int port;
@Test
public void testOk() {
ResponseEntity<String> response = new TestRestTemplate().getForEntity("http://localhost:" + port, String.class);
assertNotNull("response was null", response);
assertEquals("Bad status code", HttpStatus.OK, response.getStatusCode());
assertEquals("Wrong response text", "OK", response.getBody());
}
@Test
public void testFallback() {
ResponseEntity<String> response = new TestRestTemplate().getForEntity("http://localhost:" + port+"/fail", String.class);
assertNotNull("response was null", response);
assertEquals("Bad status code", HttpStatus.OK, response.getStatusCode());
assertEquals("Wrong response text", "from the fallback", response.getBody());
}
@Test
public void hystrixStreamWorks() throws Exception {
String url = "http://localhost:" + port;
//you have to hit a Hystrix circuit breaker before the stream sends anything
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url, String.class);
assertEquals("bad response code", HttpStatus.OK, response.getStatusCode());
URL hystrixUrl = new URL(url + "/actuator/hystrix.stream");
InputStream in = hystrixUrl.openStream();
byte[] buffer = new byte[1024];
in.read(buffer);
String contents = new String(buffer);
assertTrue("Wrong content: \n" + contents, contents.contains("data") || contents.contains("ping"));
in.close();
}
}

View File

@@ -1,26 +0,0 @@
# About
This project is a sample of using just the Hystrix Starter. For more information see the
[Hystrix documentation](https://cloud.spring.io/spring-cloud-static/spring-cloud.html#_circuit_breaker_hystrix_clients).
# Usage
This simple app contains two endpoints both surrounded by Hystrix circuit breakers.
See [HystrixApplication.java](https://github.com/spring-cloud-samples/tests/blob/master/hystrix/src/main/java/demo/HystrixApplication.java) for
the endpoint definitions.
## /ok
The `/ok` endpoint just returns the String 'OK' and should actually never trip the circuit breaker since there is no
way for it to "fail".
## /fail
The `/fail` endpoint will throw a `RuntimeException` unless the header `X-NO-FAIL` is present. If you hit the
`/fail` endpoint fast enough, the circuit will open and Hystrix will return the response from the fallback method
defined in [MyService.java](https://github.com/spring-cloud-samples/tests/blob/master/hystrix/src/main/java/demo/MyService.java#L28).
Once the circuit is open you will see the `/fail` endpoint return the string `from the fallback`. The circuit will remain
open until a successful request is made to the fail endpoint. This is where the `X-NO-FAIL` header comes in handy. If
the header is present in the request made to `/fail`, the `RuntimeException` will not be thrown. If you do this enough
while the circuit is open than the circuit will eventually close.
## Using The Hystrix Dashboard
You can use the [Hystrix Dashboard](https://github.com/spring-cloud-samples/hystrix-dashboard) sample to visualize
the state of the circuit breakers in this application. To do this, follow the instructions in the README for the
Hystrix Dashboard sample to start the dashboard and then point it at `http://localhost:8080/hystrix.stream`.

View File

@@ -1,113 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-hystrix</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-hystrix</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</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>
<!--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/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -1,41 +0,0 @@
package demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableCircuitBreaker
@RestController
public class HystrixApplication {
@Bean
public MyService myService() {
return new MyService();
}
@Autowired
private MyService myService;
@RequestMapping("/")
public String ok() {
return this.myService.ok();
}
@RequestMapping("/fail")
public String fail(@RequestHeader(name = "X-No-Fail", required = false) String noFail) {
if (noFail != null) {
return this.myService.fail(false);
}
return this.myService.fail(true);
}
public static void main(String[] args) {
SpringApplication.run(HystrixApplication.class, args);
}
}

View File

@@ -1,31 +0,0 @@
package demo;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
/**
* @author Spencer Gibb
*/
public class MyService {
@HystrixCommand(fallbackMethod = "fallback")
public String ok() {
return "OK";
}
@HystrixCommand(fallbackMethod = "fallback")
public String fail(boolean throwSomething) {
if(throwSomething)
throw new RuntimeException("fail now");
else
return "";
}
public String fallback() {
return "from the fallback";
}
public String fallback(boolean throwSomething) {
return "from the fallback";
}
}

View File

@@ -1,3 +0,0 @@
# This way you get to see the exceptions when the fallback is accessed
logging.level.com.netflix.hystrix.AbstractCommand: DEBUG
management.endpoints.web.exposure.include: *

View File

@@ -1,60 +0,0 @@
package demo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.net.URL;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class HystrixApplicationTests {
@LocalServerPort
int port;
@Test
public void testOk() {
ResponseEntity<String> response = new TestRestTemplate().getForEntity("http://localhost:" + port, String.class);
assertNotNull("response was null", response);
assertEquals("Bad status code", HttpStatus.OK, response.getStatusCode());
assertEquals("Wrong response text", "OK", response.getBody());
}
@Test
public void testFallback() {
ResponseEntity<String> response = new TestRestTemplate().getForEntity("http://localhost:" + port+"/fail", String.class);
assertNotNull("response was null", response);
assertEquals("Bad status code", HttpStatus.OK, response.getStatusCode());
assertEquals("Wrong response text", "from the fallback", response.getBody());
}
@Test
public void hystrixStreamWorks() throws Exception {
String url = "http://localhost:" + port;
//you have to hit a Hystrix circuit breaker before the stream sends anything
ResponseEntity<String> response = new TestRestTemplate().getForEntity(url, String.class);
assertEquals("bad response code", HttpStatus.OK, response.getStatusCode());
URL hystrixUrl = new URL(url + "/actuator/hystrix.stream");
InputStream in = hystrixUrl.openStream();
byte[] buffer = new byte[1024];
in.read(buffer);
String contents = new String(buffer);
assertTrue("Wrong content: \n" + contents, contents.contains("data") || contents.contains("ping"));
in.close();
}
}

View File

@@ -1 +0,0 @@
This project is a sample of a client application with OAuth2 and Zuul

View File

@@ -1,109 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-oauth2-zuul</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-oauth2-zuul</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</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>
<!--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/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

View File

@@ -1,15 +0,0 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
// import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
@SpringBootApplication
// @EnableOAuth2Sso
// FIXME boot 2.0.0 spring-security 5.0 missing oauth
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
}

View File

@@ -1,6 +0,0 @@
security.oauth2.client.clientId: acme
security.oauth2.client.clientSecret: acmesecret
security.oauth2.client.accessTokenUri: https://example.com
security.oauth2.client.userAuthorizationUri: https://example.com
security.oauth2.resource.user-info-uri: https://example.com
# debug:

View File

@@ -1,33 +0,0 @@
package demo;
import static org.junit.Assert.assertEquals;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
public class ZuulApplicationTests {
private TestRestTemplate restTemplate = new TestRestTemplate();
@Value("${local.server.port}")
int port;
@Test
@Ignore
public void useRestTemplate() throws Exception {
ResponseEntity<String> entity = this.restTemplate.getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
assertEquals("http://localhost:" + this.port + "/login", entity.getHeaders().getLocation().toString());
}
}

19
pom.xml
View File

@@ -33,25 +33,16 @@
<module>feign</module>
<module>feign-eager-instantiation</module>
<module>feign-eureka</module>
<!-- <module>feign-hystrix</module>
<module>hystrix</module>
<module>hystrix-amqp</module>
<module>netflix-sidecar</module> -->
<!--<module>netflix-sidecar</module>-->
<module>noweb</module>
<!-- <module>oauth2-ribbon</module> -->
<!-- <module>oauth2-zuul</module> -->
<!-- <module>ribbon-default-config</module>
<module>ribbon-eureka</module> -->
<!-- TODO: replace ribbon with spring cloud loadbalancer -->
<!--<module>oauth2-ribbon</module>
<module>ribbon-default-config</module>
<module>ribbon-eureka</module>-->
<module>sleuth</module>
<module>stream-bus</module>
<!-- <module>turbine</module>
<module>turbine-amqp</module> -->
<module>vanilla</module>
<module>zipkin</module>
<!-- <module>zuul</module>
<module>zuul-config-discovery</module>
<module>zuul-proxy</module>
<module>zuul-proxy-eureka</module> -->
</modules>
<build>
<plugins>

View File

@@ -1,5 +0,0 @@
rabbitmq:
image: rabbitmq:management
ports:
- "5672:5672"
- "15672:15672"

View File

@@ -1,134 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-turbine-amqp</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-turbine-amqp</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
<!-- FIXME: why is this needed? -->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-handler</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>
<!--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>

View File

@@ -1,16 +0,0 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.turbine.stream.EnableTurbineStream;
@SpringBootApplication
@EnableDiscoveryClient
@EnableTurbineStream
public class TurbineStreamApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineStreamApplication.class, args);
}
}

View File

@@ -1,4 +0,0 @@
server.port: 8989
spring.application.name: turbine
turbine.appConfig: simple
turbine.aggregator.clusterConfig: SIMPLE

View File

@@ -1,42 +0,0 @@
package demo;
import static org.junit.Assert.assertTrue;
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.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.cloud.client.discovery.simple.SimpleDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class TurbineStreamApplicationTests {
@Autowired
DiscoveryClient discoveryClient;
@Test
public void contextLoads() {
}
@Test
public void discoveryClientIsEureka() {
assertTrue("discoveryClient is wrong type " + discoveryClient.getClass(), discoveryClient instanceof CompositeDiscoveryClient);
CompositeDiscoveryClient compositeDiscoveryClient = (CompositeDiscoveryClient)discoveryClient;
assertTrue("composite discovery client should be composed of Eureka and Simple Discovery client's"
, compositeDiscoveryClient.getDiscoveryClients().size() == 2);
assertTrue("the composed discovery client should have a EurekaDiscoveryClient with a higher precedence ",
compositeDiscoveryClient.getDiscoveryClients().get(0) instanceof EurekaDiscoveryClient);
assertTrue("the composed discovery client should have a SimpleDiscoveryClient with a lower precedence ",
compositeDiscoveryClient.getDiscoveryClients().get(1) instanceof SimpleDiscoveryClient);
}
}

View File

@@ -1,4 +0,0 @@
server.port: 8761
spring.application.name: eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

View File

@@ -1,2 +0,0 @@
server.port: 8080
spring.application.name: simple

View File

@@ -1,131 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-turbine</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-turbine</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
<scope>test</scope>
</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>

View File

@@ -1,14 +0,0 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
@SpringBootApplication
@EnableTurbine
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}

View File

@@ -1,11 +0,0 @@
server:
port: 8989
spring:
application:
name: turbine
turbine:
appConfig: simple,other
aggregator:
clusterConfig: MAIN
clusterNameExpression: metadata['cluster']
combineHostPort: true

View File

@@ -1,19 +0,0 @@
package apps;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(EurekaServerApplication.class).properties(
"spring.config.name:eureka", "logging.level.com.netflix.discovery:OFF")
.run(args);
}
}

View File

@@ -1,82 +0,0 @@
/*
* Copyright 2014-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
*
* https://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 apps;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
public class OtherApplication {
@Autowired
private HelloService service;
@RequestMapping("/")
public String hello() {
return this.service.hello();
}
@RequestMapping("/session")
public String session(HttpSession session) {
return session.getId();
}
@RequestMapping("/fail")
public String fail() {
return this.service.fail();
}
public static void main(String[] args) {
new SpringApplicationBuilder(OtherApplication.class).properties(
"spring.config.name:other").run(args);
}
@Service
public static class HelloService {
@HystrixCommand(fallbackMethod="fallback")
public String hello() {
return "Hello World";
}
@HystrixCommand(fallbackMethod="fallback")
public String fail() {
throw new RuntimeException("Planned");
}
public String fallback() {
return "Fallback";
}
}
}

View File

@@ -1,82 +0,0 @@
/*
* Copyright 2014-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
*
* https://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 apps;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
@Configuration
@EnableAutoConfiguration
@EnableDiscoveryClient
@EnableCircuitBreaker
@RestController
public class SimpleApplication {
@Autowired
private HelloService service;
@RequestMapping("/")
public String hello() {
return this.service.hello();
}
@RequestMapping("/session")
public String session(HttpSession session) {
return session.getId();
}
@RequestMapping("/fail")
public String fail() {
return this.service.fail();
}
public static void main(String[] args) {
new SpringApplicationBuilder(SimpleApplication.class).properties(
"spring.config.name:simple").run(args);
}
@Service
public static class HelloService {
@HystrixCommand(fallbackMethod="fallback")
public String hello() {
return "Hello World";
}
@HystrixCommand(fallbackMethod="fallback")
public String fail() {
throw new RuntimeException("Planned");
}
public String fallback() {
return "Fallback";
}
}
}

View File

@@ -1,31 +0,0 @@
package demo;
import static org.junit.Assert.assertTrue;
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.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class TurbineApplicationTests {
@Autowired
DiscoveryClient discoveryClient;
@Test
public void contextLoads() {
}
@Test
public void discoveryClientIsEureka() {
assertTrue("discoveryClient is wrong type", discoveryClient instanceof CompositeDiscoveryClient);
}
}

View File

@@ -1,4 +0,0 @@
server.port: 8761
spring.application.name: eureka
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false

View File

@@ -1,3 +0,0 @@
server.port: 8081
spring.application.name: other
eureka.instance.metadata-map.cluster: MAIN

View File

@@ -1,3 +0,0 @@
server.port: 8080
spring.application.name: simple
eureka.instance.metadata-map.cluster: MAIN

View File

@@ -1,3 +0,0 @@
Test with zuul server, eureka and config server. Config server is located by discovery.
Test that zuul server updates routes when new routes are added (at least doesn't fail with a stack overflow exception)

View File

@@ -1,123 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-zuul-config-discovery</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-zuul-config-discovery</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.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-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</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>
<!--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/libs-release-local</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>
</pluginRepositories>
</project>

View File

@@ -1,17 +0,0 @@
package demo;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy
public class ZuulConfigDiscoveryApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ZuulConfigDiscoveryApplication.class)
.web(WebApplicationType.SERVLET).run(args);
}
}

View File

@@ -1,29 +0,0 @@
info:
component: Zuul Server
endpoints:
restart:
enabled: true
shutdown:
enabled: true
sensitive: false
logging:
level:
org.springframework.security: DEBUG
org.springframework.web: DEBUG
org.springframework.boot: INFO
#com.netflix.discovery: 'OFF'
ROOT: INFO
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
statusPageUrlPath: /admin/info
healthCheckUrlPath: /admin/health
management:
port: ${MGMT_SERVER_PORT:8766}
server:
port: ${SERVER_PORT:8765}

View File

@@ -1,15 +0,0 @@
spring:
application:
name: zuulConfigDiscoveryTest
cloud:
config:
username: user
password: password
failFast: true
discovery:
enabled: true
eureka:
client:
serviceUrl:
defaultZone: https://user::password@localhost:8761/eureka/

View File

@@ -1,23 +0,0 @@
package demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class ZuulConfigDiscoveryApplicationTests {
@LocalServerPort
private int port;
@Test
public void contextLoads() {
}
}

View File

@@ -1,124 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-zuul-proxy-eureka</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-zuul-proxy-eureka</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</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>
<!--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>

View File

@@ -1,14 +0,0 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
@SpringBootApplication
@EnableZuulProxy
public class ZuulProxyEurekaApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulProxyEurekaApplication.class, args);
}
}

View File

@@ -1,3 +0,0 @@
debug: true
spring.application.name: zuulproxy
server.port: 9900

View File

@@ -1,34 +0,0 @@
package demo;
import static org.junit.Assert.assertTrue;
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.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@DirtiesContext
public class ZuulProxyEurekaApplicationTests {
@Autowired
DiscoveryClient discoveryClient;
@Test
public void contextLoads() {
}
@Test
public void discoveryClientIsEureka() {
assertTrue("discoveryClient is wrong type", discoveryClient instanceof CompositeDiscoveryClient);
assertTrue("composite discovery client should compose Eureka Discovery Client with highest precedence",
((CompositeDiscoveryClient)discoveryClient).getDiscoveryClients().get(0) instanceof EurekaDiscoveryClient);
}
}

View File

@@ -1,120 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-zuul-proxy</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-zuul-proxy</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</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>
<!--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>

View File

@@ -1,28 +0,0 @@
package demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@EnableZuulProxy
@RestController
public class ZuulProxyApplication {
@RequestMapping("/good")
public String good(@RequestParam(required = false) String value) {
return "GOOD" + (value == null ? "" : " " + value) + "!";
}
@RequestMapping("/good/stuff")
public String stuff() {
return "STUFF!";
}
public static void main(String[] args) {
SpringApplication.run(ZuulProxyApplication.class, args);
}
}

View File

@@ -1,15 +0,0 @@
spring.application.name: zuulproxy
server.port: 9900
zuul.ignored-patterns: /missing
zuul.routes.admin.path: /admin/**
zuul.routes.admin.url: forward:/
zuul.routes.good.path: /good/**
zuul.routes.good.url: forward:/good
zuul.routes.bad.path: /bad/**
zuul.routes.bad.url: http://localhost:7777
zuul.routes.gh.path: /gh/**
zuul.routes.gh.url: https://github.com
zuul.routes.gh.sensitive-headers: Set-Cookie,Cookie
#zuul.routes.ui.path: /**
#zuul.routes.ui.url: http://localhost:8080
logging.level.org.springframework.web: DEBUG

View File

@@ -1,43 +0,0 @@
package apps;
import java.io.IOException;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
@SpringBootApplication
@RestController
public class UiApplication {
@RequestMapping("/")
public String home(@RequestParam(required = false) String value) {
return "Hello " + (value == null ? "World" : value);
}
@RequestMapping(value = "/upload", method = RequestMethod.GET)
public String upload() {
ServletUriComponentsBuilder builder = ServletUriComponentsBuilder
.fromCurrentContextPath();
return "<html><body>"
+ "<form method='post' enctype='multipart/form-data' action='"
+ builder.path("/upload").build().toUriString() + "'>"
+ "File to upload: <input type='file' name='file'>"
+ "<input type='submit' value='Upload'></form>" + "</body></html>";
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String accept(@RequestParam MultipartFile file) throws IOException {
return new String(file.getBytes());
}
public static void main(String[] args) {
new SpringApplicationBuilder(UiApplication.class)
.properties("spring.config.name:ui").run(args);
}
}

View File

@@ -1,57 +0,0 @@
package demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class ZuulProxyApplicationTests {
@Autowired
DiscoveryClient discoveryClient;
@LocalServerPort
int port;
private TestRestTemplate restTemplate = new TestRestTemplate();
@Test
public void ignoredPatternMissing() {
ResponseEntity<String> result = this.restTemplate.getForEntity("http://localhost:"+this.port +"/missing", String.class);
assertEquals(HttpStatus.NOT_FOUND, result.getStatusCode());
}
@Test
public void forwardedPatternGood() {
ResponseEntity<String> result = this.restTemplate.getForEntity("http://localhost:"+this.port +"/good", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("GOOD!", result.getBody());
}
@Test
public void forwardedPatternGoodWithPath() {
ResponseEntity<String> result = this.restTemplate.getForEntity("http://localhost:"+this.port +"/good/stuff", String.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals("STUFF!", result.getBody());
}
@Test
public void discoveryClientIsComposite() {
assertTrue("discoveryClient is wrong type", this.discoveryClient instanceof CompositeDiscoveryClient);
}
}

View File

@@ -1,14 +0,0 @@
--FOO
Content-Disposition: form-data; name="file"; filename="foo.txt"
Content-Type: text/plain
POST this file to the proxy to test multipart file data:
$ curl -v -H "Content-Type: multipart/form-data; boundary=FOO" --data-binary @thisfile
--FOO
Content-Disposition: form-data; name="name"
Dave
--FOO--

View File

@@ -1,3 +0,0 @@
spring.application.name: ui
multipart.maxFileSize: 128KB
multipart.maxRequestSize: 128KB

View File

@@ -1 +0,0 @@
Test with zuul server only. No proxy and no eureka.

View File

@@ -1,129 +0,0 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud.test</groupId>
<artifactId>spring-cloud-test-zuul</artifactId>
<version>${spring-cloud.version}</version>
<packaging>jar</packaging>
<name>spring-cloud-test-zuul</name>
<description>Demo project for Spring Cloud</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.BUILD-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>demo.DemoApplication</start-class>
<java.version>1.8</java.version>
<spring-cloud.version>2020.0.0-SNAPSHOT</spring-cloud.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.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-zuul</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>
<!--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>

View File

@@ -1,64 +0,0 @@
package demo;
import javax.servlet.http.HttpServletResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulServer;
import org.springframework.stereotype.Component;
import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
@SpringBootApplication
@EnableZuulServer
public class ZuulApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulApplication.class, args);
}
}
@Component
class SampleStaticResponseFilter extends ZuulFilter {
private static final String URI = "/static";
@Override
public String filterType() {
return "route";
}
@Override
public int filterOrder() {
return 0;
}
@Override
public boolean shouldFilter() {
String path = RequestContext.getCurrentContext().getRequest().getRequestURI();
if (checkPath(path))
return true;
if (checkPath("/" + path))
return true;
return false;
}
private boolean checkPath(String path) {
return URI.equals(path);
}
@Override
public Object run() {
RequestContext ctx = RequestContext.getCurrentContext();
// Set the default response code for static filters to be 200
ctx.setResponseStatusCode(HttpServletResponse.SC_OK);
// first StaticResponseFilter instance to match wins, others do not set body
// and/or status
if (ctx.getResponseBody() == null) {
ctx.setResponseBody("Hello World");
ctx.setSendZuulResponse(false);
}
return null;
}
}

View File

@@ -1,3 +0,0 @@
spring.application.name: zuul
server.port: 9900
zuul.routes.ui.path: /static/**

View File

@@ -1,40 +0,0 @@
package demo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.discovery.composite.CompositeDiscoveryClient;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT)
@DirtiesContext
public class ZuulApplicationTests {
@Autowired
DiscoveryClient discoveryClient;
@LocalServerPort
int port;
@Test
public void contextLoads() {
assertEquals("Hello World", new TestRestTemplate()
.getForObject("http://localhost:" + this.port + "/static", String.class));
}
@Test
public void discoveryClientIsComposite() {
assertTrue("discoveryClient is wrong type",
this.discoveryClient instanceof CompositeDiscoveryClient);
}
}

View File

@@ -1,14 +0,0 @@
--FOO
Content-Disposition: form-data; name="file"; filename="foo.txt"
Content-Type: text/plain
POST this file to the proxy to test multipart file data:
$ curl -v -H "Content-Type: multipart/form-data; boundary=FOO" --data-binary @thisfile
--FOO
Content-Disposition: form-data; name="name"
Dave
--FOO--

View File

@@ -1,3 +0,0 @@
spring.application.name: ui
multipart.maxFileSize: 128KB
multipart.maxRequestSize: 128KB