public static String checkLogin(String userMobileNo, Context _context) throws Exception { String errorCode = ""; try { JSONObject reqParameters = new JSONObject(); reqParameters.put("UMOBILENO", userMobileNo); JsonHandler jsonHandler = JsonHandler.getInstance(); String url = jsonHandler.getFullUrl("UserLogin.php"); JSONObject result = jsonHandler.postJsonDataToServer(url, reqParameters, _context); if (result != null) { String resultCode = result.getString("RESULT"); if (resultCode.contentEquals(AppConstant.PHPRESPONSE_KO)) { errorCode = result.getString("ERRORCODE"); } else { JSONObject jsonData = result.getJSONObject("USERDATA"); UserDTO userDto = new UserDTO(); LaunchActivity.loginUserId = jsonData.getInt("USERID"); userDto.setUserId(LaunchActivity.loginUserId); userDto.setFirstName(jsonData.getString("UFNAME")); userDto.setLastName(jsonData.getString("ULNAME")); userDto.setCityId(jsonData.getInt("CITYID")); userDto.setGender(jsonData.getInt("GENDER")); userDto.setAge(jsonData.getInt("AGE")); userDto.setContactNo(jsonData.getString("UCONTACTNO")); userDto.setUserCity(jsonData.getString("USERCITY")); userDto.setAppLoginUser(true); LaunchActivity.repository.addUserDTO(userDto); } } else { errorCode = PHP_ERROR_CODE.TECHNICAL; } } catch (JSONException e) { // e.printStackTrace(); throw e; } catch (ClientProtocolException e) { // e.printStackTrace(); throw e; } catch (IOException e) { // e.printStackTrace(); throw e; } catch (Exception e) { // e.printStackTrace(); throw e; } return errorCode; }
/** * Actually resolve the given exception that got thrown during on handler execution, returning a * ModelAndView that represents a specific error page if appropriate. * * <p>May be overridden in subclasses, in order to apply specific exception checks. Note that this * template method will be invoked <i>after</i> checking whether this resolved applies * ("mappedHandlers" etc), so an implementation may simply proceed with its actual exception * handling. * * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen at the time of the * exception (for example, if multipart resolution failed) * @param ex the exception that got thrown during handler execution * @return a corresponding ModelAndView to forward to, or {@code null} for default processing */ @Override protected ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { HandlerMethod methodHandler = (HandlerMethod) handler; if (methodHandler == null) { return null; } Method method = methodHandler.getMethod(); if (method.isAnnotationPresent(JsonResponseBody.class)) { String config = super.determineViewName(ex, request); Object value = Strings.isNullOrEmpty(config) ? ex : JsonHandler.parseConfig(config, ex); JsonHandler.write(value, method, request, response); // skip other resolver and view render return ModelAndViewResolver.UNRESOLVED; } return super.doResolveException(request, response, handler, ex); }
public void execute(Context context, String assetName, JsonHandler handler) throws HandlerException { try { final InputStream input = context.getAssets().open(assetName); final JsonParser parser = JsonHandlerUtils.newJsonParser(input); handler.parseAndApply(parser, mResolver); } catch (HandlerException e) { throw e; } catch (JsonParseException e) { throw new HandlerException("Problem parsing local asset: " + assetName, e); } catch (IOException e) { throw new HandlerException("Problem parsing local asset: " + assetName, e); } }