tanghc 5 years ago
parent 0958cf003c
commit 01b1e7b72d
  1. 4
      changelog.md
  2. 2
      sop-auth/pom.xml
  3. 2
      sop-common/pom.xml
  4. 4
      sop-common/sop-gateway-common/pom.xml
  5. 41
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/RequestUtil.java
  6. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/util/ResponseUtil.java
  7. 90
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/ValidateService.java
  8. 7
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/configuration/BaseZuulConfiguration.java
  9. 25
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/filter/PreValidateFilter.java
  10. 10
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParameterUtil.java
  11. 3
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/result/ZuulResultExecutor.java
  12. 4
      sop-common/sop-service-common/pom.xml
  13. 2
      sop-example/sop-book/sop-book-web/pom.xml
  14. 2
      sop-example/sop-easyopen/pom.xml
  15. 2
      sop-example/sop-springmvc/pom.xml
  16. 2
      sop-example/sop-story/sop-story-web/pom.xml
  17. 2
      sop-gateway/pom.xml
  18. 45
      sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RedirectController.java
  19. 2
      sop-gateway/src/main/java/com/gitee/sop/gateway/controller/RestServlet.java
  20. 2
      sop-test/src/test/java/com/gitee/sop/test/AllInOneTest.java
  21. 2
      sop-website/pom.xml

@ -1,5 +1,9 @@
# changelog # changelog
## 2.5.10
- 优化签名认证,优化校验日志打印
## 2.5.9 ## 2.5.9
- 优化获取context-path - 优化获取context-path

@ -26,7 +26,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<!-- sop相关配置 end--> <!-- sop相关配置 end-->

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>

