Merge branch 'master' into develop

# Conflicts:
#	changelog.md
#	sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java
#	sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/HttpTool.java
#	sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java
#	sop-test/src/main/java/com/gitee/sop/test/HttpTool.java
#	sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java
1.x
tanghc 5 years ago
commit 8718284dc3
  1. 4
      changelog.md
  2. 2
      sop-admin/sop-admin-server/pom.xml
  3. 2
      sop-common/pom.xml
  4. 4
      sop-common/sop-gateway-common/pom.xml
  5. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/gateway/param/GatewayParamBuilder.java
  6. 9
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/BaseParamBuilder.java
  7. 2
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/param/ParamNames.java
  8. 5
      sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/zuul/param/ZuulParamBuilder.java
  9. 2
      sop-common/sop-registry-api/pom.xml
  10. 28
      sop-common/sop-registry-api/src/main/java/com/gitee/sop/registryapi/bean/HttpTool.java
  11. 4
      sop-common/sop-service-common/pom.xml
  12. 2
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ParamNames.java
  13. 7
      sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingRequestCondition.java
  14. 2
      sop-example/sop-auth/pom.xml
  15. 2
      sop-example/sop-book/sop-book-web/pom.xml
  16. 2
      sop-example/sop-easyopen/pom.xml
  17. 2
      sop-example/sop-springmvc/pom.xml
  18. 2
      sop-example/sop-story/sop-story-web/pom.xml
  19. 4
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/AlipayController.java
  20. 20
      sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java
  21. 2
      sop-gateway/pom.xml
  22. 29
      sop-sdk/sdk-java/src/main/java/com/gitee/sop/sdk/client/OpenHttp.java
  23. 26
      sop-test/src/main/java/com/gitee/sop/test/HttpTool.java
  24. 2
      sop-test/src/test/java/com/gitee/sop/test/AlipayClientPostTest.java
  25. 36
      sop-test/src/test/java/com/gitee/sop/test/PostJsonTest.java
  26. 2
      sop-website/website-server/pom.xml

@ -4,6 +4,10 @@
- 支持预发布、灰度发布环境
## 1.13.5
- 修复postJson下version获取不到问题
## 1.13.4
- 修复admin服务列表最后更新时间不显示问题

@ -32,7 +32,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<!-- easyopen starter -->

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

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

@ -22,4 +22,9 @@ public class GatewayParamBuilder extends BaseParamBuilder<ServerWebExchange> {
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);
}
}

@ -31,6 +31,14 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
*/
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);
@ -38,6 +46,7 @@ public abstract class BaseParamBuilder<T> implements ParamBuilder<T> {
apiParam.putAll(requestParams);
this.initOtherProperty(apiParam);
apiParam.setIp(this.getIP(ctx));
this.setVersionInHeader(ctx, ParamNames.HEADER_VERSION_NAME, apiParam.fetchVersion());
return apiParam;
}

@ -45,7 +45,7 @@ public class ParamNames {
/** 返回sign名称 */
public static String RESPONSE_SIGN_NAME = "sign";
public static String GRAY_HEADER_VERSION_NAME = "sop_gray_version";
public static String HEADER_VERSION_NAME = "sop-version";
}

@ -52,6 +52,11 @@ public class ZuulParamBuilder extends BaseParamBuilder<RequestContext> {
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);

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

