List of usage examples for org.springframework.http HttpStatus BAD_REQUEST
HttpStatus BAD_REQUEST
To view the source code for org.springframework.http HttpStatus BAD_REQUEST.
Click Source Link
From source file:be.bittich.quote.controller.impl.DefaultExceptionHandler.java
@RequestMapping(produces = APPLICATION_JSON) @ExceptionHandler(ConstraintViolationException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST) public @ResponseBody Map<String, Object> handleValidationException(ConstraintViolationException ex) throws IOException { Map<String, Object> map = newHashMap(); map.put("error", "Validation Failure"); map.put("violations", convertConstraintViolation(ex.getConstraintViolations())); return map;// w w w .ja v a 2 s .co m }
From source file:com.chevres.rss.restapi.controller.FeedController.java
@CrossOrigin @RequestMapping(path = "/feed", method = RequestMethod.POST) @ResponseBody/*w ww. j a va2s . co m*/ public ResponseEntity<String> addFeed(@RequestHeader(value = "User-token") String userToken, @RequestBody Feed feed, BindingResult bindingResult) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); FeedDAO feedDAO = context.getBean(FeedDAO.class); UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class); ArticleStateDAO articleStateDAO = context.getBean(ArticleStateDAO.class); UserAuth userAuth = userAuthDAO.findByToken(userToken); if (userAuth == null) { context.close(); return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST); } feedValidator.validate(feed, bindingResult); if (bindingResult.hasErrors()) { context.close(); return new ResponseEntity(new ErrorMessageResponse("bad_params"), HttpStatus.BAD_REQUEST); } if (feedDAO.doesExist(userAuth, feed.getUrl())) { context.close(); return new ResponseEntity(new ErrorMessageResponse("already_exist"), HttpStatus.BAD_REQUEST); } feed.setIdUser(userAuth.getIdUser()); feed.setRefreshError(false); feedDAO.create(feed); ArticleState newState = articleStateDAO.findByLabel(ArticleState.NEW_LABEL); int newArticles = feedDAO.getNewArticlesByFeed(feed, newState); context.close(); return new ResponseEntity(new SuccessFeedInfoResponse(feed.getId(), feed.getName(), feed.getUrl(), newArticles, feed.getRefreshError()), HttpStatus.OK); }
From source file:org.esbtools.gateway.resubmit.controller.ResubmitGateway.java
@ExceptionHandler(InvalidSystemException.class) private ResponseEntity<ResubmitResponse> invalidSystemExceptionHandler(InvalidSystemException e) { ResubmitResponse resubmitResponse = new ResubmitResponse(GatewayResponse.Status.Error, e.getMessage()); return new ResponseEntity<>(resubmitResponse, HttpStatus.BAD_REQUEST); }
From source file:plbtw.klmpk.barang.hilang.controller.LogController.java
@RequestMapping(method = RequestMethod.DELETE, produces = "application/json") public CustomResponseMessage deleteLog(@RequestBody LogRequest logRequest) { try {//w w w.j av a 2 s .c o m logService.deleteLog(logRequest.getIdLog()); return new CustomResponseMessage(HttpStatus.CREATED, "Delete log successfull"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString()); } }
From source file:br.upe.community.ui.ControllerCategoria.java
@RequestMapping(value = "/atualizar", headers = "Accept=*/*", produces = MediaType.APPLICATION_JSON_VALUE) public @ResponseBody ResponseEntity<?> atualizarCategoria(String nomeAtual, String nomeAtualizar) { Categoria categoria;//from w w w. j a v a2s . c o m try { categoria = fachada.consultarPorNomeCategoria(nomeAtual); categoria.setNome(nomeAtualizar); fachada.atualizar(nomeAtual, nomeAtualizar); return new ResponseEntity<String>(HttpStatus.OK); } catch (CategoriaInexistenteException ex) { return new ResponseEntity<CategoriaInexistenteException>(ex, HttpStatus.BAD_REQUEST); } }
From source file:com.envision.envservice.rest.AssessmentResource.java
@POST @Path("/addAssessment") @Consumes(MediaType.APPLICATION_JSON)//from ww w.j a v a2s . c o m @Produces(MediaType.APPLICATION_JSON) public Response addAssessment(AssessmentBo assessmentBo) throws Exception { HttpStatus status = HttpStatus.CREATED; String response = StringUtils.EMPTY; if (!checkParam(assessmentBo)) { status = HttpStatus.BAD_REQUEST; response = FailResult.toJson(Code.PARAM_ERROR, "?"); } else { response = assessmentService.addAssessment(assessmentBo).toJSONString(); } return Response.status(status.value()).entity(response).build(); }
From source file:se.sawano.scala.examples.scalaspringmvc.ValidationTestIT.java
@Test public void scalaJavaPostWithInvalidAge() { try {//www. j a v a 2s . co m JavaIndata indata = new JavaIndata("Daniel", -1); restTemplate.postForObject(baseUrl + "scalajava/indata", indata, Void.class, (Object) null); fail("Expected JSR-303 validation to fail"); } catch (HttpClientErrorException e) { assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); } }
From source file:org.jrb.lots.web.GlobalExceptionHandler.java
/** * Converts one of several client-based bad request exceptions into an HTTP * 400 response with an error body. The mapped exceptions are as follows: * <ul>//from w ww .j av a 2s .c o m * <li>{@link InvalidTagException}</li> * <li>{@link InvalidThingException}</li> * </ul> * * @param e * the client exception * @return the error body */ @ExceptionHandler({ InvalidTagException.class, InvalidThingException.class }) public ResponseEntity<MessageResponse> handleClientBadRequest(final Exception e) { if (LOG.isDebugEnabled()) { LOG.debug(e.getMessage(), e); } return utils.createMessageResponse(e.getMessage(), HttpStatus.BAD_REQUEST); }
From source file:edu.pitt.dbmi.ccd.anno.error.ErrorHandler.java
@ExceptionHandler(NotAMemberException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody// w ww . j a va 2 s . c om public ErrorMessage handleNotAMemberException(NotAMemberException ex, HttpServletRequest req) { LOGGER.info(ex.getMessage()); return new ErrorMessage(HttpStatus.BAD_REQUEST, ex.getMessage(), req); }
From source file:com.monitor.controller.MessageController.java
@ApiOperation(value = "create", notes = "create message") @RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public ResponseEntity<Message> create(Message messageRequest) { Message messageSaved = service.insert(messageRequest); if (messageSaved != null) { return new ResponseEntity<>(messageSaved, HttpStatus.OK); } else {/*from w ww. j a va 2 s.c om*/ return new ResponseEntity<>(messageSaved, HttpStatus.BAD_REQUEST); } }