-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ad6e5b
commit 5ec06e7
Showing
15 changed files
with
212 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
gateway/src/main/java/com/microservices/GenericFallbackProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.microservices; | ||
|
||
import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
/** | ||
* Created by mihir.desai on 3/15/2018. | ||
*/ | ||
public class GenericFallbackProvider implements FallbackProvider { | ||
private String route = "*"; | ||
private HttpStatus status = HttpStatus.SERVICE_UNAVAILABLE; | ||
private String statusText = "Service Unavailable"; | ||
private int rawStatusCode = 503; | ||
private HttpHeaders headers = null; | ||
private String responseBody = "{\"message\":\"Service Unavailable. Please try after sometime\"}"; | ||
|
||
@Override | ||
public String getRoute() { | ||
return route; | ||
} | ||
|
||
public void setRoute(String route) { | ||
this.route = route; | ||
} | ||
|
||
public void setStatus(HttpStatus status) { | ||
this.status = status; | ||
} | ||
|
||
public void setStatusText(String statusText) { | ||
this.statusText = statusText; | ||
} | ||
|
||
public void setRawStatusCode(int rawStatusCode) { | ||
this.rawStatusCode = rawStatusCode; | ||
} | ||
|
||
public void setHeaders(HttpHeaders headers) { | ||
this.headers = headers; | ||
} | ||
|
||
public void setResponseBody(String responseBody) { | ||
this.responseBody = responseBody; | ||
} | ||
|
||
@Override | ||
public ClientHttpResponse fallbackResponse(String s, Throwable throwable) { | ||
return new ClientHttpResponse() { | ||
@Override | ||
public HttpStatus getStatusCode() throws IOException { | ||
if(status == null) { | ||
status = HttpStatus.SERVICE_UNAVAILABLE; | ||
} | ||
return status; | ||
} | ||
|
||
@Override | ||
public int getRawStatusCode() throws IOException { | ||
return rawStatusCode; | ||
} | ||
|
||
@Override | ||
public String getStatusText() throws IOException { | ||
if(statusText == null) { | ||
statusText = "Service Unavailable"; | ||
} | ||
return statusText; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
|
||
} | ||
|
||
@Override | ||
public InputStream getBody() throws IOException { | ||
if (responseBody == null) | ||
responseBody ="{\"message\":\"Service Unavailable. Please try after sometime\"}"; | ||
return new ByteArrayInputStream(responseBody.getBytes()); | ||
} | ||
|
||
@Override | ||
public HttpHeaders getHeaders() { | ||
if(headers == null) { | ||
headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
headers.setAccessControlAllowCredentials(true); | ||
headers.setAccessControlAllowOrigin("*"); | ||
} | ||
return headers; | ||
} | ||
}; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
gateway/src/main/java/com/microservices/configuration/HystrixFallbackProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.microservices.configuration; | ||
|
||
import com.microservices.GenericFallbackProvider; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
|
||
/** | ||
* Created by mihir.desai on 3/15/2018. | ||
*/ | ||
@Configuration | ||
public class HystrixFallbackProvider { | ||
@Bean | ||
public FallbackProvider zuulFallbackProvider() { | ||
return new GenericFallbackProvider(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.