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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<url>https://github.com/jpush/jpush-api-java-client</url>
<connection>scm:git:git@github.com:jpush/jpush-api-java-client.git</connection>
<developerConnection>scm:git:git@github.com:jpush/jpush-api-java-client.git</developerConnection>
<tag>v3.2.7</tag>
<tag>v3.2.8</tag>
</scm>

<dependencies>
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/cn/jpush/api/JPushClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpProxy proxy, ClientConfig conf,
boolean apnsProduction, long timeToLive) {
conf.setMaxRetryTimes(maxRetryTimes);
conf.setApnsProduction(apnsProduction);
conf.setTimeToLive(timeToLive);
_pushClient = new PushClient(masterSecret, appKey, proxy, conf);
_reportClient = new ReportClient(masterSecret, appKey, proxy, conf);
_deviceClient = new DeviceClient(masterSecret, appKey, proxy, conf);
_scheduleClient = new ScheduleClient(masterSecret, appKey, proxy, conf);
_pushClient.setDefaults(apnsProduction, timeToLive);

}

/**
Expand All @@ -159,7 +159,10 @@ public JPushClient(String masterSecret, String appKey, int maxRetryTimes, HttpPr
*/
@Deprecated
public JPushClient(String masterSecret, String appKey, boolean apnsProduction, long timeToLive) {
_pushClient = new PushClient(masterSecret, appKey, apnsProduction, timeToLive);
ClientConfig conf = ClientConfig.getInstance();
conf.setApnsProduction(apnsProduction);
conf.setTimeToLive(timeToLive);
_pushClient = new PushClient(masterSecret, appKey);
_reportClient = new ReportClient(masterSecret, appKey);
_deviceClient = new DeviceClient(masterSecret, appKey);
_scheduleClient = new ScheduleClient(masterSecret, appKey);
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cn/jpush/api/common/resp/BaseResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public abstract class BaseResult implements IRateLimiting {
import java.io.Serializable;

public abstract class BaseResult implements IRateLimiting, Serializable {
public static final int ERROR_CODE_NONE = -1;
public static final int ERROR_CODE_OK = 0;
public static final String ERROR_MESSAGE_NONE = "None error message.";

protected static final int RESPONSE_OK = 200;
protected static Gson _gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();


private static final long serialVersionUID = 4810924314887130678L;

private ResponseWrapper responseWrapper;

public void setResponseWrapper(ResponseWrapper responseWrapper) {
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cn/jpush/api/common/resp/ResponseWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ResponseWrapper {
import java.io.Serializable;

public class ResponseWrapper implements Serializable {

private static final Logger LOG = LoggerFactory.getLogger(ResponseWrapper.class);
private static final int RESPONSE_CODE_NONE = -1;

private static final long serialVersionUID = -4227962073448507865L;

private static Gson _gson = new Gson();
private static JsonParser jsonParser = new JsonParser();

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/cn/jpush/api/device/DeviceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ public DefaultResult updateDeviceTagAlias(String registrationId, String alias,
public DefaultResult bindMobile(String registrationId, String mobile)
throws APIConnectionException, APIRequestException
{
Preconditions.checkArgument(StringUtils.isMobileNumber(mobile), "The mobile format is incorrect. " + mobile);

if ("".equals(mobile)) {
// delete bind while mobile is empty.
} else {
Preconditions.checkArgument(StringUtils.isMobileNumber(mobile), "The mobile format is incorrect. " + mobile);
}

String url = hostName + devicesPath + "/" + registrationId;
JsonObject top = new JsonObject();
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/cn/jpush/api/device/OnlineStatus.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package cn.jpush.api.device;

public class OnlineStatus {
import java.io.Serializable;

Boolean online;
String last_online_time;
public class OnlineStatus implements Serializable {

private static final long serialVersionUID = -5436655826293828109L;

private Boolean online;
private String last_online_time;

public Boolean getOnline() {
return online;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/cn/jpush/api/device/TagAliasResult.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cn.jpush.api.device;

import java.util.List;

import cn.jpush.api.common.resp.BaseResult;

import com.google.gson.annotations.Expose;

import java.util.List;

public class TagAliasResult extends BaseResult {

private static final long serialVersionUID = -4765083329495728276L;
@Expose public List<String> tags;
@Expose public String alias;

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/jpush/api/device/TagListResult.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package cn.jpush.api.device;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.api.common.resp.BaseResult;

import com.google.gson.annotations.Expose;

import java.util.ArrayList;
import java.util.List;

public class TagListResult extends BaseResult {


private static final long serialVersionUID = -5395153728332839175L;
@Expose public List<String> tags = new ArrayList<String>();

}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/cn/jpush/api/push/PushResult.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package cn.jpush.api.push;

import cn.jpush.api.common.resp.BaseResult;

import com.google.gson.annotations.Expose;

public class PushResult extends BaseResult {


private static final long serialVersionUID = 93783137655776743L;

@Expose public long msg_id;
@Expose public int sendno;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/report/MessagesResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class MessagesResult extends BaseResult {
private static final Type MESSAGE_TYPE = new TypeToken<List<Message>>() {}.getType();
private static final long serialVersionUID = -1582895355000647292L;

@Expose
public List<Message> messages = new ArrayList<Message>();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/cn/jpush/api/report/ReceivedsResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class ReceivedsResult extends BaseResult {
private static final Type RECEIVED_TYPE = new TypeToken<List<Received>>() {}.getType();
private static final long serialVersionUID = 1761456104618847304L;

@Expose
public List<Received> received_list = new ArrayList<Received>();
Expand All @@ -24,7 +25,7 @@ public static class Received {
@Expose
public int ios_apns_sent;
@Expose
public int ios_msg_receive;
public int ios_msg_received;
@Expose
public int wp_mpns_sent;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/report/UsersResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public class UsersResult extends BaseResult {

private static final long serialVersionUID = -963296929272770550L;
@Expose public TimeUnit time_unit;
@Expose public String start;
@Expose public int duration;
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/cn/jpush/api/schedule/ScheduleClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class ScheduleClient {
private String hostName;
private String schedulePath;

// If not present, true by default.
private int apnsProduction;

// If not present, the default value is 86400(s) (one day)
private long timeToLive;

public ScheduleClient(String masterSecret, String appkey) {
this(masterSecret, appkey, null, ClientConfig.getInstance());
}
Expand All @@ -47,6 +53,8 @@ public ScheduleClient(String masterSecret, String appKey, int maxRetryTimes, Htt

hostName = (String) conf.get(ClientConfig.SCHEDULE_HOST_NAME);
schedulePath = (String) conf.get(ClientConfig.SCHEDULE_PATH);
apnsProduction = (Integer) conf.get(ClientConfig.APNS_PRODUCTION);
timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);

String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
Expand All @@ -63,6 +71,8 @@ public ScheduleClient(String masterSecret, String appKey, HttpProxy proxy, Clien
ServiceHelper.checkBasic(appKey, masterSecret);
hostName = (String) conf.get(ClientConfig.SCHEDULE_HOST_NAME);
schedulePath = (String) conf.get(ClientConfig.SCHEDULE_PATH);
apnsProduction = (Integer) conf.get(ClientConfig.APNS_PRODUCTION);
timeToLive = (Long) conf.get(ClientConfig.TIME_TO_LIVE);

String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
this._httpClient = new NativeHttpClient(authCode, proxy, conf);
Expand All @@ -72,6 +82,16 @@ public ScheduleResult createSchedule(SchedulePayload payload) throws APIConnecti

Preconditions.checkArgument(null != payload, "payload should not be null");

if (apnsProduction > 0) {
payload.resetPushApnsProduction(true);
} else if(apnsProduction == 0) {
payload.resetPushApnsProduction(false);
}

if (timeToLive >= 0) {
payload.resetPushTimeToLive(timeToLive);
}

ResponseWrapper response = _httpClient.sendPost(hostName + schedulePath, payload.toString());
return ScheduleResult.fromResponse(response, ScheduleResult.class);
}
Expand All @@ -97,6 +117,16 @@ public ScheduleResult updateSchedule(String scheduleId, SchedulePayload payload)
Preconditions.checkArgument(StringUtils.isNotEmpty(scheduleId), "scheduleId should not be empty");
Preconditions.checkArgument(null != payload, "payload should not be null");

if (apnsProduction > 0) {
payload.resetPushApnsProduction(true);
} else if(apnsProduction == 0) {
payload.resetPushApnsProduction(false);
}

if (timeToLive >= 0) {
payload.resetPushTimeToLive(timeToLive);
}

ResponseWrapper response = _httpClient.sendPut(hostName + schedulePath + "/" + scheduleId,
payload.toString());
return ScheduleResult.fromResponse(response, ScheduleResult.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class ScheduleListResult extends BaseResult{

private static final long serialVersionUID = 86248096939746151L;
@Expose int total_count;
@Expose int total_pages;
@Expose int page;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/jpush/api/schedule/ScheduleResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class ScheduleResult extends BaseResult{

private static final long serialVersionUID = 995450157929190757L;
@Expose String schedule_id;
@Expose String name;
@Expose Boolean enabled;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/cn/jpush/api/schedule/model/SchedulePayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public String toString() {
return gson.toJson(toJSON());
}

public void resetPushApnsProduction(boolean apnsProduction) {
if(null != push) {
push.resetOptionsApnsProduction(apnsProduction);
}
}

public void resetPushTimeToLive(long timeToLive) {
if(null != push) {
push.resetOptionsTimeToLive(timeToLive);
}
}

public static class Builder{
private String name;
private Boolean enabled;
Expand Down