|
|
@ -39,6 +39,10 @@ public class PolarisCircuitBreakerHttpResponse extends AbstractClientHttpRespons
|
|
|
|
|
|
|
|
|
|
|
|
private final CircuitBreakerStatus.FallbackInfo fallbackInfo;
|
|
|
|
private final CircuitBreakerStatus.FallbackInfo fallbackInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private InputStream body;
|
|
|
|
|
|
|
|
|
|
|
|
public PolarisCircuitBreakerHttpResponse(int code) {
|
|
|
|
public PolarisCircuitBreakerHttpResponse(int code) {
|
|
|
|
this(new CircuitBreakerStatus.FallbackInfo(code, null, null));
|
|
|
|
this(new CircuitBreakerStatus.FallbackInfo(code, null, null));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -53,6 +57,13 @@ public class PolarisCircuitBreakerHttpResponse extends AbstractClientHttpRespons
|
|
|
|
|
|
|
|
|
|
|
|
PolarisCircuitBreakerHttpResponse(CircuitBreakerStatus.FallbackInfo fallbackInfo) {
|
|
|
|
PolarisCircuitBreakerHttpResponse(CircuitBreakerStatus.FallbackInfo fallbackInfo) {
|
|
|
|
this.fallbackInfo = fallbackInfo;
|
|
|
|
this.fallbackInfo = fallbackInfo;
|
|
|
|
|
|
|
|
headers.add(POLARIS_CIRCUIT_BREAKER_FALLBACK_HEADER, "true");
|
|
|
|
|
|
|
|
if (fallbackInfo.getHeaders() != null) {
|
|
|
|
|
|
|
|
fallbackInfo.getHeaders().forEach(headers::add);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fallbackInfo.getBody() != null) {
|
|
|
|
|
|
|
|
body = new ByteArrayInputStream(fallbackInfo.getBody().getBytes());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -68,10 +79,9 @@ public class PolarisCircuitBreakerHttpResponse extends AbstractClientHttpRespons
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public final void close() {
|
|
|
|
public final void close() {
|
|
|
|
InputStream body = this.getBody();
|
|
|
|
if (this.body != null) {
|
|
|
|
if (body != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
body.close();
|
|
|
|
this.body.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (IOException e) {
|
|
|
|
catch (IOException e) {
|
|
|
|
// Ignore exception on close...
|
|
|
|
// Ignore exception on close...
|
|
|
@ -81,23 +91,15 @@ public class PolarisCircuitBreakerHttpResponse extends AbstractClientHttpRespons
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public final InputStream getBody() {
|
|
|
|
public final InputStream getBody() {
|
|
|
|
if (fallbackInfo.getBody() != null) {
|
|
|
|
return this.body;
|
|
|
|
return new ByteArrayInputStream(fallbackInfo.getBody().getBytes());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public final HttpHeaders getHeaders() {
|
|
|
|
public final HttpHeaders getHeaders() {
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
return this.headers;
|
|
|
|
if (fallbackInfo.getHeaders() != null) {
|
|
|
|
|
|
|
|
fallbackInfo.getHeaders().forEach(headers::add);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
headers.add(POLARIS_CIRCUIT_BREAKER_FALLBACK_HEADER, "true");
|
|
|
|
|
|
|
|
return headers;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public CircuitBreakerStatus.FallbackInfo getFallbackInfo() {
|
|
|
|
public CircuitBreakerStatus.FallbackInfo getFallbackInfo() {
|
|
|
|
return fallbackInfo;
|
|
|
|
return this.fallbackInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|