diff --git a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpressionTest.java b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpressionTest.java
index 02ef7576..8ec861f8 100644
--- a/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpressionTest.java
+++ b/spring-cloud-alibaba-dubbo/src/test/java/com/alibaba/cloud/dubbo/http/matcher/ConsumeMediaTypeExpressionTest.java
@@ -33,16 +33,16 @@ public class ConsumeMediaTypeExpressionTest
public void testMatch() {
ConsumeMediaTypeExpression expression = createExpression(MediaType.ALL_VALUE);
- Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON_UTF8));
+ Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON));
expression = createExpression(MediaType.APPLICATION_JSON_VALUE);
- Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON_UTF8));
+ Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON));
expression = createExpression(MediaType.APPLICATION_JSON_VALUE + ";q=0.7");
- Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON_UTF8));
+ Assert.assertTrue(expression.match(MediaType.APPLICATION_JSON));
expression = createExpression(MediaType.TEXT_HTML_VALUE);
- Assert.assertFalse(expression.match(MediaType.APPLICATION_JSON_UTF8));
+ Assert.assertFalse(expression.match(MediaType.APPLICATION_JSON));
}
}
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java
index 96a67ae7..2f612e40 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-spring-cloud-gateway-example/src/main/java/com/alibaba/cloud/examples/MySCGConfiguration.java
@@ -25,7 +25,7 @@ import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
-import static org.springframework.web.reactive.function.BodyInserters.fromObject;
+import static org.springframework.web.reactive.function.BodyInserters.fromValue;
/**
* @author Jim
@@ -39,9 +39,8 @@ public class MySCGConfiguration {
@Override
public Mono handleRequest(ServerWebExchange exchange,
Throwable t) {
- return ServerResponse.status(444)
- .contentType(MediaType.APPLICATION_JSON_UTF8)
- .body(fromObject("SCS Sentinel block"));
+ return ServerResponse.status(444).contentType(MediaType.APPLICATION_JSON)
+ .body(fromValue("SCS Sentinel block"));
}
};
}
diff --git a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java
index 6a8d271c..dd8df034 100644
--- a/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java
+++ b/spring-cloud-alibaba-examples/sentinel-example/sentinel-webflux-example/src/main/java/com/alibaba/cloud/examples/MyConfiguration.java
@@ -26,7 +26,7 @@ import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
-import static org.springframework.web.reactive.function.BodyInserters.fromObject;
+import static org.springframework.web.reactive.function.BodyInserters.fromValue;
/**
* @author Jim
@@ -41,8 +41,7 @@ public class MyConfiguration {
public Mono handleRequest(ServerWebExchange exchange,
Throwable t) {
return ServerResponse.status(HttpStatus.TOO_MANY_REQUESTS)
- .contentType(MediaType.APPLICATION_JSON_UTF8)
- .body(fromObject("block"));
+ .contentType(MediaType.APPLICATION_JSON).body(fromValue("block"));
}
};
}
diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java
index 5d4d6ee8..e7eed21a 100644
--- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java
+++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/FallbackProperties.java
@@ -48,7 +48,7 @@ public class FallbackProperties {
/**
* Content-Type for `response` mode.
*/
- private String contentType = MediaType.APPLICATION_JSON_UTF8.toString();
+ private String contentType = MediaType.APPLICATION_JSON.toString();
public String getMode() {
return mode;
diff --git a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java
index cd397158..32db680a 100644
--- a/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java
+++ b/spring-cloud-alibaba-sentinel-gateway/src/main/java/com/alibaba/cloud/sentinel/gateway/scg/SentinelSCGAutoConfiguration.java
@@ -33,7 +33,6 @@ import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import reactor.core.publisher.Mono;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
@@ -50,9 +49,8 @@ import org.springframework.http.MediaType;
import org.springframework.http.codec.ServerCodecConfigurer;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.reactive.result.view.ViewResolver;
-import org.springframework.web.server.ServerWebExchange;
-import static org.springframework.web.reactive.function.BodyInserters.fromObject;
+import static org.springframework.web.reactive.function.BodyInserters.fromValue;
/**
* @author Jim
@@ -93,8 +91,7 @@ public class SentinelSCGAutoConfiguration {
}
private void initAppType() {
- System.setProperty(SentinelConfig.APP_TYPE,
- String.valueOf(ConfigConstants.APP_TYPE_SCG_GATEWAY));
+ System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_SCG_GATEWAY);
}
private void initFallback() {
@@ -105,17 +102,11 @@ public class SentinelSCGAutoConfiguration {
}
if (ConfigConstants.FALLBACK_MSG_RESPONSE.equals(fallbackProperties.getMode())) {
if (StringUtil.isNotBlank(fallbackProperties.getResponseBody())) {
- GatewayCallbackManager.setBlockHandler(new BlockRequestHandler() {
- @Override
- public Mono handleRequest(ServerWebExchange exchange,
- Throwable t) {
- return ServerResponse
- .status(fallbackProperties.getResponseStatus())
- .contentType(MediaType
- .valueOf(fallbackProperties.getContentType()))
- .body(fromObject(fallbackProperties.getResponseBody()));
- }
- });
+ GatewayCallbackManager.setBlockHandler((exchange, t) -> ServerResponse
+ .status(fallbackProperties.getResponseStatus())
+ .contentType(
+ MediaType.valueOf(fallbackProperties.getContentType()))
+ .body(fromValue(fallbackProperties.getResponseBody())));
logger.info(
"[Sentinel SpringCloudGateway] using AnonymousBlockRequestHandler, responseStatus: "
+ fallbackProperties.getResponseStatus()