From e83b0b707a1d92df747978d910b54c9d54a9d68b Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 5 Aug 2019 18:29:12 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8DpostJson=E4=B8=8Bversion?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gatewaycommon/gateway/param/GatewayParamBuilder.java | 5 +++++ .../gitee/sop/gatewaycommon/param/BaseParamBuilder.java | 9 +++++++++ .../com/gitee/sop/gatewaycommon/param/ParamNames.java | 2 ++ .../sop/gatewaycommon/zuul/param/ZuulParamBuilder.java | 5 +++++ .../java/com/gitee/sop/servercommon/bean/ParamNames.java | 2 ++ .../servercommon/mapping/ApiMappingRequestCondition.java | 6 ++++-- 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/param/GatewayParamBuilder.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/param/GatewayParamBuilder.java index be9f0b68..dcdbe855 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/param/GatewayParamBuilder.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/param/GatewayParamBuilder.java @@ -22,4 +22,9 @@ public class GatewayParamBuilder extends BaseParamBuilder { public String getIP(ServerWebExchange ctx) { return ctx.getRequest().getRemoteAddress().getAddress().getHostAddress(); } + + @Override + public void setVersionInHeader(ServerWebExchange ctx, String headerName, String version) { + ctx.getRequest().getHeaders().add(headerName, version); + } } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java index 36aa6458..daaddfac 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java @@ -31,6 +31,14 @@ public abstract class BaseParamBuilder implements ParamBuilder { */ 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 public ApiParam build(T ctx) { ApiParam apiParam = this.newApiParam(ctx); @@ -40,6 +48,7 @@ public abstract class BaseParamBuilder implements ParamBuilder { } this.initOtherProperty(apiParam); apiParam.setIp(this.getIP(ctx)); + this.setVersionInHeader(ctx, ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion()); return apiParam; } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java index c375ee99..a1c65cbc 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java @@ -45,5 +45,7 @@ public class ParamNames { /** 返回sign名称 */ public static String RESPONSE_SIGN_NAME = "sign"; + public static String HEADER_VERSION_NAME = "sop-version"; + } diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParamBuilder.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParamBuilder.java index b219f8bf..c21f334f 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParamBuilder.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParamBuilder.java @@ -53,6 +53,11 @@ public class ZuulParamBuilder extends BaseParamBuilder { return RequestUtil.getIP(ctx.getRequest()); } + @Override + public void setVersionInHeader(RequestContext ctx, String headerName, String version) { + ctx.addZuulRequestHeader(headerName, version); + } + @Override protected ApiParam newApiParam(RequestContext ctx) { ApiParam apiParam = super.newApiParam(ctx); diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java index d717f627..d2e18d00 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java @@ -45,5 +45,7 @@ public class ParamNames { /** 时间戳格式 */ public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss"; + public static String HEADER_VERSION_NAME = "sop-version"; + } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java index fddad83f..e6a2739c 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java @@ -15,7 +15,6 @@ import javax.servlet.http.HttpServletRequest; @Slf4j public class ApiMappingRequestCondition implements RequestCondition { - public static final String UTF_8 = "UTF-8"; private String defaultVersion = ServiceConfig.getInstance().getDefaultVersion(); private ApiMappingInfo apiMappingInfo; @@ -46,7 +45,10 @@ public class ApiMappingRequestCondition implements RequestCondition Date: Mon, 5 Aug 2019 18:30:05 +0800 Subject: [PATCH 2/6] 1.13.5 --- sop-admin/sop-admin-server/pom.xml | 2 +- sop-common/pom.xml | 2 +- sop-common/sop-gateway-common/pom.xml | 4 +-- sop-common/sop-registry-api/pom.xml | 2 +- sop-common/sop-service-common/pom.xml | 4 +-- sop-example/sop-auth/pom.xml | 2 +- sop-example/sop-book/sop-book-web/pom.xml | 2 +- sop-example/sop-easyopen/pom.xml | 2 +- sop-example/sop-springmvc/pom.xml | 2 +- sop-example/sop-story/sop-story-web/pom.xml | 2 +- .../storyweb/controller/AlipayController.java | 4 +-- .../controller/PostJsonController.java | 20 +++++++++++ sop-gateway/pom.xml | 2 +- .../com/gitee/sop/sdk/client/OpenHttp.java | 29 +++++++++++---- .../java/com/gitee/sop/test/HttpTool.java | 12 +++---- .../gitee/sop/test/AlipayClientPostTest.java | 31 ++++++++++++++++ .../java/com/gitee/sop/test/PostJsonTest.java | 36 ++++++++++++++++++- sop-website/website-server/pom.xml | 2 +- .../sop/websiteserver/bean/HttpTool.java | 15 ++++---- 19 files changed, 140 insertions(+), 35 deletions(-) diff --git a/sop-admin/sop-admin-server/pom.xml b/sop-admin/sop-admin-server/pom.xml index ff05f7e3..b74deaf0 100644 --- a/sop-admin/sop-admin-server/pom.xml +++ b/sop-admin/sop-admin-server/pom.xml @@ -30,7 +30,7 @@ com.gitee.sop sop-registry-api - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT diff --git a/sop-common/pom.xml b/sop-common/pom.xml index b504064c..b9474842 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT pom diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index 69d81f49..4944f39f 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -5,11 +5,11 @@ com.gitee.sop sop-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT ../pom.xml sop-gateway-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT jar sop-gateway-common diff --git a/sop-common/sop-registry-api/pom.xml b/sop-common/sop-registry-api/pom.xml index f3bfcbe7..f2aa4b67 100644 --- a/sop-common/sop-registry-api/pom.xml +++ b/sop-common/sop-registry-api/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-registry-api - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT UTF-8 diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index 2be58d1f..a0b12082 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -6,11 +6,11 @@ com.gitee.sop sop-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT ../pom.xml sop-service-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT jar sop-service-common diff --git a/sop-example/sop-auth/pom.xml b/sop-example/sop-auth/pom.xml index c16a2a0d..581fb460 100644 --- a/sop-example/sop-auth/pom.xml +++ b/sop-example/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index 04be1bc8..c1610423 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index d7422ed6..ce2fe39c 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-springmvc/pom.xml b/sop-example/sop-springmvc/pom.xml index 4652ae4f..84f68b37 100644 --- a/sop-example/sop-springmvc/pom.xml +++ b/sop-example/sop-springmvc/pom.xml @@ -20,7 +20,7 @@ com.gitee.sop sop-service-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index 254cbf45..c80b2131 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java index c22509cb..a04a59df 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java @@ -30,7 +30,7 @@ public class AlipayController { // http://localhost:2222/story_get // 原生的接口,可正常调用 @RequestMapping("story_get") - public Story getStory4() { + public Story story_get() { Story story = new Story(); story.setId(1); story.setName("海底小纵队(原生)"); @@ -117,7 +117,7 @@ public class AlipayController { // http://localhost:2222/getStory2?version=2.1 // 遗留接口具备开放平台能力,在原来的基础上加版本号 @ApiAbility(version = "2.1") - @RequestMapping("getStory2") + @GetMapping("getStory2") public Story getStory2_1() { Story story = new Story(); story.setId(1); diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java index 0bc5e45a..8bed5cf8 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java @@ -37,5 +37,25 @@ public class PostJsonController { return story; } + /** + * 演示客户端使用json方式请求(application/json) + * @param param + * @return + */ + @ApiMapping(value = "demo.post.json", version = "1.2") + public Story postJson2(StoryParam param) { + // 获取开放平台请求参数 + OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); + List params = Arrays.asList( + openContext.getAppId(), + openContext.getMethod(), + openContext.getVersion() + ); + Story story = new Story(); + story.setId(1); + story.setName("1.2 参数:" + param.getName() + ", openParams:" + StringUtils.join(params)); + return story; + } + } diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 43c550e8..617820af 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -23,7 +23,7 @@ com.gitee.sop sop-gateway-common - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT diff --git a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java index aed2ee6a..68aaf5d9 100644 --- a/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java +++ b/sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java @@ -118,7 +118,7 @@ public class OpenHttp { * @return * @throws IOException */ - public String request(String url, Map form, Map header, String method) throws IOException { + public String request(String url, Map form, Map header, HTTPMethod method) throws IOException { Request.Builder requestBuilder = buildRequestBuilder(url, form, method); // 添加header addHeader(requestBuilder, header); @@ -134,21 +134,21 @@ public class OpenHttp { } } - public static Request.Builder buildRequestBuilder(String url, Map form, String method) { + public static Request.Builder buildRequestBuilder(String url, Map form, HTTPMethod method) { switch (method) { - case "get": + case GET: return new Request.Builder() .url(buildHttpUrl(url, form)) .get(); - case "head": + case HEAD: return new Request.Builder() .url(buildHttpUrl(url, form)) .head(); - case "put": + case PUT: return new Request.Builder() .url(url) .put(buildFormBody(form)); - case "delete": + case DELETE: return new Request.Builder() .url(url) .delete(buildFormBody(form)); @@ -241,5 +241,22 @@ public class OpenHttp { this.httpClient = httpClient; } + public enum HTTPMethod { + GET, + POST, + PUT, + HEAD, + DELETE; + private HTTPMethod() { + } + + public String value() { + return this.name(); + } + + public static HTTPMethod fromValue(String v) { + return valueOf(v.toUpperCase()); + } + } } diff --git a/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java b/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java index 989382df..2409977d 100644 --- a/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java +++ b/sop-test/src/main/java/com/gitee/sop/test/HttpTool.java @@ -111,7 +111,7 @@ public class HttpTool { * @throws IOException */ public String request(String url, Map form, Map header, HTTPMethod method) throws IOException { - Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value()); + Request.Builder requestBuilder = buildRequestBuilder(url, form, method); // 添加header addHeader(requestBuilder, header); @@ -153,21 +153,21 @@ public class HttpTool { } } - public static Request.Builder buildRequestBuilder(String url, Map form, String method) { + public static Request.Builder buildRequestBuilder(String url, Map form, HTTPMethod method) { switch (method) { - case "get": + case GET: return new Request.Builder() .url(buildHttpUrl(url, form)) .get(); - case "head": + case HEAD: return new Request.Builder() .url(buildHttpUrl(url, form)) .head(); - case "put": + case PUT: return new Request.Builder() .url(url) .put(buildFormBody(form)); - case "delete": + case DELETE: return new Request.Builder() .url(url) .delete(buildFormBody(form)); diff --git a/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java b/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java index 640fb5e7..223734ff 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java @@ -231,4 +231,35 @@ public class AlipayClientPostTest extends TestBase { System.out.println(responseData); } + @Test + public void testGetStory2() throws AlipayApiException { + // 公共请求参数 + Map params = new HashMap(); + params.put("app_id", appId); + params.put("method", "getStory2"); + params.put("version", "1.0"); + params.put("format", "json"); + params.put("charset", "utf-8"); + params.put("sign_type", "RSA2"); + params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + // 业务参数 + Map bizContent = new HashMap<>(); + + params.put("biz_content", JSON.toJSONString(bizContent)); + + System.out.println("----------- 请求信息 -----------"); + System.out.println("请求参数:" + buildParamQuery(params)); + System.out.println("商户秘钥:" + privateKey); + String content = AlipaySignature.getSignContent(params); + System.out.println("待签名内容:" + content); + String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); + System.out.println("签名(sign):" + sign); + + params.put("sign", sign); + + System.out.println("----------- 返回结果 -----------"); + String responseData = get(url, params);// 发送请求 + System.out.println(responseData); + } + } diff --git a/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java b/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java index 308ef486..b40f1a67 100644 --- a/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java +++ b/sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java @@ -49,7 +49,41 @@ public class PostJsonTest extends TestBase { params.put("sign", sign); System.out.println("----------- 返回结果 -----------"); - String responseData = get(url, params);// 发送请求 + String responseData = postJson(url, params);// 发送请求 + System.out.println(responseData); + } + + @Test + public void testPostJson2() throws Exception { + + // 公共请求参数 + Map params = new HashMap(); + params.put("app_id", appId); + params.put("method", "demo.post.json"); + params.put("format", "json"); + params.put("charset", "utf-8"); + params.put("sign_type", "RSA2"); + params.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + params.put("version", "1.2"); + + // 业务参数 + Map bizContent = new HashMap<>(); + bizContent.put("name", "葫芦娃"); + + params.put("biz_content", JSON.toJSONString(bizContent)); + + System.out.println("----------- 请求信息 -----------"); + System.out.println("请求参数:" + buildParamQuery(params)); + System.out.println("商户秘钥:" + privateKey); + String content = AlipaySignature.getSignContent(params); + System.out.println("待签名内容:" + content); + String sign = AlipaySignature.rsa256Sign(content, privateKey, "utf-8"); + System.out.println("签名(sign):" + sign); + + params.put("sign", sign); + + System.out.println("----------- 返回结果 -----------"); + String responseData = postJson(url, params);// 发送请求 System.out.println(responseData); } diff --git a/sop-website/website-server/pom.xml b/sop-website/website-server/pom.xml index c9e62cf7..72a66b50 100644 --- a/sop-website/website-server/pom.xml +++ b/sop-website/website-server/pom.xml @@ -25,7 +25,7 @@ com.gitee.sop sop-registry-api - 1.13.4-SNAPSHOT + 1.13.5-SNAPSHOT diff --git a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java index 8e0cce0e..ee280d4f 100644 --- a/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java +++ b/sop-website/website-server/src/main/java/com/gitee/sop/websiteserver/bean/HttpTool.java @@ -111,7 +111,7 @@ public class HttpTool { * @throws IOException */ public String request(String url, Map form, Map header, HTTPMethod method) throws IOException { - Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value()); + Request.Builder requestBuilder = buildRequestBuilder(url, form, method); // 添加header addHeader(requestBuilder, header); @@ -153,21 +153,21 @@ public class HttpTool { } } - public static Request.Builder buildRequestBuilder(String url, Map form, String method) { + public static Request.Builder buildRequestBuilder(String url, Map form, HTTPMethod method) { switch (method) { - case "get": + case GET: return new Request.Builder() .url(buildHttpUrl(url, form)) .get(); - case "head": + case HEAD: return new Request.Builder() .url(buildHttpUrl(url, form)) .head(); - case "put": + case PUT: return new Request.Builder() .url(url) .put(buildFormBody(form)); - case "delete": + case DELETE: return new Request.Builder() .url(url) .delete(buildFormBody(form)); @@ -262,6 +262,9 @@ public class HttpTool { HEAD, DELETE; + private HTTPMethod() { + } + public String value() { return this.name(); } From a54cd90b283b815e25883341f113e7b58ef2b6aa Mon Sep 17 00:00:00 2001 From: tanghc Date: Mon, 5 Aug 2019 18:32:09 +0800 Subject: [PATCH 3/6] 1.13.5 --- changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/changelog.md b/changelog.md index 251584a7..a954581d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # changelog +## 1.13.5 + +- 修复postJson下version获取不到问题 + ## 1.13.4 - 修复admin服务列表最后更新时间不显示问题 From 1e54852a3e3b2ff523e0d63e6117f30240ea6513 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 6 Aug 2019 18:25:23 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=A2=84=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E3=80=81=E7=81=B0=E5=BA=A6=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sop/gatewaycommon/result/BaseExecutorAdapter.java | 5 +++++ .../servercommon/mapping/ApiMappingRequestCondition.java | 8 +------- .../test/java/com/gitee/sop/sopauth/RefreshTokenTest.java | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java index 4307e7c6..cd0c58f8 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/result/BaseExecutorAdapter.java @@ -37,6 +37,7 @@ public abstract class BaseExecutorAdapter implements ResultExecutor private static final ErrorMeta SUCCESS_META = ErrorEnum.SUCCESS.getErrorMeta(); private static final ErrorMeta ISP_UNKNOW_ERROR_META = ErrorEnum.ISP_UNKNOW_ERROR.getErrorMeta(); private static final ErrorMeta ISP_BIZ_ERROR = ErrorEnum.BIZ_ERROR.getErrorMeta(); + private static final ErrorMeta ISV_MISSING_METHOD_META = ErrorEnum.ISV_MISSING_METHOD.getErrorMeta(); public static final String GATEWAY_CODE_NAME = "code"; public static final String GATEWAY_MSG_NAME = "msg"; @@ -90,6 +91,10 @@ public abstract class BaseExecutorAdapter implements ResultExecutor responseData = JSON.parseObject(serviceResult); responseData.put(GATEWAY_CODE_NAME, ISP_BIZ_ERROR.getCode()); responseData.put(GATEWAY_MSG_NAME, ISP_BIZ_ERROR.getError().getMsg()); + } else if(responseStatus == HttpStatus.NOT_FOUND.value()) { + responseData = JSON.parseObject(serviceResult); + responseData.put(GATEWAY_CODE_NAME, ISV_MISSING_METHOD_META.getCode()); + responseData.put(GATEWAY_MSG_NAME, ISV_MISSING_METHOD_META.getError().getCode()); } else { this.storeError(request, ErrorType.UNKNOWN); // 微服务端有可能返回500错误 diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java index e6a2739c..c64ecadf 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java @@ -63,13 +63,7 @@ public class ApiMappingRequestCondition implements RequestCondition Date: Tue, 6 Aug 2019 20:14:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D@RequestBody=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E7=BB=91=E5=AE=9A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AlipayServiceConfiguration.java | 10 -------- .../param/ApiArgumentResolver.java | 24 ++++++++++++++++--- .../controller/PostJsonController.java | 3 ++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java index e35f9237..9525532b 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java @@ -3,11 +3,8 @@ package com.gitee.sop.servercommon.configuration; import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; -import java.util.List; - /** * 具备支付宝开放平台服务提供能力 * @author tanghc @@ -22,13 +19,6 @@ public class AlipayServiceConfiguration extends BaseServiceConfiguration { @Autowired private RequestMappingHandlerAdapter requestMappingHandlerAdapter; - @Override - protected void addArgumentResolvers(List argumentResolvers) { - super.addArgumentResolvers(argumentResolvers); - SopHandlerMethodArgumentResolver sopHandlerMethodArgumentResolver = ServiceConfig.getInstance().getMethodArgumentResolver(); - argumentResolvers.add(sopHandlerMethodArgumentResolver); - } - @Override protected void doAfter() { super.doAfter(); diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java index 38982d29..cc0660e1 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java @@ -17,12 +17,15 @@ import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; +import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** @@ -42,14 +45,29 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { @Override public void setRequestMappingHandlerAdapter(RequestMappingHandlerAdapter requestMappingHandlerAdapter) { this.requestMappingHandlerAdapter = requestMappingHandlerAdapter; + List argumentResolversNew = new ArrayList<>(64); + // 先加自己 + argumentResolversNew.add(this); + HandlerMethodArgumentResolver lastOne = null; + for (HandlerMethodArgumentResolver argumentResolver : Objects.requireNonNull(requestMappingHandlerAdapter.getArgumentResolvers())) { + // RequestResponseBodyMethodProcessor暂存起来,放在最后面 + if (argumentResolver instanceof RequestResponseBodyMethodProcessor) { + lastOne = argumentResolver; + } else { + argumentResolversNew.add(argumentResolver); + } + } + if (lastOne != null) { + argumentResolversNew.add(lastOne); + } + this.requestMappingHandlerAdapter.setArgumentResolvers(argumentResolversNew); } @Override public boolean supportsParameter(MethodParameter methodParameter) { - boolean hasAnnotation = methodParameter.getMethodAnnotation(ApiMapping.class) != null - || methodParameter.getMethodAnnotation(ApiAbility.class) != null; // 有注解 - return hasAnnotation; + return methodParameter.getMethodAnnotation(ApiMapping.class) != null + || methodParameter.getMethodAnnotation(ApiAbility.class) != null; } @Override diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java index 8bed5cf8..1be5d6d4 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java @@ -6,6 +6,7 @@ import com.gitee.sop.servercommon.bean.OpenContext; import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.storyweb.controller.param.StoryParam; import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.Arrays; @@ -23,7 +24,7 @@ public class PostJsonController { * @return */ @ApiMapping("demo.post.json") - public Story postJson(StoryParam param) { + public Story postJson(@RequestBody StoryParam param) { // 获取开放平台请求参数 OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); List params = Arrays.asList( From 22409fc3cc45e2e7155d654c8023911d2d7c67bc Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 6 Aug 2019 20:16:26 +0800 Subject: [PATCH 6/6] 1.13.6 --- changelog.md | 8 ++++++++ sop-admin/sop-admin-server/pom.xml | 2 +- sop-common/pom.xml | 2 +- sop-common/sop-gateway-common/pom.xml | 4 ++-- sop-common/sop-registry-api/pom.xml | 2 +- sop-common/sop-service-common/pom.xml | 4 ++-- sop-example/sop-auth/pom.xml | 2 +- sop-example/sop-book/sop-book-web/pom.xml | 2 +- sop-example/sop-easyopen/pom.xml | 2 +- sop-example/sop-springmvc/pom.xml | 2 +- sop-example/sop-story/sop-story-web/pom.xml | 2 +- sop-gateway/pom.xml | 2 +- sop-website/website-server/pom.xml | 2 +- 13 files changed, 22 insertions(+), 14 deletions(-) diff --git a/changelog.md b/changelog.md index 251584a7..20b59569 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ # changelog +## 1.13.6 + +- 修复@RequestBody不能绑定问题 + +## 1.13.5 + +- 修复postJson下version获取不到问题 + ## 1.13.4 - 修复admin服务列表最后更新时间不显示问题 diff --git a/sop-admin/sop-admin-server/pom.xml b/sop-admin/sop-admin-server/pom.xml index b74deaf0..ef289d11 100644 --- a/sop-admin/sop-admin-server/pom.xml +++ b/sop-admin/sop-admin-server/pom.xml @@ -30,7 +30,7 @@ com.gitee.sop sop-registry-api - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT diff --git a/sop-common/pom.xml b/sop-common/pom.xml index b9474842..b72dd887 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT pom diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index 4944f39f..ab38b6f5 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -5,11 +5,11 @@ com.gitee.sop sop-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT ../pom.xml sop-gateway-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT jar sop-gateway-common diff --git a/sop-common/sop-registry-api/pom.xml b/sop-common/sop-registry-api/pom.xml index f2aa4b67..90bac2f2 100644 --- a/sop-common/sop-registry-api/pom.xml +++ b/sop-common/sop-registry-api/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-registry-api - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT UTF-8 diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index a0b12082..2b409d4e 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -6,11 +6,11 @@ com.gitee.sop sop-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT ../pom.xml sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT jar sop-service-common diff --git a/sop-example/sop-auth/pom.xml b/sop-example/sop-auth/pom.xml index 581fb460..07e5753c 100644 --- a/sop-example/sop-auth/pom.xml +++ b/sop-example/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index c1610423..8be2be93 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index ce2fe39c..068140c1 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-springmvc/pom.xml b/sop-example/sop-springmvc/pom.xml index 84f68b37..d02be1c7 100644 --- a/sop-example/sop-springmvc/pom.xml +++ b/sop-example/sop-springmvc/pom.xml @@ -20,7 +20,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index c80b2131..7c9a7766 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT com.gitee.sop diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 617820af..e69d3a3c 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -23,7 +23,7 @@ com.gitee.sop sop-gateway-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT diff --git a/sop-website/website-server/pom.xml b/sop-website/website-server/pom.xml index 72a66b50..c3f183e9 100644 --- a/sop-website/website-server/pom.xml +++ b/sop-website/website-server/pom.xml @@ -25,7 +25,7 @@ com.gitee.sop sop-registry-api - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT