Skip to content

Commit aaaa219

Browse files
authored
Merge pull request #77 from jpush/dev
prepare release v3.2.16
2 parents ff67a38 + 470599a commit aaaa219

File tree

13 files changed

+108
-38
lines changed

13 files changed

+108
-38
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<dependency>
2727
<groupId>cn.jpush.api</groupId>
2828
<artifactId>jpush-client</artifactId>
29-
<version>3.2.15</version>
29+
<version>3.2.16</version>
3030
</dependency>
3131
```
3232
### jar 包方式
@@ -46,7 +46,7 @@
4646
<dependency>
4747
<groupId>cn.jpush.api</groupId>
4848
<artifactId>jiguang-common</artifactId>
49-
<version>1.0.1</version>
49+
<version>1.0.2</version>
5050
</dependency>
5151
<dependency>
5252
<groupId>io.netty</groupId>

example/main/java/cn/jpush/api/examples/PushExample.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,27 @@ public static void main(String[] args) {
4848
// testSendIosAlert();
4949
testSendPush();
5050
// testSendPush_fromJSON();
51-
// testSendPushes();
51+
// testSendPushWithCallback();
5252
// testSendPushesWithMultiCallback();
5353
}
5454

5555
// 使用 NettyHttpClient 异步接口发送请求
56-
public static void testSendPushes() {
56+
public static void testSendPushWithCallback() {
5757
ClientConfig clientConfig = ClientConfig.getInstance();
58-
NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
58+
String host = (String) clientConfig.get(ClientConfig.PUSH_HOST_NAME);
59+
final NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
5960
null, clientConfig);
60-
for (int i = 0; i < 4; i++) {
61-
NettyHttpClient.BaseCallback callback = new NettyHttpClient.BaseCallback() {
61+
try {
62+
URI uri = new URI(host + clientConfig.get(ClientConfig.PUSH_PATH));
63+
PushPayload payload = buildPushObject_all_alias_alert();
64+
client.sendRequest(HttpMethod.POST, payload.toString(), uri, new NettyHttpClient.BaseCallback() {
6265
@Override
6366
public void onSucceed(ResponseWrapper responseWrapper) {
64-
System.out.println("callback i");
67+
LOG.info("Got result: " + responseWrapper.responseContent);
6568
}
66-
};
67-
MyThread thread = new MyThread(client, callback);
68-
thread.start();
69+
});
70+
} catch (URISyntaxException e) {
71+
e.printStackTrace();
6972
}
7073
}
7174

@@ -133,24 +136,28 @@ public static void testSendPush() {
133136
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
134137

135138
// For push, all you need do is to build PushPayload object.
136-
PushPayload payload = buildPushObject_android_newly_support();
139+
PushPayload payload = buildPushObject_all_alias_alert();
137140
try {
138141
PushResult result = jpushClient.sendPush(payload);
139142
LOG.info("Got result - " + result);
140-
143+
Thread.sleep(5000);
144+
//如果使用 NettyHttpClient,需要手动调用 close 方法退出进程
145+
// jpushClient.close();
141146
} catch (APIConnectionException e) {
142147
LOG.error("Connection error. Should retry later. ", e);
143148
LOG.error("Sendno: " + payload.getSendno());
144-
149+
145150
} catch (APIRequestException e) {
146151
LOG.error("Error response from JPush server. Should review and fix it. ", e);
147152
LOG.info("HTTP Status: " + e.getStatus());
148153
LOG.info("Error Code: " + e.getErrorCode());
149154
LOG.info("Error Message: " + e.getErrorMessage());
150155
LOG.info("Msg ID: " + e.getMsgId());
151156
LOG.error("Sendno: " + payload.getSendno());
157+
} catch (InterruptedException e) {
158+
e.printStackTrace();
152159
}
153-
}
160+
}
154161

155162
//use String to build PushPayload instance
156163
public static void testSendPush_fromJSON() {

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
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.2.15</tag>
38+
<tag>v3.2.16</tag>
3939
</scm>
4040

4141
<dependencies>
4242
<dependency>
4343
<groupId>cn.jpush.api</groupId>
4444
<artifactId>jiguang-common</artifactId>
45-
<version>1.0.1</version>
45+
<version>1.0.2</version>
4646
</dependency>
4747
<dependency>
4848
<groupId>io.netty</groupId>

src/main/java/cn/jpush/api/JPushClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,5 +1179,8 @@ private ScheduleResult createPeriodicalSchedule(String name, String start, Strin
11791179
return _scheduleClient.createSchedule(payload);
11801180
}
11811181

1182+
// public void close() {
1183+
// _pushClient.close();
1184+
// }
11821185
}
11831186

src/main/java/cn/jpush/api/push/PushClient.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class PushClient {
3030

31-
private final NettyHttpClient _httpClient;
31+
private final NativeHttpClient _httpClient;
3232
private String _baseUrl;
3333
private String _pushPath;
3434
private String _pushValidatePath;
@@ -86,7 +86,7 @@ public PushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPro
8686
this._timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);
8787

8888
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
89-
this._httpClient = new NettyHttpClient(authCode, proxy, conf);
89+
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
9090
}
9191

9292
public PushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) {
@@ -100,7 +100,7 @@ public PushClient(String masterSecret, String appKey, HttpProxy proxy, ClientCon
100100
this._timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);
101101

102102
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
103-
this._httpClient = new NettyHttpClient(authCode, proxy, conf);
103+
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
104104

105105
}
106106

@@ -210,6 +210,12 @@ public PushResult sendPushValidate(String payloadString) throws APIConnectionExc
210210
return BaseResult.fromResponse(response, PushResult.class);
211211
}
212212

213+
// 如果使用 NettyHttpClient,在发送请求后需要手动调用 close 方法
214+
// public void close() {
215+
// if (_httpClient instanceof NettyHttpClient) {
216+
// _httpClient.close();
217+
// }
218+
// }
213219
}
214220

215221

src/main/java/cn/jpush/api/push/PushResult.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class PushResult extends BaseResult {
1010

1111
@Expose public long msg_id;
1212
@Expose public int sendno;
13+
@Expose public int statusCode;
1314

1415
}
1516

src/test/java/cn/jpush/api/BaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public abstract class BaseTest {
66

7-
protected static final String APP_KEY ="d4ee2375846bc30fa51334f5";
7+
protected static final String APP_KEY = "d4ee2375846bc30fa51334f5";
88
protected static final String MASTER_SECRET = "2bf52ee46fdeaadb8718fc15";
99

1010
public static final String ALERT = "JPush Test - alert";

src/test/java/cn/jpush/api/push/PushClientTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ public class PushClientTest extends BaseTest {
3333
public void testSendPush() {
3434
ClientConfig clientConfig = ClientConfig.getInstance();
3535
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
36-
PushPayload payload = buildPushObject_all_alias_alert();
36+
PushPayload payload = PushPayload.alertAll(ALERT);
3737
try {
3838
PushResult result = jpushClient.sendPush(payload);
39+
int status = result.getResponseCode();
3940
LOG.info("Got result - " + result);
4041

4142
} catch (APIConnectionException e) {
@@ -56,7 +57,7 @@ public void testSendPush() {
5657
public void testSendPushWithCallback() {
5758
ClientConfig clientConfig = ClientConfig.getInstance();
5859
String host = (String) clientConfig.get(ClientConfig.PUSH_HOST_NAME);
59-
NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
60+
final NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
6061
null, clientConfig);
6162
try {
6263
URI uri = new URI(host + clientConfig.get(ClientConfig.PUSH_PATH));
@@ -76,7 +77,7 @@ public void onSucceed(ResponseWrapper responseWrapper) {
7677
public static PushPayload buildPushObject_all_alias_alert() {
7778
return PushPayload.newBuilder()
7879
.setPlatform(Platform.all())
79-
.setAudience(Audience.registrationId("18071adc030dcba91c0"))
80+
.setAudience(Audience.alias("alias"))
8081
.setNotification(Notification.alert(ALERT))
8182
.build();
8283
}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertTrue;
44

5+
import cn.jiguang.common.resp.APIRequestException;
56
import org.junit.Test;
67
import org.junit.experimental.categories.Category;
78

@@ -58,7 +59,11 @@ public void sendAlert_ios() throws Exception {
5859
.addPlatformNotification(IosNotification.alert("ios alert"))
5960
.build())
6061
.build();
61-
PushResult result = _client.sendPush(payload);
62+
try {
63+
PushResult result = _client.sendPush(payload);
64+
} catch (APIRequestException e) {
65+
e.printStackTrace();
66+
}
6267
}
6368

6469
@Test
@@ -71,7 +76,11 @@ public void sendAlert_wp() throws Exception {
7176
.addPlatformNotification(WinphoneNotification.alert("winphone alert"))
7277
.build())
7378
.build();
74-
PushResult result = _client.sendPush(payload);
79+
try {
80+
PushResult result = _client.sendPush(payload);
81+
} catch (APIRequestException e) {
82+
e.printStackTrace();
83+
}
7584
}
7685

7786

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,18 @@ public void sendByAlias() throws Exception {
9898
.setAudience(Audience.alias(ALIAS1))
9999
.setNotification(Notification.alert(ALERT))
100100
.build();
101-
PushResult result = _client.sendPush(payload);
101+
try {
102+
PushResult result = _client.sendPush(payload);
103+
} catch (APIRequestException e) {
104+
e.printStackTrace();
105+
}
102106
}
103107

104108
@Test
105109
public void sendByRegistrationID() throws Exception {
106110
PushPayload payload = PushPayload.newBuilder()
107111
.setPlatform(Platform.all())
108-
.setAudience(Audience.registrationId(REGISTRATION_ID1))
112+
.setAudience(Audience.registrationId(REGISTRATION_ID3))
109113
.setNotification(Notification.alert(ALERT))
110114
.build();
111115
PushResult result = _client.sendPush(payload);
@@ -171,7 +175,11 @@ public void sendByRegistrationIDMore() throws Exception {
171175
.setAudience(Audience.registrationId(REGISTRATION_ID1, REGISTRATION_ID2))
172176
.setNotification(Notification.alert(ALERT))
173177
.build();
174-
PushResult result = _client.sendPush(payload);
178+
try {
179+
PushResult result = _client.sendPush(payload);
180+
} catch (APIRequestException e) {
181+
e.printStackTrace();
182+
}
175183
}
176184

177185

0 commit comments

Comments
 (0)