List of usage examples for javax.servlet.http HttpServletResponse SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for javax.servlet.http HttpServletResponse SC_BAD_REQUEST.
Click Source Link
From source file:io.lavagna.web.security.login.PersonaLogin.java
@Override public boolean doAction(HttpServletRequest req, HttpServletResponse resp) throws IOException { if (!("POST".equalsIgnoreCase(req.getMethod()) && req.getParameterMap().containsKey("assertion"))) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); return true; }/*from w ww. j a v a 2 s . c o m*/ String audience = configurationRepository.getValue(Key.PERSONA_AUDIENCE); MultiValueMap<String, String> toPost = new LinkedMultiValueMap<>(); toPost.add("assertion", req.getParameter("assertion")); toPost.add("audience", audience); VerifierResponse verifier = restTemplate.postForObject("https://verifier.login.persona.org/verify", toPost, VerifierResponse.class); if ("okay".equals(verifier.status) && audience.equals(verifier.audience) && userRepository.userExistsAndEnabled(USER_PROVIDER, verifier.email)) { String url = Redirector.cleanupRequestedUrl(req.getParameter("reqUrl")); UserSession.setUser(userRepository.findUserByName(USER_PROVIDER, verifier.email), req, resp, userRepository); resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); JsonObject jsonObject = new JsonObject(); jsonObject.add("redirectTo", new JsonPrimitive(url)); resp.getWriter().write(jsonObject.toString()); } else { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } return true; }
From source file:org.magnum.mobilecloud.video.VideoLikeController.java
@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like", method = RequestMethod.POST) public void likeVideo(@PathVariable("id") long id, Principal p, HttpServletResponse resp) { Video v = videos.findOne(id);// w ww. ja v a 2 s .c om if (v == null) { resp.setStatus(HttpServletResponse.SC_NOT_FOUND); } else { Set<String> likedUsernames = v.getLikedUsernames(); String username = p.getName(); if (likedUsernames.contains(username)) { resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); } else { likedUsernames.add(username); v.setLikedUsernames(likedUsernames); v.setLikes(likedUsernames.size()); videos.save(v); } } }
From source file:com.google.gwt.benchmark.dashboard.server.servlets.AddBenchmarkResultServlet.java
@Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String auth = req.getHeader("auth"); if (!authController.validateAuth(auth)) { resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED); return;/*from w ww.ja va 2 s .c o m*/ } BenchmarkRunJson benchmarkRunJSON = null; String json = null; try { json = IOUtils.toString(req.getInputStream(), "UTF-8"); AutoBean<BenchmarkRunJson> bean = AutoBeanCodex.decode(JsonFactory.get(), BenchmarkRunJson.class, json); benchmarkRunJSON = bean.as(); } catch (Exception e) { logger.log(Level.WARNING, "Can not deserialize JSON", e); if (json != null) { logger.warning(json); } resp.setStatus(HttpServletResponse.SC_BAD_REQUEST); resp.getWriter().write("Can't parse JSON, see App Engine log for details."); return; } try { benchmarkController.addBenchmarkResult(benchmarkRunJSON); resp.setStatus(HttpServletResponse.SC_OK); } catch (Exception e) { logger.log(Level.WARNING, "Can not add benchmark results", e); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:cltestgrid.Upload2.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { try {/*www . ja v a 2 s . co m*/ /* During migration we wanted to upload logs under their old names. // Use req.getQueryString instead of req.getParameters, as it mutst be a POST // request, and we want to parse the request body ourselves. final boolean keepNames = (req.getQueryString() + "").contains("keepNames=true"); */ final boolean keepNames = false; Map<String, String> map = saveBlobs(req, keepNames); String result = asAssocList(map); log.info("returning blobName-blobKey map: " + result); resp.getWriter().write(result); } catch (BadRequestException e) { log.log(Level.SEVERE, "Bad request, returning status 400", e); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } }
From source file:com.devicehive.util.ServerResponsesFactory.java
public static String parseNotificationStatus(DeviceNotification notificationMessage) { Assert.notNull(notificationMessage.getParameters(), "Notification parameters are required."); String jsonParametersString = notificationMessage.getParameters().getJsonString(); Gson gson = GsonFactory.createGson(); JsonElement parametersJsonElement = gson.fromJson(jsonParametersString, JsonElement.class); JsonObject statusJsonObject;//from w w w .j av a 2 s .c o m if (parametersJsonElement instanceof JsonObject) { statusJsonObject = (JsonObject) parametersJsonElement; } else { throw new HiveException(Messages.PARAMS_NOT_JSON, HttpServletResponse.SC_BAD_REQUEST); } JsonElement jsonElement = statusJsonObject.get(Constants.STATUS); Assert.notNull(jsonElement, "Parameter " + Constants.STATUS + " is required."); return jsonElement.getAsString(); }
From source file:org.callistasoftware.netcare.web.mobile.controller.BankIdController.java
@RequestMapping(value = "/authenticate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @ResponseBody/*from ww w. ja v a 2 s . c o m*/ public String authenticate(@RequestParam(value = "crn", required = true) String crn, HttpServletResponse response) throws IOException { log.info("Authenticating user {}", crn); final PatientEntity ent = repo.findByCivicRegistrationNumber(crn.trim()); if (ent != null) { try { return service.authenticate(new CivicRegistrationNumber(crn)); } catch (final Exception e) { log.error("Error in bank id service. Message: {}", e.getMessage()); response.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); return null; } } log.info("User {} does not have an account in the system", crn); response.sendError(HttpServletResponse.SC_NOT_FOUND, "The user does not have an account..."); return null; }
From source file:com.thinkberg.webdav.CopyMoveBase.java
/** * Handle a COPY or MOVE request./*from ww w. java 2 s .c o m*/ * * @param request the servlet request * @param response the servlet response * @throws IOException if there is an error executing this request */ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean overwrite = getOverwrite(request); FileObject object = VFSBackend.resolveFile(request.getPathInfo()); FileObject targetObject = getDestination(request); try { final LockManager lockManager = LockManager.getInstance(); LockManager.EvaluationResult evaluation = lockManager.evaluateCondition(targetObject, getIf(request)); if (!evaluation.result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if ("MOVE".equals(request.getMethod())) { evaluation = lockManager.evaluateCondition(object, getIf(request)); if (!evaluation.result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if (null == targetObject) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } if (object.equals(targetObject)) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (targetObject.exists()) { if (!overwrite) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } response.setStatus(HttpServletResponse.SC_NO_CONTENT); } else { FileObject targetParent = targetObject.getParent(); if (!targetParent.exists() || !FileType.FOLDER.equals(targetParent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); } response.setStatus(HttpServletResponse.SC_CREATED); } // delegate the actual execution to a sub class copyOrMove(object, targetObject, getDepth(request)); }
From source file:fedora.server.management.UploadServlet.java
/** * The servlet entry point. http://host:port/fedora/management/upload *///from w w w. ja v a 2 s . c om @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Context context = ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri, request); try { // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(); // Parse the request, looking for "file" InputStream in = null; FileItemIterator iter = upload.getItemIterator(request); while (in == null && iter.hasNext()) { FileItemStream item = iter.next(); LOG.info("Got next item: isFormField=" + item.isFormField() + " fieldName=" + item.getFieldName()); if (!item.isFormField() && item.getFieldName().equals("file")) { in = item.openStream(); } } if (in == null) { sendResponse(HttpServletResponse.SC_BAD_REQUEST, "No data sent.", response); } else { sendResponse(HttpServletResponse.SC_CREATED, s_management.putTempStream(context, in), response); } } catch (AuthzException ae) { throw RootException.getServletException(ae, request, "Upload", new String[0]); } catch (Exception e) { e.printStackTrace(); sendResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getClass().getName() + ": " + e.getMessage(), response); } }
From source file:com.oneops.transistor.ws.rest.CatalogRestController.java
@ExceptionHandler(DJException.class) public void handleDJExceptions(DJException e, HttpServletResponse response) throws IOException { logger.error(e);/*from ww w.jav a 2 s.c o m*/ sendError(response, HttpServletResponse.SC_BAD_REQUEST, e); }
From source file:de.thm.arsnova.controller.UserController.java
@RequestMapping(value = { "/register" }, method = RequestMethod.POST) public void register(@RequestParam final String username, @RequestParam final String password, final HttpServletRequest request, final HttpServletResponse response) { if (null != userService.createDbUser(username, password)) { return;/*from ww w. j a va2 s . c o m*/ } /* TODO: Improve error handling: send reason to client */ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); }