Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@
RegisterInfo[] regUsers = new RegisterInfo[users.size()];

String res = client.registerUsers(users.toArray(regUsers));
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
```

Expand All @@ -272,11 +274,13 @@
JMessageClient client = new JMessageClient(appkey, masterSecret);
try {
String res = client.createGroup("test_user", "test_gname1", "description", "test_user");
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
```

63 changes: 39 additions & 24 deletions example/main/java/cn/jpush/api/examples/IMGroupExample.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package cn.jpush.api.jmessage;

package cn.jpush.api.examples;

import cn.jpush.api.jmessage.JMessageClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.jmessage.base.connection.APIRequestException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class IMGroupExample {

protected static final Logger LOG = LoggerFactory.getLogger(IMGroupExample.class);

private static final String appkey = "242780bfdd7315dc1989fe2b";
private static final String masterSecret = "2f5ced2bef64167950e63d13";

public static void testCreateGroup() {
JMessageClient client = new JMessageClient(appkey, masterSecret);
try {
String res = client.createGroup("test_user", "test_gname1", "description", "test_user");
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -26,11 +33,13 @@ public static void testGetGroupInfo() {

try {
String res = client.getGroupInfo(10003767);
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -39,11 +48,13 @@ public static void testGetGroupMemberList() {

try {
String res = client.getGroupMembers(10003767);
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -52,11 +63,13 @@ public static void testGetGroupListByAppkey() {

try {
String res = client.getGroupListByAppkey(0, 30);
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -69,9 +82,11 @@ public static void testManageGroup() {
client.addOrRemoveMembers(10003767, addList, null );
client.addOrRemoveMembers(10003767, null, removeList);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -81,9 +96,11 @@ public static void testUpdateGroupInfo() {
try {
client.updateGroupInfo(10003767, "test_gname_new", "update desc");
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -93,17 +110,15 @@ public static void testDeleteGroup() {
try {
client.deleteGroup(10003765);
} catch (APIConnectionException e) {
System.out.println(e.getMessage());
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

public static void main(String[] args) {
// testGetGroupInfo();
// testGetGroupListByAppkey();
// testUpdateGroupInfo();
// testDeleteGroup();

}
}
57 changes: 36 additions & 21 deletions example/main/java/cn/jpush/api/examples/IMUserExample.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cn.jpush.api.jmessage;

package cn.jpush.api.examples;

import cn.jpush.api.jmessage.JMessageClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.jmessage.base.connection.APIRequestException;
import cn.jpush.api.jmessage.base.model.RegisterInfo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -40,11 +41,13 @@ public static void testRegisterUsers() {
RegisterInfo[] regUsers = new RegisterInfo[users.size()];

String res = client.registerUsers(users.toArray(regUsers));
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
System.out.println(e.getErrorMessage());
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -53,11 +56,13 @@ public static void testGetUserInfo() {

try {
String res = client.getUserInfo("test_user");
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -67,9 +72,11 @@ public static void testUpdatePassword() {
try {
client.updateUserPassword("test_user", "test_new_pass");
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -79,9 +86,11 @@ public static void testUpdateUserInfo() {
try {
client.updateUserInfo("test_user", "test_nick", "2000-01-12", "help me!", 1, "shenzhen", "nanshan", null);
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -90,11 +99,13 @@ public static void testGetUsers() {

try {
String res = client.getUserList(0, 30);
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -103,11 +114,13 @@ public static void testGetGroupsByUser() {

try {
String res = client.getGroupListByUser("test_user");
System.out.println(res);
LOG.info(res);
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

Expand All @@ -117,14 +130,16 @@ public static void testDeleteUser() {
try {
client.deleteUser("test_user_119");
} catch (APIConnectionException e) {
e.printStackTrace();
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
e.printStackTrace();
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Message: " + e.getMessage());
}
}

public static void main(String[] args) {
testRegisterUsers();
testGetGroupsByUser();
}

}
Expand Down
Loading