ApiFallbackProvider.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package com.txz.project.configurer;
  2. // import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider;
  3. // import org.springframework.http.HttpHeaders;
  4. // import org.springframework.http.HttpStatus;
  5. // import org.springframework.http.MediaType;
  6. // import org.springframework.http.client.ClientHttpResponse;
  7. // import org.springframework.stereotype.Component;
  8. //
  9. // import java.io.ByteArrayInputStream;
  10. // import java.io.IOException;
  11. // import java.io.InputStream;
  12. //
  13. // /**
  14. // * @author: linjie
  15. // * @description:错误拦截回显,熔断
  16. // * @create: 2018/10/11 20:01
  17. // */
  18. // @Component
  19. // public class ApiFallbackProvider implements FallbackProvider{
  20. //
  21. // @Override
  22. // public String getRoute() {
  23. // //设置熔断的服务名
  24. // //如果是所有服务则设置为*
  25. // return "*";
  26. // }
  27. //
  28. // @Override
  29. // public ClientHttpResponse fallbackResponse(String route, Throwable cause) {
  30. // return new ClientHttpResponse() {
  31. // @Override
  32. // public HttpStatus getStatusCode() throws IOException {
  33. // return HttpStatus.OK;
  34. // }
  35. //
  36. // @Override
  37. // public int getRawStatusCode() throws IOException {
  38. // return 200;
  39. // }
  40. //
  41. // @Override
  42. // public String getStatusText() throws IOException {
  43. // return "{code:0,message:service error =_=}";
  44. // }
  45. //
  46. // @Override
  47. // public void close() {
  48. //
  49. // }
  50. //
  51. // @Override
  52. // public InputStream getBody() throws IOException {
  53. // return new ByteArrayInputStream("{\"code\":\"599\",\"message\":\"zuul Access Filter - The service is unavailable.\"}".getBytes());
  54. // }
  55. //
  56. // @Override
  57. // public HttpHeaders getHeaders() {
  58. // HttpHeaders headers = new HttpHeaders();
  59. // headers.setContentType(MediaType.APPLICATION_JSON);
  60. // return headers;
  61. // }
  62. // };
  63. // }
  64. //
  65. //
  66. // }