@ -1,4 +1,4 @@
package com.gitee.sop.registryapi.bean;
package com.gitee.sop.websiteserver.bean;
import lombok.Data;
import lombok.Getter;
@ -110,8 +110,8 @@ public class HttpTool {
* @return
* @throws IOException
*/
public String request(String url, Map<String, ?> form, Map<String, String> header, HTTPMethod method) throws IOException {
Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value());
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
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<String, ?> form, String method) {
public static Request.Builder buildRequestBuilder(String url, Map<String, String> 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));
@ -178,18 +178,18 @@ public class HttpTool {
}
}
public static HttpUrl buildHttpUrl(String url, Map<String, ?> form) {
public static HttpUrl buildHttpUrl(String url, Map<String, String> form) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
for (Map.Entry<String, ?> entry : form.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), String.valueOf(entry.getValue()));
for (Map.Entry<String, String> entry : form.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
return urlBuilder.build();
}
public static FormBody buildFormBody(Map<String, ?> form) {
public static FormBody buildFormBody(Map<String, String> form) {
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
for (Map.Entry<String, ?> entry : form.entrySet()) {
paramBuilder.add(entry.getKey(), String.valueOf(entry.getValue()));
for (Map.Entry<String, String> entry : form.entrySet()) {
paramBuilder.add(entry.getKey(), entry.getValue());
}
return paramBuilder.build();
}

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

@ -47,5 +47,7 @@ public class ParamNames {
/** 时间戳格式 */
public static String TIMESTAMP_PATTERN = "yyyy-MM-dd HH:mm:ss";
public static String HEADER_VERSION_NAME = "sop-version";
}

@ -45,11 +45,10 @@ public class ApiMappingRequestCondition implements RequestCondition<ApiMappingRe
}
protected String getVersion(HttpServletRequest request) {
String versionInHeader = request.getHeader(ParamNames.HEADER_VERSION_NAME);
if (versionInHeader != null) {
return versionInHeader;
String version = request.getHeader(ParamNames.HEADER_VERSION_NAME);
if (version == null) {
version = request.getParameter(ParamNames.VERSION_NAME);
}
String version = request.getParameter(ParamNames.VERSION_NAME);
return version == null ? defaultVersion : version;
}

@ -26,7 +26,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

@ -24,7 +24,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -29,7 +29,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

@ -20,7 +20,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<!-- eureka 服务发现 -->
<dependency>

@ -24,7 +24,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-service-common</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.gitee.sop</groupId>

@ -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);

@ -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<Object> 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;
}
}

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

@ -118,7 +118,7 @@ public class OpenHttp {
* @return
* @throws IOException
*/
public String request(String url, Map<String, String> form, Map<String, String> header, String method) throws IOException {
public String request(String url, Map<String, String> form, Map<String, String> 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<String, String> form, String method) {
public static Request.Builder buildRequestBuilder(String url, Map<String, String> 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());
}
}
}

@ -110,8 +110,8 @@ public class HttpTool {
* @return
* @throws IOException
*/
public String request(String url, Map<String, ?> form, Map<String, String> header, HTTPMethod method) throws IOException {
Request.Builder requestBuilder = buildRequestBuilder(url, form, method.value());
public String request(String url, Map<String, String> form, Map<String, String> header, HTTPMethod method) throws IOException {
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<String, ?> form, String method) {
public static Request.Builder buildRequestBuilder(String url, Map<String, String> 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));
@ -178,18 +178,18 @@ public class HttpTool {
}
}
public static HttpUrl buildHttpUrl(String url, Map<String, ?> form) {
public static HttpUrl buildHttpUrl(String url, Map<String, String> form) {
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
for (Map.Entry<String, ?> entry : form.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), String.valueOf(entry.getValue()));
for (Map.Entry<String, String> entry : form.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
}
return urlBuilder.build();
}
public static FormBody buildFormBody(Map<String, ?> form) {
public static FormBody buildFormBody(Map<String, String> form) {
FormBody.Builder paramBuilder = new FormBody.Builder(StandardCharsets.UTF_8);
for (Map.Entry<String, ?> entry : form.entrySet()) {
paramBuilder.add(entry.getKey(), String.valueOf(entry.getValue()));
for (Map.Entry<String, String> entry : form.entrySet()) {
paramBuilder.add(entry.getKey(), entry.getValue());
}
return paramBuilder.build();
}

@ -232,7 +232,7 @@ public class AlipayClientPostTest extends TestBase {
}
@Test
public void testApiAbility() throws AlipayApiException {
public void testGetStory2() throws AlipayApiException {
// 公共请求参数
Map<String, String> params = new HashMap<String, String>();
params.put("app_id", appId);

@ -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<String, String> params = new HashMap<String, String>();
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<String, String> 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);
}

@ -25,7 +25,7 @@
<dependency>
<groupId>com.gitee.sop</groupId>
<artifactId>sop-registry-api</artifactId>
<version>1.13.4-SNAPSHOT</version>
<version>1.13.5-SNAPSHOT</version>
</dependency>
<dependency>

Loading…
Cancel
Save