Client:优化错误提示;Server:Controller中update方法改名为put
This commit is contained in:
parent
02049fc569
commit
33f3fc64e7
@ -15,6 +15,6 @@
|
||||
<string name="complex">复杂结构</string>
|
||||
<string name="access_error">没有访问权限</string>
|
||||
<string name="access_permitted">允许使用权限</string>
|
||||
<string name="query_error">可能出现了一些问题,可以按照以下步骤解决:\n\n1.检查网络连接\n\n2.检查url是否为一个可用的IPV4地址\n\n3.长按[查询]按钮用浏览器发送请求\n\n4.查看目标服务器上的log\n\n5.再试一次</string>
|
||||
<string name="query_error">可能出现了一些问题,可以按照以下步骤解决:\n\n1.检查网络连接\n\n2.检查url是否为一个可用的IPV4地址\n\n3.长按[ %1$s ]按钮用浏览器发送请求\n\n4.查看目标服务器上的log\n\n5.再试一次</string>
|
||||
|
||||
</resources>
|
@ -15,7 +15,7 @@
|
||||
<string name="complex">Complex</string>
|
||||
<string name="access_error">Access Error</string>
|
||||
<string name="access_permitted">Access Permitted</string>
|
||||
<string name="query_error">There may be something wrong,you can follow by the steps:\n\n1.Check your net connection\n\n2.Check the url whether it\'s an available ipv4 address\n\n3.Long click the [get] button to open the request by web browser\n\n4.Check logs outputed on the target server\n\n5.Try again</string>
|
||||
<string name="query_error">There may be something wrong,you can follow by the steps:\n\n1.Check your net connection\n\n2.Check the url whether it\'s an available ipv4 address\n\n3.Long click the [ %1$s ] button to open the request by web browser\n\n4.Check logs outputed on the target server\n\n5.Try again</string>
|
||||
<string name="demo_post">{\n   \"tag\":\"post_user\",\n   \"User\":{\n      \"name\":\"Tommy\",\n      \"sex\":0,\n      \"phone\":\"1234567890\"\n   }\n}</string>
|
||||
<string name="demo_delete">{\n   \"tag\":\"delete_user\",\n   \"User\":{\n      \"id\":93794\n   }\n}</string>
|
||||
<string name="demo_put">{\n   \"tag\":\"put_user\",\n   \"User\":{\n      \"id\":38710,\n      \"name\":\"Lemon\",\n      \"picture\":\"[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\", \"http://common.cnblogs.com/images/icon_weibo_24.png\", \"http://static.oschina.net/uploads/user/585/1170143_50.jpg?t=1390226446000\"]\"\n   }\n}</string>
|
||||
|
@ -87,15 +87,19 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
public static final int TYPE_ACCESS_PERMITTED = 16;
|
||||
|
||||
|
||||
private int type = TYPE_SINGLE;
|
||||
private String url;
|
||||
|
||||
private Activity context;
|
||||
private boolean isAlive;
|
||||
|
||||
private int type = TYPE_COMPLEX;
|
||||
private String url;
|
||||
private String error;
|
||||
|
||||
private TextView tvQueryResult;
|
||||
private ProgressBar pbQuery;
|
||||
private EditText etQueryUrl;
|
||||
private Button btnQueryQuery;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -111,16 +115,19 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
tvQueryResult = (TextView) findViewById(R.id.tvQueryResult);
|
||||
pbQuery = (ProgressBar) findViewById(R.id.pbQuery);
|
||||
etQueryUrl = (EditText) findViewById(R.id.etQueryUrl);
|
||||
btnQueryQuery = (Button) findViewById(R.id.btnQueryQuery);
|
||||
|
||||
|
||||
etQueryUrl.setText(StringUtil.getString(StringUtil.isNotEmpty(url, true)
|
||||
? url : "http://139.196.140.118:8080/"));//TODO my server ipv4 address, edit it to your server url
|
||||
btnQueryQuery.setText(getMethod(type));
|
||||
|
||||
|
||||
error = String.format(getResources().getString(R.string.query_error), StringUtil.getTrimedString(btnQueryQuery));
|
||||
|
||||
query();
|
||||
|
||||
|
||||
Button btnQueryQuery = (Button) findViewById(R.id.btnQueryQuery);
|
||||
btnQueryQuery.setText(getMethod(type));
|
||||
|
||||
btnQueryQuery.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
@ -144,14 +151,15 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
private void query() {
|
||||
setRequest();
|
||||
|
||||
tvQueryResult.setText("requesting...\n\n url = " + url + "\n\n request = \n" + request
|
||||
+ "\n\n\n" + getResources().getString(R.string.query_error));
|
||||
final String fullUrl = getUrl(type);
|
||||
|
||||
tvQueryResult.setText("requesting...\n\n url = " + fullUrl + "\n\n request = \n" + request + "\n\n\n" + error);
|
||||
pbQuery.setVisibility(View.VISIBLE);
|
||||
|
||||
if (type < 10) {
|
||||
HttpManager.getInstance().post(getUrl(type), request, this);
|
||||
HttpManager.getInstance().post(fullUrl, request, this);
|
||||
} else {
|
||||
HttpManager.getInstance().get(getUrl(type), request, this);
|
||||
HttpManager.getInstance().get(fullUrl, request, this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -175,12 +183,12 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private String getUrl(int type) {
|
||||
return url + getMethod(type) + "/";
|
||||
return url + StringUtil.getTrimedString(btnQueryQuery) + "/";
|
||||
}
|
||||
|
||||
|
||||
private String getMethod(int type) {
|
||||
switch (type) {
|
||||
case TYPE_POST:
|
||||
@ -193,7 +201,7 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
return "get";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String request;
|
||||
public void setRequest() {
|
||||
url = StringUtil.getNoBlankString(etQueryUrl);
|
||||
@ -247,15 +255,15 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
JSONArray array = JSONResponse.getJSONArray(response.getJSONObject("[]"));//, "Comment[]");//
|
||||
if (array == null || array.isEmpty()) {
|
||||
Log.e(TAG, "onHttpResponse type == TYPE_COMPLEX >> array == null || array.isEmpty() >> return;");
|
||||
return;
|
||||
}
|
||||
response = new JSONResponse(array.getJSONObject(0));
|
||||
} else {
|
||||
response = new JSONResponse(array.getJSONObject(0));
|
||||
|
||||
User user = JSONResponse.getObject(response, User.class);
|
||||
Log.d(TAG, "onHttpResponse type == TYPE_COMPLEX >> user = " + JSON.toJSONString(user));
|
||||
Work work = JSONResponse.getObject(response, Work.class);
|
||||
Log.d(TAG, "onHttpResponse type == TYPE_COMPLEX >> work = " + JSON.toJSONString(work));
|
||||
logList(JSONResponse.getList(response == null ? null : response.getJSONObject("Comment[]"), Comment.class));
|
||||
User user = JSONResponse.getObject(response, User.class);
|
||||
Log.d(TAG, "onHttpResponse type == TYPE_COMPLEX >> user = " + JSON.toJSONString(user));
|
||||
Work work = JSONResponse.getObject(response, Work.class);
|
||||
Log.d(TAG, "onHttpResponse type == TYPE_COMPLEX >> work = " + JSON.toJSONString(work));
|
||||
logList(JSONResponse.getList(response == null ? null : response.getJSONObject("Comment[]"), Comment.class));
|
||||
}
|
||||
} else if (type == TYPE_ACCESS_PERMITTED) {
|
||||
response = new JSONResponse(resultJson);
|
||||
Wallet wallet = JSONResponse.getObject(response, Wallet.class);
|
||||
@ -271,8 +279,7 @@ public class QueryActivity extends Activity implements OnHttpResponseListener {
|
||||
Toast.makeText(context, "received result!", Toast.LENGTH_SHORT).show();
|
||||
|
||||
tvQueryResult.setText(e == null || JSON.isJsonCorrect(resultJson)
|
||||
? StringUtil.getTrimedString(resultJson)
|
||||
: e.getMessage() + "\n\n\n" + getResources().getString(R.string.query_error));
|
||||
? StringUtil.getTrimedString(resultJson) : e.getMessage() + "\n\n\n" + error);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
@RequestMapping(value="put", method = RequestMethod.POST)
|
||||
public String update(@RequestBody String request) {
|
||||
public String put(@RequestBody String request) {
|
||||
System.out.println("put/request = " + request);
|
||||
JSONObject object = new RequestParser(RequestMethod.PUT).parse(request);
|
||||
System.out.println("put/return " + JSON.toJSONString(object));
|
||||
|
Loading…
Reference in New Issue
Block a user