@@ -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 () {
0 commit comments