66import java .util .Map ;
77
88import cn .jiguang .common .ServiceHelper ;
9+ import cn .jiguang .common .connection .NativeHttpClient ;
910import cn .jiguang .common .connection .NettyHttpClient ;
1011import cn .jiguang .common .resp .ResponseWrapper ;
1112import cn .jpush .api .push .model .notification .*;
@@ -46,7 +47,8 @@ public class PushExample {
4647 public static void main (String [] args ) {
4748// testSendPushWithCustomConfig();
4849// testSendIosAlert();
49- testSendPush ();
50+ // testSendPush();
51+ testSendPushes ();
5052// testSendPush_fromJSON();
5153// testSendPushWithCallback();
5254// testSendPushesWithMultiCallback();
@@ -134,15 +136,22 @@ public static void testSendPush() {
134136 // Can use this https proxy: https://github.com/Exa-Networks/exaproxy
135137 ClientConfig clientConfig = ClientConfig .getInstance ();
136138 JPushClient jpushClient = new JPushClient (MASTER_SECRET , APP_KEY , null , clientConfig );
137-
139+ String authCode = ServiceHelper .getBasicAuthorization (APP_KEY , MASTER_SECRET );
140+ // Here you can use NativeHttpClient or NettyHttpClient.
141+ NativeHttpClient httpClient = new NativeHttpClient (authCode , null , clientConfig );
142+ // Call setHttpClient to set httpClient,
143+ // If you don't invoke this method, default httpClient will use NativeHttpClient.
144+ jpushClient .getPushClient ().setHttpClient (httpClient );
145+
146+
138147 // For push, all you need do is to build PushPayload object.
139148 PushPayload payload = buildPushObject_all_alias_alert ();
140149 try {
141150 PushResult result = jpushClient .sendPush (payload );
142151 LOG .info ("Got result - " + result );
143- Thread . sleep ( 5000 );
144- //如果使用 NettyHttpClient,需要手动调用 close 方法退出进程
145- // jpushClient.close();
152+ // 如果使用 NettyHttpClient,需要手动调用 close 方法退出进程
153+ // If uses NettyHttpClient, call close when finished sending request, otherwise process will not exit.
154+ // jpushClient.close();
146155 } catch (APIConnectionException e ) {
147156 LOG .error ("Connection error. Should retry later. " , e );
148157 LOG .error ("Sendno: " + payload .getSendno ());
@@ -154,8 +163,6 @@ public static void testSendPush() {
154163 LOG .info ("Error Message: " + e .getErrorMessage ());
155164 LOG .info ("Msg ID: " + e .getMsgId ());
156165 LOG .error ("Sendno: " + payload .getSendno ());
157- } catch (InterruptedException e ) {
158- e .printStackTrace ();
159166 }
160167 }
161168
@@ -185,6 +192,10 @@ public static void testSendPush_fromJSON() {
185192 LOG .info ("Msg ID: " + e .getMsgId ());
186193 LOG .error ("Sendno: " + payload .getSendno ());
187194 }
195+ }
196+
197+ public static void testSendPushes () {
198+
188199 }
189200
190201 public static PushPayload buildPushObject_all_all_alert () {
0 commit comments