1- package cn .jpush .api .jmessage ;
1+ package cn .jpush .api .examples ;
22
3+ import cn .jpush .api .jmessage .JMessageClient ;
34
45import cn .jpush .api .common .resp .APIConnectionException ;
56import cn .jpush .api .jmessage .base .connection .APIRequestException ;
67
78public class IMGroupExample {
89
10+ protected static final Logger LOG = LoggerFactory .getLogger (IMGroupExample .class );
11+
912 private static final String appkey = "242780bfdd7315dc1989fe2b" ;
1013 private static final String masterSecret = "2f5ced2bef64167950e63d13" ;
1114
@@ -15,9 +18,11 @@ public static void testCreateGroup() {
1518 String res = client .createGroup ("test_user" , "test_gname1" , "description" , "test_user" );
1619 System .out .println (res );
1720 } catch (APIConnectionException e ) {
18- System . out . println ( e . getMessage () );
21+ LOG . error ( "Connection error. Should retry later. " , e );
1922 } catch (APIRequestException e ) {
20- System .out .println (e .getErrorMessage ());
23+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
24+ LOG .info ("HTTP Status: " + e .getStatus ());
25+ LOG .info ("Error Message: " + e .getMessage ());
2126 }
2227 }
2328
@@ -28,9 +33,11 @@ public static void testGetGroupInfo() {
2833 String res = client .getGroupInfo (10003767 );
2934 System .out .println (res );
3035 } catch (APIConnectionException e ) {
31- System . out . println ( e . getMessage () );
36+ LOG . error ( "Connection error. Should retry later. " , e );
3237 } catch (APIRequestException e ) {
33- System .out .println (e .getErrorMessage ());
38+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
39+ LOG .info ("HTTP Status: " + e .getStatus ());
40+ LOG .info ("Error Message: " + e .getMessage ());
3441 }
3542 }
3643
@@ -41,9 +48,11 @@ public static void testGetGroupMemberList() {
4148 String res = client .getGroupMembers (10003767 );
4249 System .out .println (res );
4350 } catch (APIConnectionException e ) {
44- System . out . println ( e . getMessage () );
51+ LOG . error ( "Connection error. Should retry later. " , e );
4552 } catch (APIRequestException e ) {
46- System .out .println (e .getErrorMessage ());
53+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
54+ LOG .info ("HTTP Status: " + e .getStatus ());
55+ LOG .info ("Error Message: " + e .getMessage ());
4756 }
4857 }
4958
@@ -54,9 +63,11 @@ public static void testGetGroupListByAppkey() {
5463 String res = client .getGroupListByAppkey (0 , 30 );
5564 System .out .println (res );
5665 } catch (APIConnectionException e ) {
57- System . out . println ( e . getMessage () );
66+ LOG . error ( "Connection error. Should retry later. " , e );
5867 } catch (APIRequestException e ) {
59- System .out .println (e .getErrorMessage ());
68+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
69+ LOG .info ("HTTP Status: " + e .getStatus ());
70+ LOG .info ("Error Message: " + e .getMessage ());
6071 }
6172 }
6273
@@ -69,9 +80,11 @@ public static void testManageGroup() {
6980 client .addOrRemoveMembers (10003767 , addList , null );
7081 client .addOrRemoveMembers (10003767 , null , removeList );
7182 } catch (APIConnectionException e ) {
72- System . out . println ( e . getMessage () );
83+ LOG . error ( "Connection error. Should retry later. " , e );
7384 } catch (APIRequestException e ) {
74- System .out .println (e .getErrorMessage ());
85+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
86+ LOG .info ("HTTP Status: " + e .getStatus ());
87+ LOG .info ("Error Message: " + e .getMessage ());
7588 }
7689 }
7790
@@ -81,9 +94,11 @@ public static void testUpdateGroupInfo() {
8194 try {
8295 client .updateGroupInfo (10003767 , "test_gname_new" , "update desc" );
8396 } catch (APIConnectionException e ) {
84- System . out . println ( e . getMessage () );
97+ LOG . error ( "Connection error. Should retry later. " , e );
8598 } catch (APIRequestException e ) {
86- System .out .println (e .getErrorMessage ());
99+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
100+ LOG .info ("HTTP Status: " + e .getStatus ());
101+ LOG .info ("Error Message: " + e .getMessage ());
87102 }
88103 }
89104
@@ -93,17 +108,15 @@ public static void testDeleteGroup() {
93108 try {
94109 client .deleteGroup (10003765 );
95110 } catch (APIConnectionException e ) {
96- System . out . println ( e . getMessage () );
111+ LOG . error ( "Connection error. Should retry later. " , e );
97112 } catch (APIRequestException e ) {
98- System .out .println (e .getErrorMessage ());
113+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
114+ LOG .info ("HTTP Status: " + e .getStatus ());
115+ LOG .info ("Error Message: " + e .getMessage ());
99116 }
100117 }
101118
102119 public static void main (String [] args ) {
103120// testGetGroupInfo();
104- // testGetGroupListByAppkey();
105- // testUpdateGroupInfo();
106- // testDeleteGroup();
107-
108121 }
109122}
0 commit comments