mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
sentinel support custom block response by sentinelClientHttpResponse
This commit is contained in:
parent
8c661d051a
commit
849b224fad
@ -127,6 +127,18 @@
|
|||||||
<artifactId>sentinel-dubbo-api</artifactId>
|
<artifactId>sentinel-dubbo-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-cluster-server-default</artifactId>
|
||||||
|
<version>${sentinel.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-cluster-client-default</artifactId>
|
||||||
|
<version>${sentinel.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.rocketmq</groupId>
|
<groupId>org.apache.rocketmq</groupId>
|
||||||
<artifactId>rocketmq-client</artifactId>
|
<artifactId>rocketmq-client</artifactId>
|
||||||
|
@ -35,6 +35,16 @@
|
|||||||
<artifactId>sentinel-dubbo-adapter</artifactId>
|
<artifactId>sentinel-dubbo-adapter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-cluster-server-default</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-cluster-client-default</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.cloud</groupId>
|
<groupId>org.springframework.cloud</groupId>
|
||||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||||
|
@ -16,6 +16,13 @@
|
|||||||
|
|
||||||
package org.springframework.cloud.alibaba.sentinel.rest;
|
package org.springframework.cloud.alibaba.sentinel.rest;
|
||||||
|
|
||||||
|
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
|
||||||
|
import org.springframework.cloud.alibaba.sentinel.custom.SentinelProtectInterceptor;
|
||||||
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.http.client.AbstractClientHttpResponse;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -24,20 +31,22 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.cloud.alibaba.sentinel.annotation.SentinelRestTemplate;
|
|
||||||
import org.springframework.cloud.alibaba.sentinel.custom.SentinelProtectInterceptor;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.MediaType;
|
|
||||||
import org.springframework.http.client.AbstractClientHttpResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Using by {@link SentinelRestTemplate} and {@link SentinelProtectInterceptor}
|
* Using by {@link SentinelRestTemplate} and {@link SentinelProtectInterceptor}
|
||||||
|
*
|
||||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||||
*/
|
*/
|
||||||
public class SentinelClientHttpResponse extends AbstractClientHttpResponse {
|
public class SentinelClientHttpResponse extends AbstractClientHttpResponse {
|
||||||
|
|
||||||
private final String BLOCK_STR = "RestTemplate request block by sentinel";
|
private String blockResponse = "RestTemplate request block by sentinel";
|
||||||
|
|
||||||
|
public SentinelClientHttpResponse() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public SentinelClientHttpResponse(String blockResponse) {
|
||||||
|
this.blockResponse = blockResponse;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRawStatusCode() throws IOException {
|
public int getRawStatusCode() throws IOException {
|
||||||
@ -46,7 +55,7 @@ public class SentinelClientHttpResponse extends AbstractClientHttpResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStatusText() throws IOException {
|
public String getStatusText() throws IOException {
|
||||||
return BLOCK_STR;
|
return blockResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -56,7 +65,7 @@ public class SentinelClientHttpResponse extends AbstractClientHttpResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getBody() throws IOException {
|
public InputStream getBody() throws IOException {
|
||||||
return new ByteArrayInputStream(BLOCK_STR.getBytes());
|
return new ByteArrayInputStream(blockResponse.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user