Skip to content

Commit 1581c14

Browse files
authored
Merge pull request #21 from lexiLiu/1.0.0.6
[fix]
2 parents 8ec457e + a08c703 commit 1581c14

6 files changed

Lines changed: 102 additions & 59 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release Notes
22

3+
## 1.0.0.6
4+
### Fix
5+
修复并发请求消息体异常问题
6+
37
## 1.0.0.5
48
### Fix
59
修复长连接单位错误问题 由分钟改为秒

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>com.getui.push</groupId>
88
<artifactId>restful-sdk</artifactId>
99
<packaging>jar</packaging>
10-
<version>1.0.0.5</version>
10+
<version>1.0.0.6</version>
1111
<url>https://github.com/GetuiLaboratory/getui-pushapi-java-client-v2</url>
1212
<name>Getui Push API Java Client</name>
1313
<description>Getui's officially supported Java client library for accessing Getui APIs.</description>

src/main/java/com/getui/push/v2/sdk/common/http/HttpManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public class HttpManager {
2121
* @param maxHttpTryTime 失败最大尝试次数
2222
* @param trustSSL
2323
*/
24-
public HttpManager(int connectionTimeOut, int readTimeout, int maxHttpTryTime, long keepAliveMinutes, GtHttpProxyConfig proxyConfig, boolean trustSSL) {
25-
this.client = new GtHttpClient(connectionTimeOut, readTimeout, maxHttpTryTime, keepAliveMinutes, proxyConfig, trustSSL);
24+
public HttpManager(int connectionTimeOut, int readTimeout, int maxHttpTryTime, long keepAliveSeconds, GtHttpProxyConfig proxyConfig, boolean trustSSL) {
25+
this.client = new GtHttpClient(connectionTimeOut, readTimeout, maxHttpTryTime, keepAliveSeconds, proxyConfig, trustSSL);
2626
}
2727

2828
public String syncHttps(String url, String method, Map<String, Object> headers, String body, String contentType) {

src/main/java/com/getui/push/v2/sdk/core/factory/GtApiProxyFactory.java

Lines changed: 77 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public Object invoke(Object proxy, Method method, Object[] args) {
7979
if ("toString".equalsIgnoreCase(method.getName()) && Utils.isEmpty(args)) {
8080
return this.toString();
8181
}
82-
ApiParam apiParam = gtApiRegistry.get(method);
82+
final BaseParam baseParam = gtApiRegistry.get(method);
83+
ApiParam apiParam = new ApiParam(baseParam);
8384
// 解析参数 -> HTTP参数
8485
handleApiParam(method, args, apiParam);
8586
return defaultApiClient.execute(apiParam);
@@ -115,24 +116,12 @@ public void close() {
115116
cache.remove(this.defaultApiClient);
116117
}
117118

118-
/**
119-
* HTTP请求的参数
120-
*/
121119
public static class ApiParam {
122-
/**
123-
* 接口调用相对路径
124-
* eg. /auth
125-
*/
126-
private String uri;
127-
/**
128-
* 接口请求方式 GET/POST/PUT/DELETE
129-
*/
130-
private String method;
120+
private final BaseParam baseParam;
131121
/**
132122
* 路径参数
133123
*/
134124
private String pathParams;
135-
136125
/**
137126
* query参数
138127
*/
@@ -141,14 +130,10 @@ public static class ApiParam {
141130
* body参数
142131
*/
143132
private Object body;
144-
/**
145-
* 是否需要token
146-
*/
147-
private Boolean needToken;
148-
/**
149-
* 返回值类型
150-
*/
151-
private Type returnType;
133+
134+
public ApiParam(BaseParam baseParam) {
135+
this.baseParam = baseParam;
136+
}
152137

153138
/**
154139
* 处理路径参数
@@ -160,19 +145,19 @@ public void handlePathParam(Object arg) {
160145
setPathParams(handleArg(arg));
161146
}
162147

163-
public void handleQueryParam(Object arg, String name) {
164-
Assert.notNull(arg, "query参数");
165-
final String param = handleArg(arg);
166-
addQueryParams(name, param);
167-
}
168-
169148
private void addQueryParams(String name, String param) {
170149
if (queryParams == null) {
171150
queryParams = new ArrayList<String>();
172151
}
173152
queryParams.add(name + "=" + param);
174153
}
175154

155+
public void handleQueryParam(Object arg, String name) {
156+
Assert.notNull(arg, "query参数");
157+
final String param = handleArg(arg);
158+
addQueryParams(name, param);
159+
}
160+
176161
private String handleArg(Object arg) {
177162
if (arg instanceof Iterable) {
178163
final Iterator iterator = ((Iterable) arg).iterator();
@@ -195,19 +180,23 @@ private String handleArg(Object arg) {
195180
}
196181

197182
public String getUri() {
198-
return uri;
183+
return baseParam.getUri();
199184
}
200185

201-
public void setUri(String uri) {
202-
this.uri = uri;
186+
public String getMethod() {
187+
return baseParam.getMethod();
203188
}
204189

205-
public String getMethod() {
206-
return method;
190+
public Boolean getNeedToken() {
191+
return baseParam.getNeedToken();
207192
}
208193

209-
public void setMethod(String method) {
210-
this.method = method;
194+
public Type getReturnType() {
195+
return baseParam.getReturnType();
196+
}
197+
198+
public BaseParam getBaseParam() {
199+
return baseParam;
211200
}
212201

213202
public String getPathParams() {
@@ -234,6 +223,58 @@ public void setBody(Object body) {
234223
this.body = body;
235224
}
236225

226+
227+
@Override
228+
public String toString() {
229+
final StringBuilder sb = new StringBuilder("ApiParam{");
230+
sb.append("baseParam=").append(baseParam);
231+
sb.append(", pathParams='").append(pathParams).append('\'');
232+
sb.append(", queryParams=").append(queryParams);
233+
sb.append(", body=").append(body);
234+
sb.append('}');
235+
return sb.toString();
236+
}
237+
}
238+
239+
/**
240+
* HTTP请求的参数
241+
*/
242+
public static class BaseParam {
243+
/**
244+
* 接口调用相对路径
245+
* eg. /auth
246+
*/
247+
private String uri;
248+
/**
249+
* 接口请求方式 GET/POST/PUT/DELETE
250+
*/
251+
private String method;
252+
253+
/**
254+
* 是否需要token
255+
*/
256+
private Boolean needToken;
257+
/**
258+
* 返回值类型
259+
*/
260+
private Type returnType;
261+
262+
public String getUri() {
263+
return uri;
264+
}
265+
266+
public void setUri(String uri) {
267+
this.uri = uri;
268+
}
269+
270+
public String getMethod() {
271+
return method;
272+
}
273+
274+
public void setMethod(String method) {
275+
this.method = method;
276+
}
277+
237278
public Boolean getNeedToken() {
238279
return needToken;
239280
}
@@ -252,11 +293,9 @@ public void setReturnType(Type returnType) {
252293

253294
@Override
254295
public String toString() {
255-
return "ApiParam{" +
296+
return "BaseParam{" +
256297
"uri='" + uri + '\'' +
257298
", method='" + method + '\'' +
258-
", pathParams='" + pathParams + '\'' +
259-
", body=" + body +
260299
", needToken=" + needToken +
261300
", returnType=" + returnType +
262301
'}';

src/main/java/com/getui/push/v2/sdk/core/registry/DefaultGtApiRegistry.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,39 @@
2424
*/
2525
public class DefaultGtApiRegistry implements GtApiRegistry {
2626

27-
private Map<String, GtApiProxyFactory.ApiParam> cache = new ConcurrentHashMap<String, GtApiProxyFactory.ApiParam>();
27+
private Map<String, GtApiProxyFactory.BaseParam> cache = new ConcurrentHashMap<String, GtApiProxyFactory.BaseParam>();
2828

2929
@Override
3030
public void register(Method method) {
3131
get(method);
3232
}
3333

3434
@Override
35-
public GtApiProxyFactory.ApiParam get(Method method) {
36-
GtApiProxyFactory.ApiParam apiParam = cache.get(method.toString());
37-
if (apiParam != null) {
38-
return apiParam;
35+
public GtApiProxyFactory.BaseParam get(Method method) {
36+
GtApiProxyFactory.BaseParam param = cache.get(method.toString());
37+
if (param != null) {
38+
return param;
3939
}
4040
synchronized (cache) {
41-
apiParam = cache.get(method.toString());
42-
if (apiParam != null) {
43-
return apiParam;
41+
param = cache.get(method.toString());
42+
if (param != null) {
43+
return param;
4444
}
45-
apiParam = doAnalise(method);
46-
cache.put(method.toString(), apiParam);
47-
return apiParam;
45+
param = doAnalise(method);
46+
cache.put(method.toString(), param);
47+
return param;
4848
}
4949
}
5050

51-
private GtApiProxyFactory.ApiParam doAnalise(Method method) {
52-
GtApiProxyFactory.ApiParam apiParam = new GtApiProxyFactory.ApiParam();
51+
private GtApiProxyFactory.BaseParam doAnalise(Method method) {
52+
GtApiProxyFactory.BaseParam param = new GtApiProxyFactory.BaseParam();
5353
// 解析方法注解 -> HTTP请求方式和uri
54-
handleAnnotation(method.getAnnotations(), apiParam);
54+
handleAnnotation(method.getAnnotations(), param);
5555
// 获取泛型类型,用于反序列化使用
5656
Type[] types = ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments();
5757
// 设置返回值类型,用于反序列化
58-
apiParam.setReturnType(new GtTypeHelper(method.getReturnType(), types).getType());
59-
return apiParam;
58+
param.setReturnType(new GtTypeHelper(method.getReturnType(), types).getType());
59+
return param;
6060
}
6161

6262
/**
@@ -84,7 +84,7 @@ public Type getType() {
8484
* @param annotations
8585
* @param apiParam notnull
8686
*/
87-
private GtApiProxyFactory.ApiParam handleAnnotation(Annotation[] annotations, GtApiProxyFactory.ApiParam apiParam) {
87+
private GtApiProxyFactory.BaseParam handleAnnotation(Annotation[] annotations, GtApiProxyFactory.BaseParam apiParam) {
8888
if (apiParam == null) {
8989
throw new ApiException("apiParam cannot be null.");
9090
}

src/main/java/com/getui/push/v2/sdk/core/registry/GtApiRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public interface GtApiRegistry {
2424
* @param method 方法
2525
* @return
2626
*/
27-
GtApiProxyFactory.ApiParam get(Method method);
27+
GtApiProxyFactory.BaseParam get(Method method);
2828

2929
}

0 commit comments

Comments
 (0)