Skip to content

Commit fca02bc

Browse files
KenChoiKenChoi
authored andcommitted
prepare release v3.2.15
1 parent aaf4b9b commit fca02bc

File tree

6 files changed

+286
-57
lines changed

6 files changed

+286
-57
lines changed

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

Lines changed: 118 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
package cn.jpush.api.examples;
22

3+
import java.net.URI;
4+
import java.net.URISyntaxException;
35
import java.util.HashMap;
46
import java.util.Map;
57

8+
import cn.jiguang.common.ServiceHelper;
9+
import cn.jiguang.common.connection.NettyHttpClient;
10+
import cn.jiguang.common.resp.ResponseWrapper;
611
import cn.jpush.api.push.model.notification.*;
712
import com.google.gson.*;
13+
import io.netty.handler.codec.http.HttpMethod;
814
import org.slf4j.Logger;
915
import org.slf4j.LoggerFactory;
1016

@@ -27,6 +33,9 @@ public class PushExample {
2733
// demo App defined in resources/jpush-api.conf
2834
private static final String appKey ="dd1066407b044738b6479275";
2935
private static final String masterSecret = "e8cc9a76d5b7a580859bcfa7";
36+
37+
protected static final String APP_KEY ="d4ee2375846bc30fa51334f5";
38+
protected static final String MASTER_SECRET = "2bf52ee46fdeaadb8718fc15";
3039

3140
public static final String TITLE = "Test from API example";
3241
public static final String ALERT = "Test from API Example - alert";
@@ -37,32 +46,109 @@ public class PushExample {
3746
public static void main(String[] args) {
3847
// testSendPushWithCustomConfig();
3948
// testSendIosAlert();
40-
// testSendPush();
49+
testSendPush();
4150
// testSendPush_fromJSON();
51+
// testSendPushes();
52+
// testSendPushesWithMultiCallback();
4253
}
54+
55+
// 使用 NettyHttpClient 异步接口发送请求
56+
public static void testSendPushes() {
57+
ClientConfig clientConfig = ClientConfig.getInstance();
58+
NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
59+
null, clientConfig);
60+
for (int i = 0; i < 4; i++) {
61+
NettyHttpClient.BaseCallback callback = new NettyHttpClient.BaseCallback() {
62+
@Override
63+
public void onSucceed(ResponseWrapper responseWrapper) {
64+
System.out.println("callback i");
65+
}
66+
};
67+
MyThread thread = new MyThread(client, callback);
68+
thread.start();
69+
}
70+
}
71+
72+
public static void testSendPushesWithMultiCallback() {
73+
NettyHttpClient client = new NettyHttpClient(ServiceHelper.getBasicAuthorization(APP_KEY, MASTER_SECRET),
74+
null, ClientConfig.getInstance());
75+
String host = (String) ClientConfig.getInstance().get(ClientConfig.PUSH_HOST_NAME);
76+
URI uri = null;
77+
try {
78+
uri = new URI(host + (String) ClientConfig.getInstance().get(ClientConfig.PUSH_PATH));
79+
PushPayload payload = PushPayload.alertAll("test");
80+
System.out.println(payload.toString());
81+
NettyHttpClient.BaseCallback callback1 = new NettyHttpClient.BaseCallback() {
82+
@Override
83+
public void onSucceed(ResponseWrapper responseWrapper) {
84+
System.out.println("callback1 Got result: " + responseWrapper.responseContent);
85+
}
86+
};
87+
NettyHttpClient.BaseCallback callback2 = new NettyHttpClient.BaseCallback() {
88+
@Override
89+
public void onSucceed(ResponseWrapper responseWrapper) {
90+
System.out.println("callback2 Got result: " + responseWrapper.responseContent);
91+
}
92+
};
93+
MyThread thread1 = new MyThread(client, callback1);
94+
MyThread thread2 = new MyThread(client, callback2);
95+
thread1.start();
96+
thread2.start();
97+
} catch (URISyntaxException e) {
98+
e.printStackTrace();
99+
}
100+
}
101+
102+
private static class MyThread extends Thread {
103+
104+
private NettyHttpClient client;
105+
private NettyHttpClient.BaseCallback callback;
106+
107+
public MyThread(NettyHttpClient client, NettyHttpClient.BaseCallback callback) {
108+
this.client = client;
109+
this.callback = callback;
110+
}
111+
112+
@Override
113+
public void run() {
114+
// super.run();
115+
System.out.println("running send push");
116+
try {
117+
String host = (String) ClientConfig.getInstance().get(ClientConfig.PUSH_HOST_NAME);
118+
URI uri = new URI(host + (String) ClientConfig.getInstance().get(ClientConfig.PUSH_PATH));
119+
PushPayload payload = PushPayload.alertAll("test");
120+
System.out.println(payload.toString());
121+
client.sendRequest(HttpMethod.POST, payload.toString(), uri, callback);
122+
} catch (URISyntaxException e) {
123+
e.printStackTrace();
124+
}
125+
}
126+
}
43127

44128

45129
public static void testSendPush() {
46130
// HttpProxy proxy = new HttpProxy("localhost", 3128);
47131
// Can use this https proxy: https://github.com/Exa-Networks/exaproxy
48132
ClientConfig clientConfig = ClientConfig.getInstance();
49-
JPushClient jpushClient = new JPushClient(masterSecret, appKey, null, clientConfig);
133+
JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
50134

51135
// For push, all you need do is to build PushPayload object.
52-
PushPayload payload = buildPushObject_ios_tagAnd_alertWithExtrasAndMessage();
136+
PushPayload payload = buildPushObject_android_newly_support();
53137
try {
54138
PushResult result = jpushClient.sendPush(payload);
55139
LOG.info("Got result - " + result);
56140

57141
} catch (APIConnectionException e) {
58142
LOG.error("Connection error. Should retry later. ", e);
143+
LOG.error("Sendno: " + payload.getSendno());
59144

60145
} catch (APIRequestException e) {
61146
LOG.error("Error response from JPush server. Should review and fix it. ", e);
62147
LOG.info("HTTP Status: " + e.getStatus());
63148
LOG.info("Error Code: " + e.getErrorCode());
64149
LOG.info("Error Message: " + e.getErrorMessage());
65150
LOG.info("Msg ID: " + e.getMsgId());
151+
LOG.error("Sendno: " + payload.getSendno());
66152
}
67153
}
68154

@@ -82,13 +168,15 @@ public static void testSendPush_fromJSON() {
82168

83169
} catch (APIConnectionException e) {
84170
LOG.error("Connection error. Should retry later. ", e);
171+
LOG.error("Sendno: " + payload.getSendno());
85172

86173
} catch (APIRequestException e) {
87174
LOG.error("Error response from JPush server. Should review and fix it. ", e);
88175
LOG.info("HTTP Status: " + e.getStatus());
89176
LOG.info("Error Code: " + e.getErrorCode());
90177
LOG.info("Error Message: " + e.getErrorMessage());
91178
LOG.info("Msg ID: " + e.getMsgId());
179+
LOG.error("Sendno: " + payload.getSendno());
92180
}
93181
}
94182

