diff --git a/pom.xml b/pom.xml
index 5dd458ea..511ca824 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
cn.jpush.api
jpush-client
- 3.2.6-SNAPSHOT
+ 3.2.7-SNAPSHOT
jar
https://github.com/jpush/jpush-api-java-client
JPush API Java Client
@@ -35,7 +35,7 @@
https://github.com/jpush/jpush-api-java-client
scm:git:git@github.com:jpush/jpush-api-java-client.git
scm:git:git@github.com:jpush/jpush-api-java-client.git
- v3.1.1
+ v3.2.6
diff --git a/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java b/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java
index eb52944d..32306176 100644
--- a/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java
+++ b/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java
@@ -1,31 +1,20 @@
package cn.jpush.api.common.connection;
+import cn.jpush.api.common.resp.APIConnectionException;
+import cn.jpush.api.common.resp.APIRequestException;
+import cn.jpush.api.common.resp.ResponseWrapper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.ssl.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
-import java.net.Authenticator;
-import java.net.HttpURLConnection;
-import java.net.PasswordAuthentication;
-import java.net.SocketTimeoutException;
-import java.net.URL;
+import java.net.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManager;
-import javax.net.ssl.X509TrustManager;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import cn.jpush.api.common.resp.APIConnectionException;
-import cn.jpush.api.common.resp.APIRequestException;
-import cn.jpush.api.common.resp.ResponseWrapper;
-
/**
* The implementation has no connection pool mechanism, used origin java connection.
*
@@ -68,13 +57,23 @@ public NativeHttpClient(String authCode, int maxRetryTimes, HttpProxy proxy) {
public ResponseWrapper sendGet(String url)
throws APIConnectionException, APIRequestException {
- return doRequest(url, null, RequestMethod.GET);
+ return sendGet(url, null);
+ }
+
+ public ResponseWrapper sendGet(String url, String content)
+ throws APIConnectionException, APIRequestException {
+ return doRequest(url, content, RequestMethod.GET);
}
public ResponseWrapper sendDelete(String url)
throws APIConnectionException, APIRequestException {
- return doRequest(url, null, RequestMethod.DELETE);
+ return sendDelete(url, null);
}
+
+ public ResponseWrapper sendDelete(String url, String content)
+ throws APIConnectionException, APIRequestException {
+ return doRequest(url, content, RequestMethod.DELETE);
+ }
public ResponseWrapper sendPost(String url, String content)
throws APIConnectionException, APIRequestException {
@@ -117,7 +116,6 @@ private ResponseWrapper _doRequest(String url, String content,
if (null != content) {
LOG.debug("Request Content - " + content);
}
-
HttpURLConnection conn = null;
OutputStream out = null;
StringBuffer sb = new StringBuffer();
@@ -146,17 +144,15 @@ private ResponseWrapper _doRequest(String url, String content,
conn.setRequestProperty("Authorization", _authCode);
conn.setRequestProperty("Content-Type", CONTENT_TYPE_JSON);
- if (RequestMethod.GET == method) {
- conn.setDoOutput(false);
- } else if (RequestMethod.DELETE == method) {
- conn.setDoOutput(false);
- } else if (RequestMethod.POST == method || RequestMethod.PUT == method) {
- conn.setDoOutput(true);
- byte[] data = content.getBytes(CHARSET);
+ if(null == content) {
+ conn.setDoOutput(false);
+ } else {
+ conn.setDoOutput(true);
+ byte[] data = content.getBytes(CHARSET);
conn.setRequestProperty("Content-Length", String.valueOf(data.length));
- out = conn.getOutputStream();
+ out = conn.getOutputStream();
out.write(data);
- out.flush();
+ out.flush();
}
int status = conn.getResponseCode();
diff --git a/src/main/java/cn/jpush/api/common/resp/BaseResult.java b/src/main/java/cn/jpush/api/common/resp/BaseResult.java
index b980fdd5..c54c67b6 100644
--- a/src/main/java/cn/jpush/api/common/resp/BaseResult.java
+++ b/src/main/java/cn/jpush/api/common/resp/BaseResult.java
@@ -23,9 +23,19 @@ public String getOriginalContent() {
}
return null;
}
+
+ public int getResponseCode() {
+ if(null != responseWrapper) {
+ return responseWrapper.responseCode;
+ }
+ return -1;
+ }
public boolean isResultOK() {
- return RESPONSE_OK == responseWrapper.responseCode;
+ if(null != responseWrapper) {
+ return ( responseWrapper.responseCode / 200 ) == 1;
+ }
+ return false;
}
public static T fromResponse(
diff --git a/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java b/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java
index c38e0df9..e82cf092 100644
--- a/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java
+++ b/src/test/java/cn/jpush/api/push/remote/ExceptionTest.java
@@ -1,9 +1,4 @@
package cn.jpush.api.push.remote;
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
import cn.jpush.api.JPushClient;
import cn.jpush.api.SlowTests;
import cn.jpush.api.common.resp.APIConnectionException;
@@ -12,9 +7,12 @@
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;
-
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import static org.junit.Assert.assertEquals;
@Category(SlowTests.class)
public class ExceptionTest extends BaseRemotePushTest {
@@ -160,7 +158,7 @@ public void invalidParams_notification_ios() {
assertEquals(INVALID_PARAMS, e.getErrorCode());
}
}
-
+ /*
@Test
public void invalidParams_notification_winphone() {
JsonObject payload = new JsonObject();
@@ -181,7 +179,7 @@ public void invalidParams_notification_winphone() {
assertEquals(INVALID_PARAMS, e.getErrorCode());
}
}
-
+ */
@Test
public void invalidParams_notification_android_builderidNotNumber() {
JsonObject payload = new JsonObject();