@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String requestFactorJson = request.getParameter("factor"); FactorClientData clientData = (FactorClientData) mRequestConverter.convert(requestFactorJson, FactorClientData.class); ResponsePayload responsePayload = new ResponsePayload(); mFactorController.storeFactor( clientData, responsePayload, ServletSecurityUtils.getLoggedUser(request)); if (responsePayload.getErrors().size() > 0) { ServletUtils.setResponseClientError(response); } else { ServletUtils.setResponseCreated(response); } ServletUtils.setResponseBody(response, mResponseFormatter.toJson(responsePayload)); }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String callback; ServletUtils.setJsonContentType(response); ResponsePayload responsePayload = new ResponsePayload(); try { callback = ServletUtils.getCallbackParameter(request); try { String action = ServletUtils.getSelectActionParameter(request); executeAction(action, request, responsePayload); } catch (AWInvalidParameterException | AWNoSuchEntityException | AWInvalidResourceIdException ex) { responsePayload.addError(ex.getMessage()); } finally { ServletUtils.printResponse(response, callback, mResponseFormatter.toJson(responsePayload)); } } catch (AWInvalidParameterException ex) { responsePayload.addError(ex.getMessage()); ServletUtils.setResponseBody(response, mResponseFormatter.toJson(responsePayload)); ServletUtils.setResponseClientError(response); } }
@Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String factorHousingJson = ServletUtils.getRequestBody(request); FactorClientData clientData = (FactorClientData) mRequestConverter.convert(factorHousingJson, FactorClientData.class); ResponsePayload responsePayload = new ResponsePayload(); Long factorId = ServletUtils.getNumberResourceId(request); if (!ValidatorUtils.isResourceValid(factorId, HttpMethod.PUT)) { ServletUtils.setResponseResourceNotFound(response); return; } mFactorController.updateFactor( factorId, clientData, responsePayload, ServletSecurityUtils.getLoggedUser(request)); if (responsePayload.getErrors().size() > 0) { ServletUtils.setResponseClientError(response); } else { ServletUtils.setResponseOk(response); } ServletUtils.setResponseBody(response, mResponseFormatter.toJson(responsePayload)); }