Search in sources :

Example 1 with BizException

use of com.shizhefei.test.models.exception.BizException in project MVCHelper by LuckyJayce.

the class LoginAsyncTask method execute.

@Override
public RequestHandle execute(final ResponseSender<User> sender) throws Exception {
    String url = "https://www.baidu.com";
    Uri.Builder builder = Uri.parse(url).buildUpon();
    builder.appendQueryParameter("userName", name);
    builder.appendQueryParameter("password", password);
    StringRequest jsonObjRequest = new StringRequest(Request.Method.GET, builder.toString(), new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            if (TextUtils.isEmpty(name)) {
                sender.sendError(new BizException("请输入用户名"));
            } else if (TextUtils.isEmpty(password)) {
                sender.sendError(new BizException("请输入密码"));
            } else if (name.equals("LuckyJayce") && password.equals("111")) {
                sender.sendData(new User("1", "LuckyJayce", 23, "中国人"));
            } else {
                sender.sendError(new BizException("用户名或者密码不正确"));
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            sender.sendError(error);
        }
    });
    MyVolley.getRequestQueue().add(jsonObjRequest);
    return new VolleyRequestHandle(jsonObjRequest);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) User(com.shizhefei.test.models.enties.User) VolleyRequestHandle(com.shizhefei.test.models.datasource.volley.VolleyRequestHandle) StringRequest(com.android.volley.toolbox.StringRequest) BizException(com.shizhefei.test.models.exception.BizException) Uri(android.net.Uri)

Example 2 with BizException

use of com.shizhefei.test.models.exception.BizException in project MVCHelper by LuckyJayce.

the class MeizhiParser method parseImp.

protected DATA parseImp(Response response) throws Exception {
    if (response.isSuccessful()) {
        String json = response.body().string();
        JSONObject jsonObject = new JSONObject(json);
        boolean error = jsonObject.getBoolean("error");
        if (!error) {
            String result = jsonObject.getString("results");
            DATA data = new JsonParser<DATA>(getClass()) {
            }.parse(result);
            return data;
        }
        throw new BizException();
    }
    throw new NetworkExeption(response);
}
Also used : JSONObject(org.json.JSONObject) BizException(com.shizhefei.test.models.exception.BizException) NetworkExeption(com.shizhefei.mvc.http.NetworkExeption)

Aggregations

BizException (com.shizhefei.test.models.exception.BizException)2 Uri (android.net.Uri)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 StringRequest (com.android.volley.toolbox.StringRequest)1 NetworkExeption (com.shizhefei.mvc.http.NetworkExeption)1 VolleyRequestHandle (com.shizhefei.test.models.datasource.volley.VolleyRequestHandle)1 User (com.shizhefei.test.models.enties.User)1 JSONObject (org.json.JSONObject)1