@@ -176,6 +264,33 @@ public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage()
176264
.build())
177265
.build();
178266
}
267+
268+
public static PushPayload buildPushObject_android_newly_support() {
269+
JsonObject inbox = new JsonObject();
270+
inbox.add("line1", new JsonPrimitive("line1 string"));
271+
inbox.add("line2", new JsonPrimitive("line2 string"));
272+
inbox.add("contentTitle", new JsonPrimitive("title string"));
273+
inbox.add("summaryText", new JsonPrimitive("+3 more"));
274+
Notification notification = Notification.newBuilder()
275+
.addPlatformNotification(AndroidNotification.newBuilder()
276+
.setAlert(ALERT)
277+
.setBigPicPath("path to big picture")
278+
.setBigText("long text")
279+
.setBuilderId(1)
280+
.setCategory("CATEGORY_SOCIAL")
281+
.setInbox(inbox)
282+
.setStyle(1)
283+
.setTitle("Alert test")
284+
.setPriority(1)
285+
.build())
286+
.build();
287+
return PushPayload.newBuilder()
288+
.setPlatform(Platform.all())
289+
.setAudience(Audience.registrationId("18071adc030dcba91c0"))
290+
.setNotification(notification)
291+
.setOptions(Options.sendno())
292+
.build();
293+
}
179294

180295
public static PushPayload buildPushObject_ios_audienceMore_messageWithExtras() {
181296
return PushPayload.newBuilder()

pom.xml

Lines changed: 14 additions & 18 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.13-SNAPSHOT</version>
6+
<version>3.2.15-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,26 +35,22 @@
3535
<url>https://github.com/jpush/jpush-api-java-client</url>
3636
<connection>scm:git:[email protected]:jpush/jpush-api-java-client.git</connection>
3737
<developerConnection>scm:git:[email protected]:jpush/jpush-api-java-client.git</developerConnection>
38-
<tag>v3.2.13</tag>
38+
<tag>v3.2.15</tag>
3939
</scm>
4040

4141
<dependencies>
42-
<dependency>
43-
<groupId>cn.jpush.api</groupId>
44-
<artifactId>jiguang-common</artifactId>
45-
<version>0.1.6</version>
46-
<exclusions>
47-
<exclusion>
48-
<groupId>org.slf4j</groupId>
49-
<artifactId>slf4j-jdk14</artifactId>
50-
</exclusion>
51-
<exclusion>
52-
<groupId>org.slf4j</groupId>
53-
<artifactId>slf4j-nop</artifactId>
54-
</exclusion>
55-
</exclusions>
56-
</dependency>
57-
<dependency>
42+
<dependency>
43+
<groupId>cn.jpush.api</groupId>
44+
<artifactId>jiguang-common</artifactId>
45+
<version>1.0.1</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>io.netty</groupId>
49+
<artifactId>netty-all</artifactId>
50+
<version>4.1.6.Final</version>
51+
<scope>compile</scope>
52+
</dependency>
53+
<dependency>
5854
<groupId>com.google.code.gson</groupId>
5955
<artifactId>gson</artifactId>
6056
<version>2.3</version>

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.jpush.api.push;
22

3+
import cn.jiguang.common.connection.NettyHttpClient;
34
import com.google.gson.JsonParseException;
45
import com.google.gson.JsonParser;
56

@@ -27,7 +28,7 @@
2728
*/
2829
public class PushClient {
2930

30-
private final NativeHttpClient _httpClient;
31+
private final NettyHttpClient _httpClient;
3132
private String _baseUrl;
3233
private String _pushPath;
3334
private String _pushValidatePath;
@@ -85,7 +86,7 @@ public PushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPro
8586
this._timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);
8687

8788
String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
88-
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
89+
this._httpClient = new NettyHttpClient(authCode, proxy, conf);
8990
}
9091

9192
public PushClient(String masterSecret, String appKey, HttpProxy proxy, ClientConfig conf) {
@@ -99,7 +100,7 @@ public PushClient(String masterSecret, String appKey, HttpProxy proxy, ClientCon
99100
this._timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);
100101

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

104105
}
105106

0 commit comments

Comments
 (0)