Skip to content

Commit 41b5ee7

Browse files
authored
Merge pull request #24 from jpush/dev
Dev
2 parents 9f8fd25 + dfda631 commit 41b5ee7

File tree

7 files changed

+62
-52
lines changed

7 files changed

+62
-52
lines changed

.classpath

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<attributes>
1111
<attribute name="optional" value="true"/>
1212
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
1314
</attributes>
1415
</classpathentry>
1516
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@@ -21,6 +22,27 @@
2122
<classpathentry kind="lib" path="libs/log4j-1.2.17.jar"/>
2223
<classpathentry kind="lib" path="libs/slf4j-api-1.7.7.jar"/>
2324
<classpathentry kind="lib" path="libs/slf4j-log4j12-1.7.7.jar"/>
24-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="src" path="target/generated-sources/annotations">
31+
<attributes>
32+
<attribute name="optional" value="true"/>
33+
<attribute name="maven.pomderived" value="true"/>
34+
<attribute name="ignore_optional_problems" value="true"/>
35+
<attribute name="m2e-apt" value="true"/>
36+
</attributes>
37+
</classpathentry>
38+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
39+
<attributes>
40+
<attribute name="optional" value="true"/>
41+
<attribute name="maven.pomderived" value="true"/>
42+
<attribute name="ignore_optional_problems" value="true"/>
43+
<attribute name="m2e-apt" value="true"/>
44+
<attribute name="test" value="true"/>
45+
</attributes>
46+
</classpathentry>
2547
<classpathentry kind="output" path="target/classes"/>
2648
</classpath>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void testSendPushWithCallback() {
6161
<dependency>
6262
<groupId>cn.jpush.api</groupId>
6363
<artifactId>jiguang-common</artifactId>
64-
<version>1.1.3</version>
64+
<version>1.1.4</version>
6565
</dependency>
6666
<dependency>
6767
<groupId>com.google.code.gson</groupId>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>cn.jpush.api</groupId>
55
<artifactId>jiguang-common</artifactId>
6-
<version>1.1.4-SNAPSHOT</version>
6+
<version>1.1.5-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<url>https://github.com/jpush/jiguang-java-client-common</url>
99
<name>Jiguang Client Common Dependencies</name>
@@ -34,7 +34,7 @@
3434
<url>https://github.com/jpush/jiguang-java-client-common</url>
3535
<connection>scm:git:[email protected]:jpush/jiguang-java-client-common.git</connection>
3636
<developerConnection>scm:git:[email protected]:jpush/jiguang-java-client-common.git</developerConnection>
37-
<tag>jiguang-common-1.1.3</tag>
37+
<tag>jiguang-common-1.1.4</tag>
3838
</scm>
3939

4040
<dependencies>

src/main/java/cn/jiguang/common/ClientConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cn.jiguang.common;
22

33
import java.util.HashMap;
4-
import java.util.Observable;
54

65
public class ClientConfig extends HashMap<String, Object> {
76

src/main/java/cn/jiguang/common/connection/ApacheHttpClient.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,15 @@ public ResponseWrapper sendGet(String url) throws APIConnectionException, APIReq
211211
processResponse(response, wrapper);
212212
} catch (IOException e) {
213213
httpGet.abort();
214-
e.printStackTrace();
214+
LOG.debug(IO_ERROR_MESSAGE, e);
215+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
215216
} finally {
216217
try {
217218
if (response != null) {
218219
response.close();
219220
}
220221
} catch (IOException e) {
221-
e.printStackTrace();
222+
e.printStackTrace();
222223
}
223224
}
224225
return wrapper;
@@ -238,14 +239,15 @@ public ResponseWrapper sendGet(String url, String content)
238239
processResponse(response, wrapper);
239240
} catch (IOException e) {
240241
httpGet.abort();
241-
e.printStackTrace();
242+
LOG.debug(IO_ERROR_MESSAGE, e);
243+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
242244
} finally {
243245
try {
244246
if (response != null) {
245247
response.close();
246248
}
247249
} catch (IOException e) {
248-
e.printStackTrace();
250+
e.printStackTrace();
249251
}
250252
}
251253
return wrapper;
@@ -263,14 +265,15 @@ public ResponseWrapper sendDelete(String url) throws APIConnectionException, API
263265
processResponse(response, wrapper);
264266
} catch (IOException e) {
265267
httpDelete.abort();
266-
e.printStackTrace();
268+
LOG.debug(IO_ERROR_MESSAGE, e);
269+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
267270
} finally {
268271
try {
269272
if (response != null) {
270273
response.close();
271274
}
272275
} catch (IOException e) {
273-
e.printStackTrace();
276+
e.printStackTrace();
274277
}
275278
}
276279
return wrapper;
@@ -289,14 +292,15 @@ public ResponseWrapper sendDelete(String url, String content)
289292
processResponse(response, wrapper);
290293
} catch (IOException e) {
291294
httpDelete.abort();
292-
e.printStackTrace();
295+
LOG.debug(IO_ERROR_MESSAGE, e);
296+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
293297
} finally {
294298
try {
295299
if (response != null) {
296300
response.close();
297301
}
298302
} catch (IOException e) {
299-
e.printStackTrace();
303+
e.printStackTrace();
300304
}
301305
}
302306
return wrapper;
@@ -317,14 +321,15 @@ public ResponseWrapper sendPost(String url, String content) throws APIConnection
317321
processResponse(response, wrapper);
318322
} catch (IOException e) {
319323
httpPost.abort();
320-
e.printStackTrace();
324+
LOG.debug(IO_ERROR_MESSAGE, e);
325+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
321326
} finally {
322327
try {
323328
if (response != null) {
324329
response.close();
325330
}
326331
} catch (IOException e) {
327-
e.printStackTrace();
332+
e.printStackTrace();
328333
}
329334
}
330335
return wrapper;
@@ -346,14 +351,15 @@ public ResponseWrapper sendPut(String url, String content) throws APIConnectionE
346351
processResponse(response, wrapper);
347352
} catch (IOException e) {
348353
httpPut.abort();
349-
e.printStackTrace();
354+
LOG.debug(IO_ERROR_MESSAGE, e);
355+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
350356
} finally {
351357
try {
352358
if (response != null) {
353359
response.close();
354360
}
355361
} catch (IOException e) {
356-
e.printStackTrace();
362+
e.printStackTrace();
357363
}
358364
}
359365
return wrapper;
@@ -391,14 +397,15 @@ public ResponseWrapper uploadFile(String url, String path, String fileType) thro
391397
response = getHttpClient(url).execute(httpPost);
392398
processResponse(response, wrapper);
393399
} catch (IOException e) {
394-
e.printStackTrace();
400+
LOG.debug(IO_ERROR_MESSAGE, e);
401+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
395402
} finally {
396403
try {
397404
if (response != null) {
398405
response.close();
399406
}
400407
} catch (IOException e) {
401-
e.printStackTrace();
408+
e.printStackTrace();
402409
}
403410
}
404411
return wrapper;

