Add the ability to provide a default ZuulFallbackProvider. Fixes #1506

This commit is contained in:
Ryan Baxter
2017-02-14 13:59:25 -05:00
parent d78da7b994
commit 731c8bf0fd
6 changed files with 168 additions and 7 deletions

View File

@@ -1755,6 +1755,56 @@ zuul:
customers: /customers/**
----
If you would like to provide a default fallback for all routes than you can create a bean of
type `ZuulFallbackProvider` and have the `getRoute` method return `*` or `null`.
[source,java]
----
class MyFallbackProvider implements ZuulFallbackProvider {
@Override
public String getRoute() {
return "*";
}
@Override
public ClientHttpResponse fallbackResponse() {
return new ClientHttpResponse() {
@Override
public HttpStatus getStatusCode() throws IOException {
return HttpStatus.OK;
}
@Override
public int getRawStatusCode() throws IOException {
return 200;
}
@Override
public String getStatusText() throws IOException {
return "OK";
}
@Override
public void close() {
}
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream("fallback".getBytes());
}
@Override
public HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return headers;
}
};
}
}
----
[[zuul-developer-guide]]
=== Zuul Developer Guide