Skip to content

Commit 7d25169

Browse files
committed
Merge pull request #25 from Liuchy1/master
modify jpush common
2 parents 84f4043 + 2522fe4 commit 7d25169

File tree

4 files changed

+46
-42
lines changed

4 files changed

+46
-42
lines changed

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>jpush-client</artifactId>
6-
<version>3.2.6-SNAPSHOT</version>
6+
<version>3.2.7-SNAPSHOT</version>
77
<packaging>jar</packaging>
88
<url>https://github.com/jpush/jpush-api-java-client</url>
99
<name>JPush API Java Client</name>
@@ -35,7 +35,7 @@
3535
<url>https://github.com/jpush/jpush-api-java-client</url>
3636
<connection>scm:git:git@github.com:jpush/jpush-api-java-client.git</connection>
3737
<developerConnection>scm:git:git@github.com:jpush/jpush-api-java-client.git</developerConnection>
38-
<tag>v3.1.1</tag>
38+
<tag>v3.2.6</tag>
3939
</scm>
4040

4141
<dependencies>

src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
package cn.jpush.api.common.connection;
22

3+
import cn.jpush.api.common.resp.APIConnectionException;
4+
import cn.jpush.api.common.resp.APIRequestException;
5+
import cn.jpush.api.common.resp.ResponseWrapper;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import javax.net.ssl.*;
310
import java.io.IOException;
411
import java.io.InputStream;
512
import java.io.InputStreamReader;
613
import java.io.OutputStream;
7-
import java.net.Authenticator;
8-
import java.net.HttpURLConnection;
9-
import java.net.PasswordAuthentication;
10-
import java.net.SocketTimeoutException;
11-
import java.net.URL;
14+
import java.net.*;
1215
import java.security.cert.CertificateException;
1316
import java.security.cert.X509Certificate;
1417

15-
import javax.net.ssl.HostnameVerifier;
16-
import javax.net.ssl.HttpsURLConnection;
17-
import javax.net.ssl.SSLContext;
18-
import javax.net.ssl.SSLSession;
19-
import javax.net.ssl.TrustManager;
20-
import javax.net.ssl.X509TrustManager;
21-
22-
import org.slf4j.Logger;
23-
import org.slf4j.LoggerFactory;
24-
25-
import cn.jpush.api.common.resp.APIConnectionException;
26-
import cn.jpush.api.common.resp.APIRequestException;
27-
import cn.jpush.api.common.resp.ResponseWrapper;
28-
2918
/**
3019
* The implementation has no connection pool mechanism, used origin java connection.
3120
*
@@ -68,13 +57,23 @@ public NativeHttpClient(String authCode, int maxRetryTimes, HttpProxy proxy) {
6857

6958
public ResponseWrapper sendGet(String url)
7059
throws APIConnectionException, APIRequestException {
71-
return doRequest(url, null, RequestMethod.GET);
60+
return sendGet(url, null);
61+
}
62+
63+
public ResponseWrapper sendGet(String url, String content)
64+
throws APIConnectionException, APIRequestException {
65+
return doRequest(url, content, RequestMethod.GET);
7266
}
7367

7468
public ResponseWrapper sendDelete(String url)
7569
throws APIConnectionException, APIRequestException {
76-
return doRequest(url, null, RequestMethod.DELETE);
70+
return sendDelete(url, null);
7771
}
72+
73+
public ResponseWrapper sendDelete(String url, String content)
74+
throws APIConnectionException, APIRequestException {
75+
return doRequest(url, content, RequestMethod.DELETE);
76+
}
7877

7978
public ResponseWrapper sendPost(String url, String content)
8079
throws APIConnectionException, APIRequestException {
@@ -117,7 +116,6 @@ private ResponseWrapper _doRequest(String url, String content,
117116
if (null != content) {
118117
LOG.debug("Request Content - " + content);
119118
}
120-
121119
HttpURLConnection conn = null;
122120
OutputStream out = null;
123121
StringBuffer sb = new StringBuffer();
@@ -146,17 +144,15 @@ private ResponseWrapper _doRequest(String url, String content,
146144
conn.setRequestProperty("Authorization", _authCode);
147145
conn.setRequestProperty("Content-Type", CONTENT_TYPE_JSON);
148146

149-
if (RequestMethod.GET == method) {
150-
conn.setDoOutput(false);
151-
} else if (RequestMethod.DELETE == method) {
152-
conn.setDoOutput(false);
153-
} else if (RequestMethod.POST == method || RequestMethod.PUT == method) {
154-
conn.setDoOutput(true);
155-
byte[] data = content.getBytes(CHARSET);
147+
if(null == content) {
148+
conn.setDoOutput(false);
149+
} else {
150+
conn.setDoOutput(true);
151+
byte[] data = content.getBytes(CHARSET);
156152
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
157-
out = conn.getOutputStream();
153+
out = conn.getOutputStream();
158154
out.write(data);
159-
out.flush();
155+
out.flush();
160156
}
161157

162158
int status = conn.getResponseCode();

src/main/java/cn/jpush/api/common/resp/BaseResult.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ public String getOriginalContent() {
2323
}
2424
return null;
2525
}
26+
27+
public int getResponseCode() {
28+
if(null != responseWrapper) {
29+
return responseWrapper.responseCode;
30+
}
31+
return -1;
32+
}
2633

2734
public boolean isResultOK() {
28-
return RESPONSE_OK == responseWrapper.responseCode;
35+
if(null != responseWrapper) {
36+
return ( responseWrapper.responseCode / 200 ) == 1;
37+
}
38+
return false;
2939
}
3040

3141
public static <T extends BaseResult> T fromResponse(

src/test/java/cn/jpush/api/push/remote/ExceptionTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
package cn.jpush.api.push.remote;
2-
import static org.junit.Assert.*;
3-
4-
import org.junit.Test;
5-
import org.junit.experimental.categories.Category;
6-
72
import cn.jpush.api.JPushClient;
83
import cn.jpush.api.SlowTests;
94
import cn.jpush.api.common.resp.APIConnectionException;
@@ -12,9 +7,12 @@
127
import cn.jpush.api.push.model.PushPayload;
138
import cn.jpush.api.push.model.audience.Audience;
149
import cn.jpush.api.push.model.notification.Notification;
15-
1610
import com.google.gson.JsonObject;
1711
import com.google.gson.JsonPrimitive;
12+
import org.junit.Test;
13+
import org.junit.experimental.categories.Category;
14+
15+
import static org.junit.Assert.assertEquals;
1816

1917
@Category(SlowTests.class)
2018
public class ExceptionTest extends BaseRemotePushTest {
@@ -160,7 +158,7 @@ public void invalidParams_notification_ios() {
160158
assertEquals(INVALID_PARAMS, e.getErrorCode());
161159
}
162160
}
163-
161+
/*
164162
@Test
165163
public void invalidParams_notification_winphone() {
166164
JsonObject payload = new JsonObject();
@@ -181,7 +179,7 @@ public void invalidParams_notification_winphone() {
181179
assertEquals(INVALID_PARAMS, e.getErrorCode());
182180
}
183181
}
184-
182+
*/
185183
@Test
186184
public void invalidParams_notification_android_builderidNotNumber() {
187185
JsonObject payload = new JsonObject();

0 commit comments

Comments
 (0)