Skip to content

Commit 47b6082

Browse files
committed
Server:接口全走HTTP POST,Parser#parseRequest取消decode;解决部分情况下取关联路径对应的对象时对路径判断错误;加强写操作安全验证:写操作必须要有where条件;批量写操作一次最多操作10条;批量操作由返回id改为返回id{};优化SQLConfig中@about解析;其它完善和优化; Client:优化JSONObject和JSONRequest,去除encode;简化JSONResponse,format只处理key;App和Test针对新版Server的其它调整优化
1 parent 99ba3ed commit 47b6082

40 files changed

+1499
-1411
lines changed

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/LoginActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {
174174
JSONResponse response = new JSONResponse(resultJson);
175175
User user = response.getObject(User.class);
176176

177-
if (response.isSucceed() == false) {
177+
if (response.isSuccess() == false) {
178178
switch (response.getCode()) {
179179
case JSONResponse.CODE_NOT_FOUND:
180180
showShortToast("账号不存在,请先注册");

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/MineFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {
321321
switch (requestCode) {
322322
case HTTP_LOUOUT:
323323
JSONResponse response = new JSONResponse(resultJson).getJSONResponse(Login.class.getSimpleName());
324-
boolean succeed = JSONResponse.isSucceed(response);
324+
boolean succeed = JSONResponse.isSuccess(response);
325325
Log.d(TAG, succeed ? "服务端退出成功" : "服务端退出失败");
326326
showShortToast(succeed ? "服务端退出成功" : "服务端退出失败");
327327
break;

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/MomentActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public void getListAsync(final int page) {
367367

368368
@Override
369369
public List<CommentItem> parseArray(String json) {
370-
return JSON.parseArray(new JSONResponse(json).getArray(CommentItem.class.getSimpleName()), CommentItem.class);
370+
return new JSONResponse(json).getList(CommentItem.class);
371371
}
372372

373373
@Override
@@ -520,7 +520,7 @@ public void run() {
520520
if (requestCode == HTTP_GET_MOMENT) {
521521
MomentItem data = JSONResponse.toObject(response, MomentItem.class);
522522
if (data == null || data.getId() <= 0) {
523-
if (JSONResponse.isSucceed(response)) {
523+
if (JSONResponse.isSuccess(response)) {
524524
showShortToast("动态不存在");
525525
MomentActivity.super.finish();//需要动画,且不需要保存缓存
526526
return;
@@ -534,7 +534,7 @@ public void run() {
534534

535535

536536
JSONResponse comment = response.getJSONResponse(Comment.class.getSimpleName());
537-
final boolean succeed = JSONResponse.isSucceed(comment);
537+
final boolean succeed = JSONResponse.isSuccess(comment);
538538
String operation = "操作";
539539
switch (requestCode) {
540540
case HTTP_COMMENT: // 新增评论

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/MomentListFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
367367
JSONRequest search = new JSONRequest();
368368
if (StringUtil.isNotEmpty(value, true)) {
369369
split = ":";
370-
search.putSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER);
370+
search.putsSearch(HttpRequest.CONTENT, value, SQL.SEARCH_TYPE_CONTAIN_ORDER);
371371
}
372372
toActivity(MomentListActivity.createIntent(context, range, id, search, false)
373373
.putExtra(INTENT_TITLE, "搜索" + split + value));

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/NumberPasswordActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {
312312
dismissProgressDialog();
313313
switch (requestCode) {
314314
case HTTP_SET_PASSWORD:
315-
if (response.isSucceed()) {
315+
if (response.isSuccess()) {
316316
showShortToast(R.string.change_succeed);
317317
saveAndExit(true);
318318
} else {

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/PasswordActivity.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ public void onHttpResponse(int requestCode, String resultJson, Exception e) {
351351
@Override
352352
public void run() {
353353
showVerifyGet(false);
354-
if (JSONResponse.isSucceed(response2) == false) {
354+
if (JSONResponse.isSuccess(response2) == false) {
355355
showShortToast(R.string.get_failed);
356356
} else if (JSONResponse.isExist(response2)) {
357357
if (type == TYPE_REGISTER) {
@@ -412,7 +412,7 @@ public void run() {
412412
case HTTP_REGISTER:
413413
User user = response.getObject(User.class);
414414
dismissProgressDialog();
415-
if (user == null || user.getId() <= 0 || JSONResponse.isSucceed(
415+
if (user == null || user.getId() <= 0 || JSONResponse.isSuccess(
416416
response.getJSONResponse(User.class.getSimpleName())) == false) {
417417
if (response.getCode() == CODE_TIME_OUT || response.getCode() == 412) {
418418
EditTextUtil.showInputedError(context, etPasswordVerify
@@ -430,7 +430,7 @@ public void run() {
430430
case HTTP_RESET_PASSWORD:
431431
response2 = response.getJSONResponse(Privacy.class.getSimpleName());
432432
dismissProgressDialog();
433-
if (JSONResponse.isSucceed(response2) == false) {
433+
if (JSONResponse.isSuccess(response2) == false) {
434434
EditTextUtil.showInputedError(context, etPasswordVerify
435435
, response.getCode() == CODE_TIME_OUT ? "验证码已过期" : "验证码错误");
436436
} else {

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/UserActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,14 @@ public void onBottomMenuItemClick(int intentCode) {
450450
public void onHttpResponse(int requestCode, String resultJson, Exception e) {
451451
JSONResponse response = new JSONResponse(resultJson);
452452
JSONResponse response2 = response.getJSONResponse(User.class.getSimpleName());
453-
boolean isSucceed = JSONResponse.isSucceed(response2);
453+
boolean isSucceed = JSONResponse.isSuccess(response2);
454454

455455
dismissProgressDialog();
456456
switch (requestCode) {
457457
case HTTP_GET:
458458
User user = response.getObject(User.class);
459459
if (user == null || user.getId() <= 0) {
460-
if (JSONResponse.isSucceed(response)) {
460+
if (JSONResponse.isSuccess(response)) {
461461
showShortToast("用户已注销");
462462
super.finish();//需要动画,且不需要保存缓存
463463
return;

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/UserListFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
383383
if (StringUtil.isNotEmpty(value, true)) {
384384
split = ":";
385385
if (isSearch) {
386-
search.putSearch(HttpRequest.NAME, value);
386+
search.putsSearch(HttpRequest.NAME, value);
387387
} else {
388-
search.put(HttpRequest.PHONE, value);
388+
search.puts(HttpRequest.PHONE, value);
389389
}
390390
}
391391
intent = isSearch

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/activity_fragment/WalletActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public void onHttpResponse(final int requestCode, final String resultJson, Excep
167167
public void run() {
168168

169169
JSONResponse response = new JSONResponse(resultJson);
170-
isSucceed = JSONResponse.isSucceed(response);
170+
isSucceed = JSONResponse.isSuccess(response);
171171

172172
dismissProgressDialog();
173173
switch (requestCode) {

APIJSON-Android/APIJSON-ADT/APIJSONApp/APIJSONApp/src/apijson/demo/client/manager/HttpManager.java

Lines changed: 14 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,32 @@
1515

1616
package apijson.demo.client.manager;
1717

18-
import android.content.Context;
19-
import android.os.AsyncTask;
20-
import android.text.TextUtils;
21-
22-
import com.squareup.okhttp.MediaType;
23-
import com.squareup.okhttp.OkHttpClient;
24-
import com.squareup.okhttp.Request;
25-
import com.squareup.okhttp.RequestBody;
26-
import com.squareup.okhttp.Response;
27-
28-
import org.json.JSONException;
29-
import org.json.JSONObject;
30-
3118
import java.io.IOException;
3219
import java.net.CookieHandler;
3320
import java.net.URI;
34-
import java.net.URLEncoder;
3521
import java.util.ArrayList;
3622
import java.util.HashMap;
3723
import java.util.List;
3824
import java.util.Map;
3925
import java.util.concurrent.TimeUnit;
4026

41-
import apijson.demo.client.application.APIJSONApplication;
42-
import zuo.biao.apijson.JSON;
43-
import zuo.biao.apijson.JSONRequest;
27+
import org.json.JSONException;
28+
4429
import zuo.biao.apijson.StringUtil;
4530
import zuo.biao.library.manager.HttpManager.OnHttpResponseListener;
4631
import zuo.biao.library.util.Log;
32+
import android.content.Context;
33+
import android.os.AsyncTask;
34+
import android.text.TextUtils;
35+
import apijson.demo.client.application.APIJSONApplication;
4736

48-
import static zuo.biao.apijson.StringUtil.UTF_8;
37+
import com.alibaba.fastjson.JSON;
38+
import com.alibaba.fastjson.JSONObject;
39+
import com.squareup.okhttp.MediaType;
40+
import com.squareup.okhttp.OkHttpClient;
41+
import com.squareup.okhttp.Request;
42+
import com.squareup.okhttp.RequestBody;
43+
import com.squareup.okhttp.Response;
4944

5045
/**HTTP请求管理类
5146
* @author Lemon
@@ -85,58 +80,6 @@ public static HttpManager getInstance() {
8580
public static final String KEY_COOKIE = "cookie";
8681

8782

88-
/**GET请求
89-
* @param url_ 接口url
90-
* @param request 请求
91-
* @param requestCode
92-
* 请求码,类似onActivityResult中请求码,当同一activity中以实现接口方式发起多个网络请求时,请求结束后都会回调
93-
* {@link OnHttpResponseListener#onHttpResponse(int, String, Exception)}<br/>
94-
* 在发起请求的类中可以用requestCode来区分各个请求
95-
* @param listener
96-
*/
97-
public void get(final String url_, final com.alibaba.fastjson.JSONObject request
98-
, final int requestCode, final OnHttpResponseListener listener) {
99-
new AsyncTask<Void, Void, Exception>() {
100-
101-
String result;
102-
@Override
103-
protected Exception doInBackground(Void... params) {
104-
String body = request == null || request.isEmpty() ? null : JSON.toJSONString(request);
105-
Log.d(TAG, "\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n get url = " + url_ + "\n request = \n" + body);
106-
try {
107-
String url = StringUtil.getNoBlankString(url_)
108-
+ (body == null ? "" : URLEncoder.encode(StringUtil.getNoBlankString(body), UTF_8));
109-
StringBuffer sb = new StringBuffer();
110-
sb.append(url);
111-
112-
OkHttpClient client = getHttpClient(url);
113-
if (client == null) {
114-
return new Exception(TAG + ".get AsyncTask.doInBackground client == null >> return;");
115-
}
116-
117-
result = getResponseJson(client, new Request.Builder()
118-
.addHeader(KEY_TOKEN, getToken(url))
119-
.url(sb.toString()).build());
120-
Log.d(TAG, "\n get result = \n" + result + "\n >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n");
121-
} catch (Exception e) {
122-
Log.e(TAG, "get AsyncTask.doInBackground try { result = getResponseJson(..." +
123-
"} catch (Exception e) {\n" + e.getMessage());
124-
return e;
125-
}
126-
127-
return null;
128-
}
129-
130-
@Override
131-
protected void onPostExecute(Exception exception) {
132-
super.onPostExecute(exception);
133-
listener.onHttpResponse(requestCode, result, exception);
134-
}
135-
136-
}.execute();
137-
138-
}
139-
14083
public static final MediaType TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
14184

14285
/**POST请求
@@ -150,11 +93,6 @@ protected void onPostExecute(Exception exception) {
15093
*/
15194
public void post(final String url_, final com.alibaba.fastjson.JSONObject request
15295
, final int requestCode, final OnHttpResponseListener listener) {
153-
if (request == null || request.containsKey(JSONRequest.KEY_TAG) == false) {
154-
throw new IllegalArgumentException("post " + url_ + " \n" +
155-
" request == null || request.containsKey(JSONRequest.KEY_TAG) == false !!!");
156-
}
157-
15896
new AsyncTask<Void, Void, Exception>() {
15997

16098
String result;
@@ -280,7 +218,7 @@ private String getResponseJson(OkHttpClient client, Request request) throws Exce
280218
* @throws JSONException
281219
*/
282220
public <T> T getValue(String json, String key) throws JSONException {
283-
return getValue(new JSONObject(json), key);
221+
return getValue(JSON.parseObject(json), key);
284222
}
285223
/**从object中获取key对应的值
286224
* *获取如果T是基本类型容易崩溃,所以需要try-catch

0 commit comments

Comments
 (0)