src/main/java/cn/jiguang/common/connection/HttpResponseHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cn.jiguang.common.connection;
22

3-
import cn.jiguang.common.resp.APIConnectionException;
4-
import cn.jiguang.common.resp.APIRequestException;
53
import cn.jiguang.common.resp.ResponseWrapper;
64
import io.netty.channel.ChannelHandler;
75
import io.netty.channel.ChannelHandlerContext;

src/main/java/cn/jiguang/common/connection/NettyHttpClient.java

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,17 @@ public ResponseWrapper sendGet(String url) throws APIConnectionException, APIReq
109109
}
110110

111111
public ResponseWrapper sendGet(String url, String content) throws APIConnectionException, APIRequestException {
112-
ResponseWrapper wrapper = new ResponseWrapper();
113-
try {
114-
return sendHttpRequest(HttpMethod.GET, url, content);
115-
} catch (URISyntaxException e) {
116-
e.printStackTrace();
117-
}
118-
return wrapper;
112+
return sendHttpRequest(HttpMethod.GET, url, content);
119113
}
120114

121115
@Override
122116
public ResponseWrapper sendPut(String url, String content) throws APIConnectionException, APIRequestException {
123-
ResponseWrapper wrapper = new ResponseWrapper();
124-
try {
125-
return sendHttpRequest(HttpMethod.PUT, url, content);
126-
} catch (URISyntaxException e) {
127-
e.printStackTrace();
128-
}
129-
return wrapper;
117+
return sendHttpRequest(HttpMethod.PUT, url, content);
130118
}
131119

132120
@Override
133121
public ResponseWrapper sendPost(String url, String content) throws APIConnectionException, APIRequestException {
134-
ResponseWrapper wrapper = new ResponseWrapper();
135-
try {
136-
return sendHttpRequest(HttpMethod.POST, url, content);
137-
} catch (URISyntaxException e) {
138-
e.printStackTrace();
139-
}
140-
return wrapper;
122+
return sendHttpRequest(HttpMethod.POST, url, content);
141123
}
142124

143125
@Override
@@ -146,24 +128,25 @@ public ResponseWrapper sendDelete(String url) throws APIConnectionException, API
146128
}
147129

148130
public ResponseWrapper sendDelete(String url, String content) throws APIConnectionException, APIRequestException {
149-
ResponseWrapper wrapper = new ResponseWrapper();
150-
try {
151-
return sendHttpRequest(HttpMethod.DELETE, url, content);
152-
} catch (URISyntaxException e) {
153-
e.printStackTrace();
154-
}
155-
return wrapper;
131+
return sendHttpRequest(HttpMethod.DELETE, url, content);
156132
}
157133

158134

159135

160136
private ResponseWrapper sendHttpRequest(HttpMethod method, String url, String body) throws APIConnectionException,
161-
APIRequestException, URISyntaxException {
137+
APIRequestException{
162138
CountDownLatch latch = new CountDownLatch(1);
163139
NettyClientInitializer initializer = new NettyClientInitializer(_sslCtx, null, latch);
164140
b.handler(initializer);
165141
ResponseWrapper wrapper = new ResponseWrapper();
166-
URI uri = new URI(url);
142+
URI uri = null;
143+
try {
144+
uri = new URI(url);
145+
} catch (URISyntaxException e1) {
146+
// TODO Auto-generated catch block
147+
LOG.debug(IO_ERROR_MESSAGE, e1);
148+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e1, true);
149+
}
167150
String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
168151
String host = uri.getHost() == null ? "127.0.0.1" : uri.getHost();
169152
int port = uri.getPort();
@@ -243,7 +226,8 @@ private ResponseWrapper sendHttpRequest(HttpMethod method, String url, String bo
243226
throw new APIRequestException(wrapper);
244227
}
245228
} catch (InterruptedException e) {
246-
e.printStackTrace();
229+
LOG.debug(IO_ERROR_MESSAGE, e);
230+
throw new APIConnectionException(READ_TIMED_OUT_MESSAGE, e, true);
247231
}
248232
return wrapper;
249233
}

0 commit comments

Comments
 (0)