List of usage examples for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY
HttpStatus UNPROCESSABLE_ENTITY
To view the source code for org.springframework.http HttpStatus UNPROCESSABLE_ENTITY.
Click Source Link
From source file:io.lavagna.web.helper.GeneralHandlerExceptionResolver.java
public GeneralHandlerExceptionResolver() { // add the exceptions from the less generic to the more one statusCodeResolver.put(EmptyResultDataAccessException.class, HttpStatus.NOT_FOUND.value()); statusCodeResolver.put(ValidationException.class, HttpStatus.UNPROCESSABLE_ENTITY.value()); }
From source file:com.sentinel.web.controllers.AdminController.java
@RequestMapping(value = "/users/{userId}/grant/role", method = RequestMethod.POST) @PreAuthorize(value = "hasRole('SUPER_ADMIN_PRIVILEGE')") @ResponseBody//from w ww. j a v a2 s. c o m public ResponseEntity<String> grantSimpleRole(@PathVariable Long userId) { User user = userRepository.findOne(userId); LOG.debug("Allow user for Simle user permissions"); if (user == null) { return new ResponseEntity<String>("invalid user id", HttpStatus.UNPROCESSABLE_ENTITY); } Role role = roleRepository.findByName("ROLE_SIMPLE_USER"); userService.grantRole(user, role); user.setEnabled(true); userRepository.saveAndFlush(user); return new ResponseEntity<String>("role granted", HttpStatus.OK); }
From source file:com.github.woki.payments.adyen.simulator.web.controller.PaymentController.java
@RequestMapping(value = { "/pal/servlet/Payment/v30/authorise", "/pal/servlet/Payment/v30/authorise3d" }, method = RequestMethod.POST) public ResponseEntity<PaymentResponse> authorize(@RequestBody PaymentRequest request) { PaymentResponse res = new PaymentResponse(); if ("gimme_500".equals(request.getReference())) { res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); return new ResponseEntity<>(res, HttpStatus.INTERNAL_SERVER_ERROR); }// ww w. j av a 2 s. c om if ("gimme_400".equals(request.getReference())) { res.setStatus(HttpStatus.BAD_REQUEST.value()); return new ResponseEntity<>(res, HttpStatus.BAD_REQUEST); } if ("gimme_422".equals(request.getReference())) { res.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return new ResponseEntity<>(res, HttpStatus.UNPROCESSABLE_ENTITY); } if ("gimme_401".equals(request.getReference())) { res.setStatus(HttpStatus.UNAUTHORIZED.value()); return new ResponseEntity<>(res, HttpStatus.UNAUTHORIZED); } if ("gimme_403".equals(request.getReference())) { res.setStatus(HttpStatus.FORBIDDEN.value()); return new ResponseEntity<>(res, HttpStatus.FORBIDDEN); } if ("gimme_404".equals(request.getReference())) { res.setStatus(HttpStatus.NOT_FOUND.value()); return new ResponseEntity<>(res, HttpStatus.NOT_FOUND); } if ("gimme_200".equals(request.getReference())) { res.setStatus(HttpStatus.OK.value()); return new ResponseEntity<>(res, HttpStatus.OK); } res.setStatus(HttpStatus.NON_AUTHORITATIVE_INFORMATION.value()); return new ResponseEntity<>(res, HttpStatus.NON_AUTHORITATIVE_INFORMATION); }
From source file:com.sra.biotech.submittool.persistence.client.SubmitExceptionHandler.java
@ExceptionHandler({ InvalidRequestException.class }) protected ResponseEntity<Object> handleInvalidRequest(RuntimeException e, WebRequest request) { InvalidRequestException ire = (InvalidRequestException) e; List<FieldErrorResource> fieldErrorResources = new ArrayList<>(); List<FieldError> fieldErrors = ire.getErrors().getFieldErrors(); for (FieldError fieldError : fieldErrors) { FieldErrorResource fieldErrorResource = new FieldErrorResource(); fieldErrorResource.setResource(fieldError.getObjectName()); fieldErrorResource.setField(fieldError.getField()); fieldErrorResource.setCode(fieldError.getCode()); fieldErrorResource.setMessage(fieldError.getDefaultMessage()); fieldErrorResources.add(fieldErrorResource); }//w w w . j a va2s. c o m ErrorResource error = new ErrorResource("InvalidRequest", ire.getMessage()); error.setFieldErrors(fieldErrorResources); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, error, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }
From source file:things.view.rest.ThingRestExceptionHandler.java
@ExceptionHandler(ConstraintViolationException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) @ResponseBody/*from w ww . jav a 2 s .c o m*/ public ErrorInfo validationException(final HttpServletRequest req, final ConstraintViolationException cve) { StringBuffer msg = new StringBuffer("Invalid input:"); cve.getConstraintViolations().forEach(cv -> { msg.append(" " + cv.getPropertyPath() + " -> " + cv.getMessage()); }); myLogger.debug(msg.toString()); ErrorInfo ei = new ErrorInfo(req.getRequestURL().toString(), cve); ei.setMessage(msg.toString()); return ei; }
From source file:org.openbaton.autoscaling.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ NotFoundException.class, NoResultException.class }) @ResponseStatus(value = HttpStatus.NOT_FOUND) protected ResponseEntity<Object> handleNotFoundException(Exception e, WebRequest request) { log.error("Exception with message " + e.getMessage() + " was thrown"); ExceptionResource exc = new ExceptionResource("Not Found", e.getMessage()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }
From source file:org.smigo.comment.CommentController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/rest/comment", produces = "application/json", method = RequestMethod.POST) @ResponseBody/* ww w . j a v a 2 s .c o m*/ public Object addMessage(@Valid @RequestBody Comment comment, BindingResult result, @AuthenticationPrincipal AuthenticatedUser user, HttpServletResponse response) { if (result.hasErrors()) { response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); } return commentHandler.addComment(comment, user.getId()); }
From source file:org.cloudfoundry.identity.uaa.login.ChangePasswordController.java
@RequestMapping(value = "/change_password.do", method = POST) public String changePassword(Model model, @RequestParam("current_password") String currentPassword, @RequestParam("new_password") String newPassword, @RequestParam("confirm_password") String confirmPassword, HttpServletResponse response) { ChangePasswordValidation validation = new ChangePasswordValidation(newPassword, confirmPassword); if (!validation.valid()) { model.addAttribute("message_code", validation.getMessageCode()); response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return "change_password"; }/* w w w. j a va 2 s . co m*/ SecurityContext securityContext = SecurityContextHolder.getContext(); String username = securityContext.getAuthentication().getName(); try { changePasswordService.changePassword(username, currentPassword, newPassword); return "redirect:profile"; } catch (RestClientException e) { model.addAttribute("message_code", "unauthorized"); } response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return "change_password"; }
From source file:org.openbaton.nfvo.api.exceptions.GlobalExceptionHandler.java
@ExceptionHandler({ NotFoundException.class, NoResultException.class }) @ResponseStatus(value = HttpStatus.NOT_FOUND) protected ResponseEntity<Object> handleNotFoundException(Exception e, WebRequest request) { if (log.isDebugEnabled()) { log.error("Exception was thrown -> Return message: " + e.getMessage(), e); } else {//from ww w.j a v a2s. c o m log.error("Exception was thrown -> Return message: " + e.getMessage()); } ExceptionResource exc = new ExceptionResource("Not Found", e.getMessage()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); return handleExceptionInternal(e, exc, headers, HttpStatus.UNPROCESSABLE_ENTITY, request); }
From source file:org.smigo.species.varieties.VarietyController.java
@PreAuthorize("isAuthenticated()") @RequestMapping(value = "/rest/variety", method = RequestMethod.POST) public Object addVariety(@Valid @RequestBody Variety variety, BindingResult result, HttpServletResponse response, @AuthenticationPrincipal AuthenticatedUser user) { if (result.hasErrors()) { response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value()); return result.getAllErrors(); }// w w w. j a v a2 s . c o m variety.setUserId(user.getId()); final int id = varietyDao.addVariety(variety); response.setStatus(HttpServletResponse.SC_CREATED); return id; }