mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-12 07:02:14 +08:00
修复postJson下version获取不到问题
This commit is contained in:
@@ -22,4 +22,9 @@ public class GatewayParamBuilder extends BaseParamBuilder<ServerWebExchange> {
|
|||||||
public String getIP(ServerWebExchange ctx) {
|
public String getIP(ServerWebExchange ctx) {
|
||||||
return ctx.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
return ctx.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVersionInHeader(ServerWebExchange ctx, String headerName, String version) {
|
||||||
|
ctx.getRequest().getHeaders().add(headerName, version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,14 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
*/
|
*/
|
||||||
public abstract String getIP(T ctx);
|
public abstract String getIP(T ctx);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将版本号添加到header中
|
||||||
|
* @param ctx 请求request
|
||||||
|
* @param headerName headerName
|
||||||
|
* @param version 版本号
|
||||||
|
*/
|
||||||
|
public abstract void setVersionInHeader(T ctx, String headerName, String version);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiParam build(T ctx) {
|
public ApiParam build(T ctx) {
|
||||||
ApiParam apiParam = this.newApiParam(ctx);
|
ApiParam apiParam = this.newApiParam(ctx);
|
||||||
@@ -40,6 +48,7 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
|
|||||||
}
|
}
|
||||||
this.initOtherProperty(apiParam);
|
this.initOtherProperty(apiParam);
|
||||||
apiParam.setIp(this.getIP(ctx));
|
apiParam.setIp(this.getIP(ctx));
|
||||||
|
this.setVersionInHeader(ctx, ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion());
|
||||||
return apiParam;
|
return apiParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,5 +45,7 @@ public class ParamNames {
|
|||||||
/** 返回sign名称 */
|
/** 返回sign名称 */
|
||||||
public static String RESPONSE_SIGN_NAME = "sign";
|
public static String RESPONSE_SIGN_NAME = "sign";
|
||||||
|
|
||||||
|
public static String HEADER_VERSION_NAME = "sop-version";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -53,6 +53,11 @@ public class ZuulParamBuilder extends BaseParamBuilder<RequestContext> {
|
|||||||
return RequestUtil.getIP(ctx.getRequest());
|
return RequestUtil.getIP(ctx.getRequest());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setVersionInHeader(RequestContext ctx, String headerName, String version) {
|
||||||
|
ctx.addZuulRequestHeader(headerName, version);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ApiParam newApiParam(RequestContext ctx) {
|
protected ApiParam newApiParam(RequestContext ctx) {
|
||||||
ApiParam apiParam = super.newApiParam(ctx);
|
ApiParam apiParam = super.newApiParam(ctx);
|
||||||
|
@@ -45,5 +45,7 @@ public class ParamNames {
|
|||||||
/** 时间戳格式 */
|
/** 时间戳格式 */
|
||||||
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
|
||||||
|
public static String HEADER_VERSION_NAME = "sop-version";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class ApiMappingRequestCondition implements RequestCondition<ApiMappingRequestCondition> {
|
public class ApiMappingRequestCondition implements RequestCondition<ApiMappingRequestCondition> {
|
||||||
|
|
||||||
public static final String UTF_8 = "UTF-8";
|
|
||||||
private String defaultVersion = ServiceConfig.getInstance().getDefaultVersion();
|
private String defaultVersion = ServiceConfig.getInstance().getDefaultVersion();
|
||||||
|
|
||||||
private ApiMappingInfo apiMappingInfo;
|
private ApiMappingInfo apiMappingInfo;
|
||||||
@@ -46,7 +45,10 @@ public class ApiMappingRequestCondition implements RequestCondition<ApiMappingRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String getVersion(HttpServletRequest request) {
|
protected String getVersion(HttpServletRequest request) {
|
||||||
String version = request.getParameter(ParamNames.VERSION_NAME);
|
String version = request.getHeader(ParamNames.HEADER_VERSION_NAME);
|
||||||
|
if (version == null) {
|
||||||
|
version = request.getParameter(ParamNames.VERSION_NAME);
|
||||||
|
}
|
||||||
return version == null ? defaultVersion : version;
|
return version == null ? defaultVersion : version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user