pull/1/head
tanghc 5 years ago
parent 26f7d2843e
commit c5c43b3be4
  1. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/filter/ParameterFormatterFilter.java
  2. 6
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/PreParameterFormatterFilter.java

@ -21,7 +21,7 @@ import static com.gitee.sop.gatewaycommon.gateway.filter.Orders.PARAMETER_FORMAT
public class ParameterFormatterFilter implements GlobalFilter, Ordered { public class ParameterFormatterFilter implements GlobalFilter, Ordered {
@Autowired(required = false) @Autowired(required = false)
private ParameterFormatter sopParameterFormatter; private ParameterFormatter parameterFormatter;
@Override @Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) { public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
@ -30,11 +30,11 @@ public class ParameterFormatterFilter implements GlobalFilter, Ordered {
return chain.filter(exchange); return chain.filter(exchange);
} }
// 校验成功后进行参数转换 // 校验成功后进行参数转换
if (sopParameterFormatter != null) { if (parameterFormatter != null) {
ServerWebExchange formatExchange = ServerWebExchangeUtil.format( ServerWebExchange formatExchange = ServerWebExchangeUtil.format(
exchange exchange
, apiParam , apiParam
, sopParameterFormatter::format , parameterFormatter::format
, httpHeaders -> httpHeaders.set(ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion())); , httpHeaders -> httpHeaders.set(ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion()));
return chain.filter(formatExchange); return chain.filter(formatExchange);
} }

@ -17,7 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
public class PreParameterFormatterFilter extends BaseZuulFilter { public class PreParameterFormatterFilter extends BaseZuulFilter {
@Autowired(required = false) @Autowired(required = false)
private ParameterFormatter sopParameterFormatter; private ParameterFormatter parameterFormatter;
@Override @Override
protected FilterType getFilterType() { protected FilterType getFilterType() {
@ -33,8 +33,8 @@ public class PreParameterFormatterFilter extends BaseZuulFilter {
protected Object doRun(RequestContext requestContext) throws ZuulException { protected Object doRun(RequestContext requestContext) throws ZuulException {
ApiParam apiParam = ZuulContext.getApiParam(); ApiParam apiParam = ZuulContext.getApiParam();
// 校验成功后进行参数转换 // 校验成功后进行参数转换
if (sopParameterFormatter != null) { if (parameterFormatter != null) {
ZuulParameterUtil.format(apiParam, sopParameterFormatter::format); ZuulParameterUtil.format(apiParam, parameterFormatter::format);
requestContext.addZuulRequestHeader(ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion()); requestContext.addZuulRequestHeader(ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion());
} }
return null; return null;

Loading…
Cancel
Save