From 33f3fc64e7affd9ef3cc8c7853da6e380f62bccf Mon Sep 17 00:00:00 2001 From: TommyLemon <1184482681@qq.com> Date: Sun, 8 Jan 2017 17:19:54 +0800 Subject: [PATCH] =?UTF-8?q?Client=EF=BC=9A=E4=BC=98=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA=EF=BC=9BServer=EF=BC=9AController?= =?UTF-8?q?=E4=B8=ADupdate=E6=96=B9=E6=B3=95=E6=94=B9=E5=90=8D=E4=B8=BAput?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../APIJSONDemoApp/res/values-zh/strings.xml | 2 +- .../APIJSONDemoApp/res/values/strings.xml | 2 +- .../src/apijson/demo/ui/QueryActivity.java | 55 +++++++++++-------- .../zuo/biao/apijson/server/Controller.java | 2 +- 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values-zh/strings.xml b/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values-zh/strings.xml index bafb5006..831e5966 100644 --- a/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values-zh/strings.xml +++ b/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values-zh/strings.xml @@ -15,6 +15,6 @@ 复杂结构 没有访问权限 允许使用权限 - 可能出现了一些问题,可以按照以下步骤解决:\n\n1.检查网络连接\n\n2.检查url是否为一个可用的IPV4地址\n\n3.长按[查询]按钮用浏览器发送请求\n\n4.查看目标服务器上的log\n\n5.再试一次 + 可能出现了一些问题,可以按照以下步骤解决:\n\n1.检查网络连接\n\n2.检查url是否为一个可用的IPV4地址\n\n3.长按[ %1$s ]按钮用浏览器发送请求\n\n4.查看目标服务器上的log\n\n5.再试一次 \ No newline at end of file diff --git a/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values/strings.xml b/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values/strings.xml index 711e9205..7f13f7f5 100644 --- a/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values/strings.xml +++ b/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/res/values/strings.xml @@ -15,7 +15,7 @@ Complex Access Error Access Permitted - 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 + 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 {\n   \"tag\":\"post_user\",\n   \"User\":{\n      \"name\":\"Tommy\",\n      \"sex\":0,\n      \"phone\":\"1234567890\"\n   }\n} {\n   \"tag\":\"delete_user\",\n   \"User\":{\n      \"id\":93794\n   }\n} {\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} diff --git a/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/QueryActivity.java b/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/QueryActivity.java index 8b0e4f47..0bd64d26 100644 --- a/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/QueryActivity.java +++ b/APIJSON(Android)/APIJSON(ADT)/APIJSONDemoApp/src/apijson/demo/ui/QueryActivity.java @@ -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); } } diff --git a/APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Controller.java b/APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Controller.java index f04d5428..f037c041 100755 --- a/APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Controller.java +++ b/APIJSON(Server)/APIJSON(Eclipse_JEE)/src/main/java/zuo/biao/apijson/server/Controller.java @@ -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));