diff --git a/README.md b/README.md
index 005ab260..4f1f4078 100644
--- a/README.md
+++ b/README.md
@@ -87,27 +87,26 @@
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.PushExample
```Java
- JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
-
- // For push, all you need do is to build PushPayload object.
- PushPayload payload = buildPushObject_all_all_alert();
-
- try {
- PushResult result = jpushClient.sendPush(payload);
- LOG.info("Got result - " + result);
-
- } catch (APIConnectionException e) {
- // Connection error, should retry later
- LOG.error("Connection error, should retry later", e);
-
- } catch (APIRequestException e) {
- // Should review the error, and fix the request
- LOG.error("Should review the error, and fix the request", e);
- LOG.info("HTTP Status: " + e.getStatus());
- LOG.info("Error Code: " + e.getErrorCode());
- LOG.info("Error Message: " + e.getErrorMessage());
- }
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
+ // For push, all you need do is to build PushPayload object.
+ PushPayload payload = buildPushObject_all_all_alert();
+
+ try {
+ PushResult result = jpushClient.sendPush(payload);
+ LOG.info("Got result - " + result);
+
+ } catch (APIConnectionException e) {
+ // Connection error, should retry later
+ LOG.error("Connection error, should retry later", e);
+
+ } catch (APIRequestException e) {
+ // Should review the error, and fix the request
+ LOG.error("Should review the error, and fix the request", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
```
进行推送的关键在于构建一个 PushPayload 对象。以下示例一般的构建对象的用法。
@@ -190,22 +189,22 @@
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.ReportsExample
```Java
- JPushClient jpushClient = new JPushClient(masterSecret, appKey);
- try {
- ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
- LOG.debug("Got result - " + result);
-
- } catch (APIConnectionException e) {
- // Connection error, should retry later
- LOG.error("Connection error, should retry later", e);
-
- } catch (APIRequestException e) {
- // Should review the error, and fix the request
- LOG.error("Should review the error, and fix the request", e);
- LOG.info("HTTP Status: " + e.getStatus());
- LOG.info("Error Code: " + e.getErrorCode());
- LOG.info("Error Message: " + e.getErrorMessage());
- }
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+ try {
+ ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
+ LOG.debug("Got result - " + result);
+
+ } catch (APIConnectionException e) {
+ // Connection error, should retry later
+ LOG.error("Connection error, should retry later", e);
+
+ } catch (APIRequestException e) {
+ // Should review the error, and fix the request
+ LOG.error("Should review the error, and fix the request", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
```
### Tag/Alias 样例
@@ -213,19 +212,39 @@
> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.DeviceExample
```Java
- try {
- TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
-
- LOG.info(result.alias);
- LOG.info(result.tags.toString());
-
- } catch (APIConnectionException e) {
- LOG.error("Connection error. Should retry later. ", e);
-
- } catch (APIRequestException e) {
- LOG.error("Error response from JPush server. Should review and fix it. ", e);
- LOG.info("HTTP Status: " + e.getStatus());
- LOG.info("Error Code: " + e.getErrorCode());
- LOG.info("Error Message: " + e.getErrorMessage());
- }
+ try {
+ TagAliasResult result = jpushClient.getDeviceTagAlias(REGISTRATION_ID1);
+
+ LOG.info(result.alias);
+ LOG.info(result.tags.toString());
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
+```
+
+### Schedule 样例
+
+> 以下片断来自项目代码里的文件:example / cn.jpush.api.examples.ScheduleExample
+
+```Java
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+ String name = "test_schedule_example";
+ String time = "2016-07-30 12:30:25";
+ PushPayload push = PushPayload.alertAll("test schedule example.");
+ try {
+ ScheduleResult result = jpushClient.createSingleSchedule(name, time, push);
+ LOG.info("schedule result is " + result);
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
```
diff --git a/example/main/java/cn/jpush/api/examples/ScheduleExample.java b/example/main/java/cn/jpush/api/examples/ScheduleExample.java
new file mode 100644
index 00000000..3141bb5f
--- /dev/null
+++ b/example/main/java/cn/jpush/api/examples/ScheduleExample.java
@@ -0,0 +1,118 @@
+package cn.jpush.api.examples;
+
+import cn.jpush.api.JPushClient;
+import cn.jpush.api.common.resp.APIConnectionException;
+import cn.jpush.api.common.resp.APIRequestException;
+import cn.jpush.api.push.model.PushPayload;
+import cn.jpush.api.schedule.ScheduleListResult;
+import cn.jpush.api.schedule.ScheduleResult;
+import cn.jpush.api.schedule.model.SchedulePayload;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ScheduleExample {
+
+ protected static final Logger LOG = LoggerFactory.getLogger(ScheduleExample.class);
+
+ private static final String appKey ="e5c0d34f58732cf09b2d4d74";
+ private static final String masterSecret = "4cdda6d3c8b029941dbc5cb3";
+
+ public static void main(String[] args) {
+
+// testDeleteSchedule();
+ testGetScheduleList();
+// testUpdateSchedule();
+ testGetSchedule();
+ }
+
+ public static void testCreateSingleSchedule() {
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+ String name = "test_schedule_example";
+ String time = "2016-07-30 12:30:25";
+ PushPayload push = PushPayload.alertAll("test schedule example.");
+ try {
+ ScheduleResult result = jpushClient.createSingleSchedule(name, time, push);
+ LOG.info("schedule result is " + result);
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
+ }
+
+ public static void testDeleteSchedule() {
+ String scheduleId = "95bbd066-3a88-11e5-8e62-0021f652c102";
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+
+ try {
+ jpushClient.deleteSchedule(scheduleId);
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
+ }
+
+ public static void testGetScheduleList() {
+ int page = 1;
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+
+ try {
+ ScheduleListResult list = jpushClient.getScheduleList(page);
+ LOG.info("total " + list.getTotal_count());
+ for(ScheduleResult s : list.getSchedules()) {
+ LOG.info(s.toString());
+ }
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
+ }
+
+ public static void testUpdateSchedule() {
+ String scheduleId = "95bbd066-3a88-11e5-8e62-0021f652c102";
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+ SchedulePayload payload = SchedulePayload.newBuilder()
+ .setEnabled(false)
+ .build();
+ try {
+ jpushClient.updateSchedule(scheduleId, payload);
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
+ }
+
+ public static void testGetSchedule() {
+ String scheduleId = "95bbd066-3a88-11e5-8e62-0021f652c102";
+ JPushClient jpushClient = new JPushClient(masterSecret, appKey);
+
+ try {
+ ScheduleResult result = jpushClient.getSchedule(scheduleId);
+ LOG.info("schedule " + result);
+ } catch (APIConnectionException e) {
+ LOG.error("Connection error. Should retry later. ", e);
+ } catch (APIRequestException e) {
+ LOG.error("Error response from JPush server. Should review and fix it. ", e);
+ LOG.info("HTTP Status: " + e.getStatus());
+ LOG.info("Error Code: " + e.getErrorCode());
+ LOG.info("Error Message: " + e.getErrorMessage());
+ }
+ }
+
+
+}
diff --git a/pom.xml b/pom.xml
index 50eb2825..5dd458ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
UTF-8
1.6
1.6
- -Xdoclint:none
+
diff --git a/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java b/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java
index a3c0ced1..eb52944d 100644
--- a/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java
+++ b/src/main/java/cn/jpush/api/common/connection/NativeHttpClient.java
@@ -208,6 +208,10 @@ private ResponseWrapper _doRequest(String url, String content,
LOG.error("Request is forbidden! Maybe your appkey is listed in blacklist or your params is invalid.");
wrapper.setErrorObject();
break;
+ case 404:
+ LOG.error("Request page is not found! Maybe your params is invalid.");
+ wrapper.setErrorObject();
+ break;
case 410:
LOG.error("Request resource is no longer in service. Please according to notice on official website.");
wrapper.setErrorObject();
diff --git a/src/main/java/cn/jpush/api/schedule/ScheduleClient.java b/src/main/java/cn/jpush/api/schedule/ScheduleClient.java
index d475b54d..3219e748 100644
--- a/src/main/java/cn/jpush/api/schedule/ScheduleClient.java
+++ b/src/main/java/cn/jpush/api/schedule/ScheduleClient.java
@@ -9,11 +9,11 @@
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.common.resp.ResponseWrapper;
import cn.jpush.api.schedule.model.SchedulePayload;
+import cn.jpush.api.utils.Preconditions;
+import cn.jpush.api.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.lang.reflect.Proxy;
-
public class ScheduleClient {
private static final Logger LOG = LoggerFactory.getLogger(ScheduleClient.class);
@@ -52,28 +52,43 @@ public ScheduleClient(String masterSecret, String appKey, int maxRetryTimes, Htt
}
public ScheduleResult createSchedule(SchedulePayload payload) throws APIConnectionException, APIRequestException {
+
+ Preconditions.checkArgument(null != payload, "payload should not be null");
+
ResponseWrapper response = _httpClient.sendPost(hostName + schedulePath, payload.toString());
return ScheduleResult.fromResponse(response, ScheduleResult.class);
}
public ScheduleListResult getScheduleList(int page) throws APIConnectionException, APIRequestException{
+
+ Preconditions.checkArgument(page > 0, "page should more than 0.");
+
ResponseWrapper response = _httpClient.sendGet(hostName + schedulePath + "?page=" + page);
return ScheduleListResult.fromResponse(response, ScheduleListResult.class);
}
public ScheduleResult getSchedule(String scheduleId) throws APIConnectionException, APIRequestException{
- ResponseWrapper response = _httpClient.sendGet(hostName + schedulePath + "/" + scheduleId);
+ Preconditions.checkArgument(StringUtils.isNotEmpty(scheduleId), "scheduleId should not be empty");
+
+ ResponseWrapper response = _httpClient.sendGet(hostName + schedulePath + "/" + scheduleId);
return ScheduleResult.fromResponse(response, ScheduleResult.class);
}
public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload) throws APIConnectionException, APIRequestException{
+
+ Preconditions.checkArgument(StringUtils.isNotEmpty(scheduleId), "scheduleId should not be empty");
+ Preconditions.checkArgument(null != payload, "payload should not be null");
+
ResponseWrapper response = _httpClient.sendPut(hostName + schedulePath + "/" + scheduleId,
payload.toString());
return ScheduleResult.fromResponse(response, ScheduleResult.class);
}
public void deleteSchedule(String scheduleId) throws APIConnectionException, APIRequestException{
+
+ Preconditions.checkArgument(StringUtils.isNotEmpty(scheduleId), "scheduleId should not be empty");
+
_httpClient.sendDelete(hostName + schedulePath + "/" + scheduleId);
}
diff --git a/src/main/java/cn/jpush/api/schedule/ScheduleListResult.java b/src/main/java/cn/jpush/api/schedule/ScheduleListResult.java
index 0deeff14..eeda28db 100644
--- a/src/main/java/cn/jpush/api/schedule/ScheduleListResult.java
+++ b/src/main/java/cn/jpush/api/schedule/ScheduleListResult.java
@@ -12,4 +12,20 @@ public class ScheduleListResult extends BaseResult{
@Expose int total_pages;
@Expose int page;
@Expose List schedules;
+
+ public int getTotal_count() {
+ return total_count;
+ }
+
+ public int getTotal_pages() {
+ return total_pages;
+ }
+
+ public int getPage() {
+ return page;
+ }
+
+ public List getSchedules() {
+ return schedules;
+ }
}
diff --git a/src/main/java/cn/jpush/api/schedule/ScheduleResult.java b/src/main/java/cn/jpush/api/schedule/ScheduleResult.java
index ceb0fbf9..50619aa4 100644
--- a/src/main/java/cn/jpush/api/schedule/ScheduleResult.java
+++ b/src/main/java/cn/jpush/api/schedule/ScheduleResult.java
@@ -11,4 +11,24 @@ public class ScheduleResult extends BaseResult{
@Expose Boolean enabled;
@Expose JsonObject trigger;
@Expose JsonObject push;
+
+ public String getSchedule_id() {
+ return schedule_id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Boolean getEnabled() {
+ return enabled;
+ }
+
+ public JsonObject getTrigger() {
+ return trigger;
+ }
+
+ public JsonObject getPush() {
+ return push;
+ }
}
diff --git a/src/main/java/cn/jpush/api/schedule/model/TriggerPayload.java b/src/main/java/cn/jpush/api/schedule/model/TriggerPayload.java
index 376a3600..7cb6bdb0 100644
--- a/src/main/java/cn/jpush/api/schedule/model/TriggerPayload.java
+++ b/src/main/java/cn/jpush/api/schedule/model/TriggerPayload.java
@@ -93,7 +93,7 @@ public static class Builder{
/**
* Setup time for single trigger.
* @param time The execute time, format yyyy-MM-dd HH:mm:ss
- * @return
+ * @return this Builder
*/
public Builder setSingleTime(String time) {
this.time = time;
@@ -106,7 +106,7 @@ public Builder setSingleTime(String time) {
* @param start The start time, format yyyy-MM-dd HH:mm:ss
* @param end The end time, format yyyy-MM-dd HH:mm:ss
* @param time The execute time, format HH:mm:ss
- * @return
+ * @return this Builder
*/
public Builder setPeriodTime(String start, String end, String time) {
this.start = start;
@@ -123,7 +123,7 @@ public Builder setPeriodTime(String start, String end, String time) {
* If time unit is day, the point should be null.
* If time unit is week, should be the abbreviation of the days. eg. {"MON", "TUE"}
* If time unit is month, should be the date of the days. eg. {"01", "03"}
- * @return
+ * @return this Builder
*/
public Builder setTimeFrequency(TimeUnit time_unit, int frequency, String[] point) {
this.time_unit = time_unit;
diff --git a/src/main/resources/javadoc-overview.html b/src/main/resources/javadoc-overview.html
index 8abe99a1..7b36a45e 100644
--- a/src/main/resources/javadoc-overview.html
+++ b/src/main/resources/javadoc-overview.html
@@ -5,6 +5,6 @@
JPush API Java 客户端。
- 主要分为 2 个功能部分:推送、报表。
+ 主要分为 4 个功能部分:推送、报表、Tag/Alias管理、定时任务管理