@ -5,11 +5,11 @@
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-gateway-common</name> <name>sop-gateway-common</name>

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.param.ApiUploadContext; import com.gitee.sop.gatewaycommon.param.ApiUploadContext;
import com.gitee.sop.gatewaycommon.param.UploadContext; import com.gitee.sop.gatewaycommon.param.UploadContext;
import com.gitee.sop.gatewaycommon.zuul.param.ZuulParameterUtil;
import com.netflix.zuul.http.HttpServletRequestWrapper; import com.netflix.zuul.http.HttpServletRequestWrapper;
import lombok.Data; import lombok.Data;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
@ -14,8 +15,11 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile; import org.springframework.web.multipart.commons.CommonsMultipartFile;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException; import java.io.IOException;
@ -24,6 +28,7 @@ import java.net.InetAddress;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -240,6 +245,9 @@ public class RequestUtil {
* @return 返回文件内容和表单内容 * @return 返回文件内容和表单内容
*/ */
public static UploadInfo getUploadInfo(HttpServletRequest request) { public static UploadInfo getUploadInfo(HttpServletRequest request) {
if (request instanceof StandardMultipartHttpServletRequest) {
return getUploadInfo((StandardMultipartHttpServletRequest)request);
}
UploadInfo uploadInfo = new UploadInfo(); UploadInfo uploadInfo = new UploadInfo();
// 创建一个文件上传解析器 // 创建一个文件上传解析器
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
@ -269,6 +277,19 @@ public class RequestUtil {
return uploadInfo; return uploadInfo;
} }
public static UploadInfo getUploadInfo(StandardMultipartHttpServletRequest request) {
UploadInfo uploadInfo = new UploadInfo();
Map<String, String> uploadParams = new HashMap<>(16);
request.getParameterMap().forEach((key, value)-> uploadParams.put(key, value[0]));
Map<String, MultipartFile> multipartFileMap = request.getMultiFileMap().toSingleValueMap();
UploadContext uploadContext = new ApiUploadContext(multipartFileMap);
uploadInfo.setUploadParams(uploadParams);
uploadInfo.setUploadContext(uploadContext);
return uploadInfo;
}
public static void checkResponseBody(String responseBody, String sign, String secret) throws Exception { public static void checkResponseBody(String responseBody, String sign, String secret) throws Exception {
if (sign == null) { if (sign == null) {
throw new Exception("签名不存在"); throw new Exception("签名不存在");
@ -280,6 +301,26 @@ public class RequestUtil {
} }
} }
public static HttpServletRequest wrapRequest(HttpServletRequest request) {
if (request.getMethod().equalsIgnoreCase(HttpMethod.GET.name()) ||
request instanceof StandardMultipartHttpServletRequest) {
return request;
}
HttpServletRequest wrapper = request;
String contentType = request.getContentType();
MediaType mediaType = MediaType.valueOf(contentType);
if (MediaType.APPLICATION_JSON.includes(mediaType)) {
try {
String json = RequestUtil.getText(request);
byte[] data = json.getBytes(StandardCharsets.UTF_8);
wrapper = new ZuulParameterUtil.BodyDataHttpServletRequestWrapper(request, data);
} catch (IOException e) {
log.error("wrapRequest异常", e);
}
}
return wrapper;
}
@Data @Data
public static class UploadInfo { public static class UploadInfo {
private Map<String, String> uploadParams; private Map<String, String> uploadParams;

@ -30,7 +30,7 @@ public class ResponseUtil {
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
response.setCharacterEncoding(UTF_8); response.setCharacterEncoding(UTF_8);
try { try {
response.getWriter().write(JSON.toJSONString(result)); response.getWriter().write(result instanceof String ? (String)result : JSON.toJSONString(result));
} catch (IOException e) { } catch (IOException e) {
log.error("doWriter", e); log.error("doWriter", e);
} }

@ -0,0 +1,90 @@
package com.gitee.sop.gatewaycommon.zuul;
import com.gitee.sop.gatewaycommon.bean.ApiConfig;
import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.param.ParamBuilder;
import com.gitee.sop.gatewaycommon.util.RequestUtil;
import com.gitee.sop.gatewaycommon.util.ResponseUtil;
import com.gitee.sop.gatewaycommon.validate.Validator;
import com.netflix.zuul.context.RequestContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* 负责签名校验
* @author tanghc
*/
@Slf4j
public class ValidateService {
@Autowired
private ParamBuilder<RequestContext> paramBuilder;
@Autowired
private Validator validator;
/**
* 校验操作
*
* @param request request
* @param response response
* @param callback 校验后操作
*/
public void validate(HttpServletRequest request, HttpServletResponse response, ValidateCallback callback) {
RequestContext currentContext = RequestContext.getCurrentContext();
currentContext.setRequest(RequestUtil.wrapRequest(request));
currentContext.setResponse(response);
doValidate(currentContext, callback);
}
/**
* 签名校验
*
* @param currentContext currentContext
*/
private void doValidate(RequestContext currentContext, ValidateCallback callback) {
// 解析参数
ApiParam param = paramBuilder.build(currentContext);
ZuulContext.setApiParam(param);
Exception error = null;
// 验证操作,这里有负责验证签名参数
try {
validator.validate(param);
} catch (Exception e) {
error = e;
}
param.fitNameVersion();
if (error == null) {
callback.onSuccess(currentContext);
} else {
callback.onError(currentContext, param, error);
}
}
public interface ValidateCallback {
/**
* 校验成功触发
*
* @param currentContext 上下文
*/
void onSuccess(RequestContext currentContext);
/**
* 校验失败触发
*
* @param currentContext 上下文
* @param param 参数
* @param throwable 异常
*/
default void onError(RequestContext currentContext, ApiParam param, Throwable throwable) {
log.error("验证失败,ip:{}, params:{}, errorMsg:{}", param.fetchIp(), param.toJSONString(), throwable.getMessage());
String errorResult = ApiConfig.getInstance().getZuulResultExecutor().buildErrorResult(currentContext, throwable);
ResponseUtil.writeJson(currentContext.getResponse(), errorResult);
}
}
}

@ -5,6 +5,7 @@ import com.gitee.sop.gatewaycommon.bean.ApiContext;
import com.gitee.sop.gatewaycommon.manager.AbstractConfiguration; import com.gitee.sop.gatewaycommon.manager.AbstractConfiguration;
import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext; import com.gitee.sop.gatewaycommon.manager.RouteRepositoryContext;
import com.gitee.sop.gatewaycommon.param.ParamBuilder; import com.gitee.sop.gatewaycommon.param.ParamBuilder;
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter; import com.gitee.sop.gatewaycommon.zuul.filter.ErrorFilter;
import com.gitee.sop.gatewaycommon.zuul.filter.FormBodyWrapperFilterExt; import com.gitee.sop.gatewaycommon.zuul.filter.FormBodyWrapperFilterExt;
import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter; import com.gitee.sop.gatewaycommon.zuul.filter.PostResultFilter;
@ -54,6 +55,7 @@ public class BaseZuulConfiguration extends AbstractConfiguration {
return zuulRouteRepository; return zuulRouteRepository;
} }
@Bean @Bean
PreHttpServletRequestWrapperFilter preHttpServletRequestWrapperFilter() { PreHttpServletRequestWrapperFilter preHttpServletRequestWrapperFilter() {
return new PreHttpServletRequestWrapperFilter(); return new PreHttpServletRequestWrapperFilter();
@ -102,6 +104,11 @@ public class BaseZuulConfiguration extends AbstractConfiguration {
return new PreValidateFilter(); return new PreValidateFilter();
} }
@Bean
ValidateService validateService() {
return new ValidateService();
}
@Bean @Bean
PreParameterFormatterFilter preParameterFormatterFilter() { PreParameterFormatterFilter preParameterFormatterFilter() {
return new PreParameterFormatterFilter(); return new PreParameterFormatterFilter();

@ -1,16 +1,15 @@
package com.gitee.sop.gatewaycommon.zuul.filter; package com.gitee.sop.gatewaycommon.zuul.filter;
import com.gitee.sop.gatewaycommon.exception.ApiException;
import com.gitee.sop.gatewaycommon.param.ApiParam; import com.gitee.sop.gatewaycommon.param.ApiParam;
import com.gitee.sop.gatewaycommon.param.ParamBuilder; import com.gitee.sop.gatewaycommon.param.ParamBuilder;
import com.gitee.sop.gatewaycommon.validate.Validator;
import com.gitee.sop.gatewaycommon.zuul.ZuulContext; import com.gitee.sop.gatewaycommon.zuul.ZuulContext;
import com.netflix.zuul.context.RequestContext; import com.netflix.zuul.context.RequestContext;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
/** /**
* 前置校验 * 校验工作转移到了 com.gitee.sop.gateway.controller.RedirectController
*
* 将校验工作提前如果在zuul过滤器中校验抛出异常将会打印非常多的日志并且无法实现自定义返回结果
* *
* @author tanghc * @author tanghc
*/ */
@ -19,9 +18,6 @@ public class PreValidateFilter extends BaseZuulFilter {
@Autowired @Autowired
private ParamBuilder<RequestContext> paramBuilder; private ParamBuilder<RequestContext> paramBuilder;
@Autowired
private Validator validator;
@Override @Override
protected FilterType getFilterType() { protected FilterType getFilterType() {
return FilterType.PRE; return FilterType.PRE;
@ -33,18 +29,11 @@ public class PreValidateFilter extends BaseZuulFilter {
} }
@Override @Override
protected Object doRun(RequestContext requestContext) throws ZuulException { protected Object doRun(RequestContext requestContext) {
// 解析参数 ApiParam param = ZuulContext.getApiParam();
ApiParam param = paramBuilder.build(requestContext); if (param == null) {
param = paramBuilder.build(requestContext);
ZuulContext.setApiParam(param); ZuulContext.setApiParam(param);
// 验证操作,这里有负责验证签名参数
try {
validator.validate(param);
} catch (ApiException e) {
log.error("验证失败,ip:{}, params:{}", param.fetchIp(), param.toJSONString(), e);
throw e;
} finally {
param.fitNameVersion();
} }
return null; return null;
} }

@ -53,11 +53,11 @@ public class ZuulParameterUtil {
((JSONObject) apiParam).toJSONString() ((JSONObject) apiParam).toJSONString()
: JSON.toJSONString(apiParam); : JSON.toJSONString(apiParam);
byte[] bytes = json.getBytes(StandardCharsets.UTF_8); byte[] bytes = json.getBytes(StandardCharsets.UTF_8);
requestContext.setRequest(new ChangeParamsHttpServletRequestWrapper(request, bytes)); requestContext.setRequest(new BodyDataHttpServletRequestWrapper(request, bytes));
} else if(StringUtils.containsIgnoreCase(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE)) { } else if(StringUtils.containsIgnoreCase(contentType, MediaType.APPLICATION_FORM_URLENCODED_VALUE)) {
String paramsStr = RequestUtil.convertMapToQueryString(apiParam); String paramsStr = RequestUtil.convertMapToQueryString(apiParam);
byte[] data = paramsStr.getBytes(StandardCharsets.UTF_8); byte[] data = paramsStr.getBytes(StandardCharsets.UTF_8);
requestContext.setRequest(new ChangeParamsHttpServletRequestWrapper(request, data)); requestContext.setRequest(new BodyDataHttpServletRequestWrapper(request, data));
} else if(RequestUtil.isMultipart(request)) { } else if(RequestUtil.isMultipart(request)) {
FormHttpOutputMessage outputMessage = new FormHttpOutputMessage(); FormHttpOutputMessage outputMessage = new FormHttpOutputMessage();
try { try {
@ -82,7 +82,7 @@ public class ZuulParameterUtil {
// 获取新的上传文件流 // 获取新的上传文件流
byte[] data = outputMessage.getInput(); byte[] data = outputMessage.getInput();
requestContext.setRequest(new ChangeParamsHttpServletRequestWrapper(request, data)); requestContext.setRequest(new BodyDataHttpServletRequestWrapper(request, data));
// 必须要重新指定content-type,因为此时的boundary已经发生改变 // 必须要重新指定content-type,因为此时的boundary已经发生改变
requestContext.getZuulRequestHeaders().put("content-type", outputMessage.getHeaders().getContentType().toString()); requestContext.getZuulRequestHeaders().put("content-type", outputMessage.getHeaders().getContentType().toString());
} catch (Exception e) { } catch (Exception e) {
@ -103,10 +103,10 @@ public class ZuulParameterUtil {
} }
} }
private static class ChangeParamsHttpServletRequestWrapper extends HttpServletRequestWrapper { public static class BodyDataHttpServletRequestWrapper extends HttpServletRequestWrapper {
private byte[] data; private byte[] data;
public ChangeParamsHttpServletRequestWrapper(HttpServletRequest request, byte[] data) { public BodyDataHttpServletRequestWrapper(HttpServletRequest request, byte[] data) {
super(request); super(request);
this.data = data; this.data = data;
} }

@ -73,6 +73,9 @@ public class ZuulResultExecutor extends BaseExecutorAdapter<RequestContext, Stri
ApiException apiException = (ApiException) cause; ApiException apiException = (ApiException) cause;
error = apiException.getError(); error = apiException.getError();
} }
} else if (throwable instanceof ApiException) {
ApiException apiException = (ApiException) throwable;
error = apiException.getError();
} }
if (error == null) { if (error == null) {
error = ErrorEnum.ISP_UNKNOWN_ERROR.getErrorMeta().getError(); error = ErrorEnum.ISP_UNKNOWN_ERROR.getErrorMeta().getError();

@ -6,11 +6,11 @@
<parent> <parent>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-common</artifactId> <artifactId>sop-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>sop-service-common</name> <name>sop-service-common</name>

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<!-- 使用nacos注册中心 <!-- 使用nacos注册中心

@ -20,7 +20,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<!-- nacos --> <!-- nacos -->
<dependency> <dependency>

@ -28,7 +28,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId> <artifactId>sop-service-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ --> <!-- ↓↓↓ 使用spring cloud zuul ↓↓↓ -->

@ -1,43 +1,66 @@
package com.gitee.sop.gateway.controller; package com.gitee.sop.gateway.controller;
import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.zuul.ValidateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/** /**
* 网关入口
*
* @author tanghc * @author tanghc
*/ */
@Slf4j
@Controller @Controller
public class RedirectController { public class RedirectController {
@Autowired
private ValidateService validateService;
@Value("${zuul.servlet-path:/zuul}") @Value("${zuul.servlet-path:/zuul}")
private String path; private String path;
/**
* 验证回调可自定义实现接口
*/
private ValidateService.ValidateCallback callback = (currentContext -> {
try {
currentContext.getRequest().getRequestDispatcher(path).forward(currentContext.getRequest(), currentContext.getResponse());
} catch (Exception e) {
log.error("请求转发异常", e);
}
});
/**
* 网关入口
*
* @param request request
* @param response response
*/
@RequestMapping("/")
public void index(HttpServletRequest request, HttpServletResponse response) {
validateService.validate(request, response, callback);
}
@RequestMapping("/{method}/{version}/") @RequestMapping("/{method}/{version}/")
public void redirect( public void redirect(
@PathVariable("method") String method @PathVariable("method") String method
, @PathVariable("version") String version , @PathVariable("version") String version
, HttpServletRequest request , HttpServletRequest request
, HttpServletResponse response , HttpServletResponse response
) throws ServletException, IOException { ) {
request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method); request.setAttribute(SopConstants.REDIRECT_METHOD_KEY, method);
request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version); request.setAttribute(SopConstants.REDIRECT_VERSION_KEY, version);
request.getRequestDispatcher(path).forward(request, response); validateService.validate(request, response, callback);
} }
@RequestMapping("/")
public void index(
HttpServletRequest request
, HttpServletResponse response
) throws ServletException, IOException {
request.getRequestDispatcher(path).forward(request, response);
}
} }

@ -1,8 +1,6 @@
package com.gitee.sop.gateway.controller; package com.gitee.sop.gateway.controller;
import com.gitee.sop.gatewaycommon.bean.SopConstants; import com.gitee.sop.gatewaycommon.bean.SopConstants;
import com.gitee.sop.gatewaycommon.param.ParamNames;
import com.gitee.sop.gatewaycommon.util.RouteUtil;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import javax.servlet.ServletException; import javax.servlet.ServletException;

@ -18,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger;
public class AllInOneTest extends TestBase { public class AllInOneTest extends TestBase {
String url = "http://localhost:8081"; String url = "http://localhost:8081";
String appId = "2019032617262200001"; String appId = "2019032617262200001-";
String privateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXJv1pQFqWNA/++OYEV7WYXwexZK/J8LY1OWlP9X0T6wHFOvxNKRvMkJ5544SbgsJpVcvRDPrcxmhPbi/sAhdO4x2PiPKIz9Yni2OtYCCeaiE056B+e1O2jXoLeXbfi9fPivJZkxH/tb4xfLkH3bA8ZAQnQsoXA0SguykMRZntF0TndUfvDrLqwhlR8r5iRdZLB6F8o8qXH6UPDfNEnf/K8wX5T4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uUMwLA/HCqUgR4K9pyYV+Oyb8d6f0+Hz0BMD92I2pqlXrD7xV2WzDvyXM3s63NvorRooKcyfd9i6ccMjAyTR2qfLkxv0hlbBbsPHz4BbU63xhTJp3Ghi0/ey/1HQKBgQC2VsgqC6ykfSidZUNLmQZe3J0p/Qf9VLkfrQ+xaHapOs6AzDU2H2osuysqXTLJHsGfrwVaTs00ER2z8ljTJPBUtNtOLrwNRlvgdnzyVAKHfOgDBGwJgiwpeE9voB1oAV/mXqSaUWNnuwlOIhvQEBwekqNyWvhLqC7nCAIhj3yvNQKBgQCqYbeec56LAhWP903Zwcj9VvG7sESqXUhIkUqoOkuIBTWFFIm54QLTA1tJxDQGb98heoCIWf5x/A3xNI98RsqNBX5JON6qNWjb7/dobitti3t99v/ptDp9u8JTMC7penoryLKK0Ty3bkan95Kn9SC42YxaSghzqkt+uvfVQgiNGQKBgGxU6P2aDAt6VNwWosHSe+d2WWXt8IZBhO9d6dn0f7ORvcjmCqNKTNGgrkewMZEuVcliueJquR47IROdY8qmwqcBAN7Vg2K7r7CPlTKAWTRYMJxCT1Hi5gwJb+CZF3+IeYqsJk2NF2s0w5WJTE70k1BSvQsfIzAIDz2yE1oPHvwVAoGAA6e+xQkVH4fMEph55RJIZ5goI4Y76BSvt2N5OKZKd4HtaV+eIhM3SDsVYRLIm9ZquJHMiZQGyUGnsvrKL6AAVNK7eQZCRDk9KQz+0GKOGqku0nOZjUbAu6A2/vtXAaAuFSFx1rUQVVjFulLexkXR3KcztL1Qu2k5pB6Si0K/uwQ=";
private Client client = new Client(url, appId, privateKey, AllInOneTest::assertResult); private Client client = new Client(url, appId, privateKey, AllInOneTest::assertResult);

@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>com.gitee.sop</groupId> <groupId>com.gitee.sop</groupId>
<artifactId>sop-gateway-common</artifactId> <artifactId>sop-gateway-common</artifactId>
<version>2.5.9-SNAPSHOT</version> <version>2.5.10-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>

Loading…
Cancel
Save