1- package cn .jpush .api .jmessage ;
2-
1+ package cn .jpush .api .examples ;
32
3+ import cn .jpush .api .jmessage .JMessageClient ;
44import cn .jpush .api .common .resp .APIConnectionException ;
55import cn .jpush .api .jmessage .base .connection .APIRequestException ;
66
7+ import org .slf4j .Logger ;
8+ import org .slf4j .LoggerFactory ;
9+
710public class IMGroupExample {
811
12+ protected static final Logger LOG = LoggerFactory .getLogger (IMGroupExample .class );
13+
914 private static final String appkey = "242780bfdd7315dc1989fe2b" ;
1015 private static final String masterSecret = "2f5ced2bef64167950e63d13" ;
1116
1217 public static void testCreateGroup () {
1318 JMessageClient client = new JMessageClient (appkey , masterSecret );
1419 try {
1520 String res = client .createGroup ("test_user" , "test_gname1" , "description" , "test_user" );
16- System . out . println (res );
21+ LOG . info (res );
1722 } catch (APIConnectionException e ) {
18- System . out . println ( e . getMessage () );
23+ LOG . error ( "Connection error. Should retry later. " , e );
1924 } catch (APIRequestException e ) {
20- System .out .println (e .getErrorMessage ());
25+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
26+ LOG .info ("HTTP Status: " + e .getStatus ());
27+ LOG .info ("Error Message: " + e .getMessage ());
2128 }
2229 }
2330
@@ -26,11 +33,13 @@ public static void testGetGroupInfo() {
2633
2734 try {
2835 String res = client .getGroupInfo (10003767 );
29- System . out . println (res );
36+ LOG . info (res );
3037 } catch (APIConnectionException e ) {
31- System . out . println ( e . getMessage () );
38+ LOG . error ( "Connection error. Should retry later. " , e );
3239 } catch (APIRequestException e ) {
33- System .out .println (e .getErrorMessage ());
40+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
41+ LOG .info ("HTTP Status: " + e .getStatus ());
42+ LOG .info ("Error Message: " + e .getMessage ());
3443 }
3544 }
3645
@@ -39,11 +48,13 @@ public static void testGetGroupMemberList() {
3948
4049 try {
4150 String res = client .getGroupMembers (10003767 );
42- System . out . println (res );
51+ LOG . info (res );
4352 } catch (APIConnectionException e ) {
44- System . out . println ( e . getMessage () );
53+ LOG . error ( "Connection error. Should retry later. " , e );
4554 } catch (APIRequestException e ) {
46- System .out .println (e .getErrorMessage ());
55+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
56+ LOG .info ("HTTP Status: " + e .getStatus ());
57+ LOG .info ("Error Message: " + e .getMessage ());
4758 }
4859 }
4960
@@ -52,11 +63,13 @@ public static void testGetGroupListByAppkey() {
5263
5364 try {
5465 String res = client .getGroupListByAppkey (0 , 30 );
55- System . out . println (res );
66+ LOG . info (res );
5667 } catch (APIConnectionException e ) {
57- System . out . println ( e . getMessage () );
68+ LOG . error ( "Connection error. Should retry later. " , e );
5869 } catch (APIRequestException e ) {
59- System .out .println (e .getErrorMessage ());
70+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
71+ LOG .info ("HTTP Status: " + e .getStatus ());
72+ LOG .info ("Error Message: " + e .getMessage ());
6073 }
6174 }
6275
@@ -69,9 +82,11 @@ public static void testManageGroup() {
6982 client .addOrRemoveMembers (10003767 , addList , null );
7083 client .addOrRemoveMembers (10003767 , null , removeList );
7184 } catch (APIConnectionException e ) {
72- System . out . println ( e . getMessage () );
85+ LOG . error ( "Connection error. Should retry later. " , e );
7386 } catch (APIRequestException e ) {
74- System .out .println (e .getErrorMessage ());
87+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
88+ LOG .info ("HTTP Status: " + e .getStatus ());
89+ LOG .info ("Error Message: " + e .getMessage ());
7590 }
7691 }
7792
@@ -81,9 +96,11 @@ public static void testUpdateGroupInfo() {
8196 try {
8297 client .updateGroupInfo (10003767 , "test_gname_new" , "update desc" );
8398 } catch (APIConnectionException e ) {
84- System . out . println ( e . getMessage () );
99+ LOG . error ( "Connection error. Should retry later. " , e );
85100 } catch (APIRequestException e ) {
86- System .out .println (e .getErrorMessage ());
101+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
102+ LOG .info ("HTTP Status: " + e .getStatus ());
103+ LOG .info ("Error Message: " + e .getMessage ());
87104 }
88105 }
89106
@@ -93,17 +110,15 @@ public static void testDeleteGroup() {
93110 try {
94111 client .deleteGroup (10003765 );
95112 } catch (APIConnectionException e ) {
96- System . out . println ( e . getMessage () );
113+ LOG . error ( "Connection error. Should retry later. " , e );
97114 } catch (APIRequestException e ) {
98- System .out .println (e .getErrorMessage ());
115+ LOG .error ("Error response from JPush server. Should review and fix it. " , e );
116+ LOG .info ("HTTP Status: " + e .getStatus ());
117+ LOG .info ("Error Message: " + e .getMessage ());
99118 }
100119 }
101120
102121 public static void main (String [] args ) {
103122// testGetGroupInfo();
104- // testGetGroupListByAppkey();
105- // testUpdateGroupInfo();
106- // testDeleteGroup();
107-
108123 }
109124}
0 commit comments