ServerResponse.java
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.taover.heartbeat.bean;
import org.apache.commons.lang.StringUtils;
import com.alibaba.fastjson.JSONObject;
public class ServerResponse {
public static String RESPONSE_CODE_OK = "ok";
private boolean isOverdue;
private boolean isCodeOk;
private String responseContent;
private Exception exception;
private ServerResponse(boolean isOverdue, boolean isCodeOk, String responseContent, Exception e) {
super();
this.isOverdue = isOverdue;
this.isCodeOk = isCodeOk;
this.responseContent = responseContent;
this.exception = e;
}
public boolean isOverdue() {
return isOverdue;
}
public void setOverdue(boolean isOverdue) {
this.isOverdue = isOverdue;
}
public boolean isCodeOk() {
return isCodeOk;
}
public void setCodeOk(boolean isCodeOk) {
this.isCodeOk = isCodeOk;
}
public String getResponseContent() {
return responseContent;
}
public void setResponseContent(String responseContent) {
this.responseContent = responseContent;
}
public Exception getException() {
return exception;
}
public void setException(Exception exception) {
this.exception = exception;
}
public static ServerResponse createByJSONString(String response) {
if(StringUtils.isBlank(response)) {
return new ServerResponse(false, false, response, null);
}else {
try {
JSONObject data = JSONObject.parseObject(response);
String code = data.getString("code");
if(RESPONSE_CODE_OK.equals(code.toLowerCase())) {
return new ServerResponse(false, true, response, null);
}else {
return new ServerResponse(false, false, response, null);
}
}catch (Exception e) {
return new ServerResponse(false, false, response, e);
}
}
}
public static ServerResponse createOverdue() {
return new ServerResponse(false, false, "", null);
}
public static ServerResponse createException(Exception e) {
return new ServerResponse(false, false, "", e);
}
}