mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
replace code properties that have expired
This commit is contained in:
parent
cc053a520a
commit
ffb246829f
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@ -39,9 +39,8 @@ public class MySCGConfiguration {
|
||||
@Override
|
||||
public Mono<ServerResponse> 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"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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 <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@ -41,8 +41,7 @@ public class MyConfiguration {
|
||||
public Mono<ServerResponse> 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"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||
@ -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<ServerResponse> handleRequest(ServerWebExchange exchange,
|
||||
Throwable t) {
|
||||
return ServerResponse
|
||||
GatewayCallbackManager.setBlockHandler((exchange, t) -> ServerResponse
|
||||
.status(fallbackProperties.getResponseStatus())
|
||||
.contentType(MediaType
|
||||
.valueOf(fallbackProperties.getContentType()))
|
||||
.body(fromObject(fallbackProperties.getResponseBody()));
|
||||
}
|
||||
});
|
||||
.contentType(
|
||||
MediaType.valueOf(fallbackProperties.getContentType()))
|
||||
.body(fromValue(fallbackProperties.getResponseBody())));
|
||||
logger.info(
|
||||
"[Sentinel SpringCloudGateway] using AnonymousBlockRequestHandler, responseStatus: "
|
||||
+ fallbackProperties.getResponseStatus()
|
||||
|
Loading…
x
Reference in New Issue
Block a user