Skip to content

Commit 8ae4bd7

Browse files
committed
项目文档补充
1 parent 7f98f31 commit 8ae4bd7

File tree

12 files changed

+143
-53
lines changed

12 files changed

+143
-53
lines changed

Advanced/app/src/main/java/com/bihe0832/request/libware/TextUtils.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
88

9+
/**
10+
* 基本的工具类 处理字符串判空、编码格式转换等
11+
*/
912
public class TextUtils {
10-
/**
11-
* 判断字符串是否为空
12-
*
13-
* @param s
14-
* 需要判断的字符串
15-
* @return boolean 为空返回true
16-
*/
13+
1714
public static boolean ckIsEmpty(String s) {
1815
if (s == null || s.trim().equals("") || s.trim().equals("null")) {
1916
return true;

Advanced/app/src/main/java/com/bihe0832/request/libware/request/BaseConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Map;
1515

1616
/**
17+
* HttpURLConnection封装基类,网络请求,设置请求协议头、发送请求
18+
*
1719
* Created by hardyshi on 16/11/22.
1820
*/
1921
public abstract class BaseConnection {

Advanced/app/src/main/java/com/bihe0832/request/libware/request/HTTPConnection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import java.net.URL;
55

66
/**
7-
* Created by hardyshi on 16/11/22.
7+
*
8+
* HTTP 请求类
9+
*
810
*/
911
public class HTTPConnection extends BaseConnection {
1012

Advanced/app/src/main/java/com/bihe0832/request/libware/request/HTTPRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.bihe0832.request.libware.request;
22

33
/**
4-
* Created by hardyshi on 16/11/22.
4+
* 网络请求基类中将请求结果处理后的返回内容转化为业务逻辑相关错误
55
*/
66
public abstract class HTTPRequestHandler {
77
public abstract void onSuccess(int statusCode,String response);

Advanced/app/src/main/java/com/bihe0832/request/libware/request/HTTPSConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import javax.net.ssl.TrustManager;
1111

1212
/**
13-
* Created by hardyshi on 16/11/22.
13+
* HTTPS 请求类
1414
*/
1515
public class HTTPSConnection extends BaseConnection {
1616

Advanced/app/src/main/java/com/bihe0832/request/libware/request/HTTPServer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
import java.net.HttpURLConnection;
1313

14+
/**
15+
* 网络请求分发、执行类
16+
*/
1417
public class HTTPServer {
1518

1619
private static final String LOG_TAG = "bihe0832 REQUEST";

Advanced/app/src/main/java/com/bihe0832/request/libware/request/HttpRequest.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010

1111
import java.util.HashMap;
1212

13+
/**
14+
*
15+
* 网络请求实例类的基类,所有具体的网络请求都是他的实现,他与{@link HttpResponse}一般成对使用
16+
*
17+
*/
1318

1419
public abstract class HttpRequest {
1520

@@ -56,19 +61,12 @@ public void onSuccess(int statusCode,String response) {
5661
if(TextUtils.ckIsEmpty(response)){
5762
Log.e(LOG_TAG,"responseBody is null");
5863
}else{
59-
int flag = HTTPServer.Error;
6064
try {
6165
JSONObject json = new JSONObject(response);
6266
int ret = json.getInt(HttpResponse.HTTP_RESP_PARAM_RET);
63-
if (ret == 0) {
64-
flag = HTTPServer.Succ;
65-
} else {
66-
flag = ret;
67-
}
6867
onRequestSuccess(ret, json);
6968
} catch (JSONException e) {
70-
flag = HTTPServer.HttpRespParseError;
71-
onRequestFailure(flag, response);
69+
onRequestFailure(HTTPServer.HttpRespParseError, response);
7270
}
7371
}
7472
}catch (Exception e){
@@ -79,18 +77,13 @@ public void onSuccess(int statusCode,String response) {
7977

8078
@Override
8179
public void onFailure(int statusCode, String responseBody) {
82-
if (null == responseBody) {
83-
Log.e(LOG_TAG,"responseBody is null");
84-
onRequestFailure(statusCode, null);
85-
}else{
86-
onRequestFailure(statusCode, responseBody);
87-
}
8880
int code = HTTPServer.NetWorkException;
8981
if (statusCode == 0) {
9082
code = HTTPServer.NetWorkException;
9183
} else if (statusCode > 300) {
9284
code = HTTPServer.HttpSatutsError;
9385
}
86+
onRequestFailure(code, responseBody);
9487
}
9588
};
9689
}

Advanced/app/src/main/java/com/bihe0832/request/libware/request/HttpResponse.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
import org.json.JSONException;
99
import org.json.JSONObject;
1010

11+
12+
/**
13+
*
14+
* 网络请求返回结果的基类,所有具体的网络请求返回都是他的实现,他与{@link HttpRequest}一般成对使用
15+
*
16+
*/
17+
1118
public abstract class HttpResponse {
1219
private static final String LOG_TAG = "bihe0832 REQUEST";
1320

@@ -38,9 +45,9 @@ public void parseSuccessResponse(int ret, JSONObject responseJson) {
3845
}
3946
}
4047

41-
public void parseFailureResponse(int statusCode,String errorResponse) {
48+
public void parseFailureResponse(int flag,String errorResponse) {
4249
this.ret = HTTPServer.RET_FAIL;
43-
this.flag = processNetErrorCode(statusCode);
50+
this.flag = flag;
4451
if(!TextUtils.ckIsEmpty(errorResponse)){
4552
this.msg = errorResponse;
4653
}
@@ -87,18 +94,4 @@ public String toString() {
8794
builder.append("&msg=" + msg);
8895
return builder.toString();
8996
}
90-
91-
/**
92-
* @param statusCode
93-
* 当其值为0时说明是异常类错误;当其值为大于300时,说明是http错误;否则的话按默认系统错误处理 网络请求模块的错误处理
94-
*/
95-
private int processNetErrorCode(int statusCode) {
96-
int code = HTTPServer.NetWorkException;
97-
if (statusCode == 0) {
98-
code = HTTPServer.NetWorkException;
99-
} else if (statusCode > 300) {
100-
code = HTTPServer.HttpSatutsError;
101-
}
102-
return code;
103-
}
10497
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
package com.bihe0832.request.libware.request;
2+
3+
/**
4+
* 具体业务网络请求结果实例的基类
5+
*/
26
public interface HttpResponseHandler<T> {
37
public void onResponse(T response);
48
}

Advanced/app/src/main/java/com/bihe0832/request/libware/request/MyX509TrustManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import javax.net.ssl.TrustManagerFactory;
1010
import javax.net.ssl.X509TrustManager;
1111

12-
/**
13-
* Created by hardyshi on 16/11/23.
14-
*/
12+
1513
public class MyX509TrustManager implements X509TrustManager {
1614
X509TrustManager sunJSSEX509TrustManager;
1715

0 commit comments

Comments
 (0)