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:alfio.controller.api.AttendeeApiController.java
@ExceptionHandler({ DataIntegrityViolationException.class, IllegalArgumentException.class }) public ResponseEntity<String> handleDataIntegrityException(Exception e) { log.warn("bad input detected", e); return new ResponseEntity<>("bad input parameters", HttpStatus.BAD_REQUEST); }
From source file:io.curly.gathering.item.ItemController.java
/** * Method that handle user's intent to add a new item to a list * @param body valid body for request/* w w w . ja va 2s .c o m*/ * @param listId list to be added to * @param user current user on context * @param bindingResult result of validation of body * @return 400 if result returns errors or 201 if ok */ @RequestMapping(value = "/add/artifact", method = { RequestMethod.PUT, RequestMethod.POST }) public Callable<HttpEntity<?>> addItem(@Valid @RequestBody AddableItemBody body, @PathVariable String listId, @GitHubAuthentication User user, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return () -> new ResponseEntity<Object>(new ModelErrors(bindingResult), HttpStatus.BAD_REQUEST); } else { return () -> { this.interaction.addItem(new AddableItem(body.getItem(), listId, ItemType.ARTIFACT), user); return new ResponseEntity<>(HttpStatus.CREATED); }; } }
From source file:com.agroservices.restcontrollers.CampesinoRest.java
@RequestMapping(value = "/{id}/productosEnVenta", method = RequestMethod.POST) public ResponseEntity<?> guardarProductoEnVenta(@PathVariable int id, @RequestBody ProductoEnVenta pv) { System.out.println("Post a campesinos productosEnVenta " + id); System.out.println(pv);/*from w w w.ja v a 2 s . c o m*/ try { cf.guardarProductoEnVentaParaCampesino(id, pv); return new ResponseEntity<>(HttpStatus.CREATED); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } }
From source file:de.steilerdev.myVerein.server.controller.user.MessageController.java
@RequestMapping(produces = "application/json", method = RequestMethod.GET, params = "id") public ResponseEntity<Message> getMessage(@RequestParam(value = "id") String messageId, @CurrentUser User currentUser) { logger.trace("[{}] Getting message with id {}", currentUser, messageId); Message message;/*from ww w . ja va2s .c o m*/ if (messageId.isEmpty()) { logger.warn("[{}] Required parameter id missing", currentUser); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } else if ((message = messageRepository.findOne(messageId)) == null) { logger.warn("[{}] Unable to find message with id {}", currentUser, messageId); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } else if (!message.getReceiver().containsKey(currentUser.getId())) { logger.warn("[{}] User is not allowed to read message {}, because he is not a receiver", currentUser, message); return new ResponseEntity<>(HttpStatus.FORBIDDEN); } else { logger.info("[{}] Delivering message {}", currentUser, message); return new ResponseEntity<>(message.getSendingObjectInternalSync(), HttpStatus.OK); } }
From source file:com.sms.server.controller.AdminController.java
@RequestMapping(value = "/user", method = RequestMethod.POST, headers = { "Content-type=application/json" }) @ResponseBody// w w w . j a v a 2 s. c om public ResponseEntity<String> createUser(@RequestBody User user) { // Check mandatory fields. if (user.getUsername() == null || user.getPassword() == null) { return new ResponseEntity<>("Missing required parameter.", HttpStatus.BAD_REQUEST); } // Check unique fields if (userDao.getUserByUsername(user.getUsername()) != null) { return new ResponseEntity<>("Username already exists.", HttpStatus.NOT_ACCEPTABLE); } // Add user to the database. if (!userDao.createUser(user)) { LogService.getInstance().addLogEntry(Level.ERROR, CLASS_NAME, "Error adding user '" + user.getUsername() + "' to database.", null); return new ResponseEntity<>("Error adding user to database.", HttpStatus.INTERNAL_SERVER_ERROR); } LogService.getInstance().addLogEntry(Level.INFO, CLASS_NAME, "User '" + user.getUsername() + "' created successfully.", null); return new ResponseEntity<>("User created successfully.", HttpStatus.CREATED); }
From source file:org.syncope.core.rest.data.VirtualSchemaDataBinder.java
public <T extends AbstractSchema> AbstractVirSchema create(final VirtualSchemaTO virtualSchemaTO, AbstractVirSchema virtualSchema, final Class<T> reference) { return populate(virtualSchema, virtualSchemaTO, reference, new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST)); }
From source file:sample.jersey.SampleJerseyApplicationTests.java
@Test public void validation() { ResponseEntity<String> entity = this.restTemplate.getForEntity("http://localhost:" + this.port + "/reverse", String.class); assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); }
From source file:com.expedia.seiso.web.controller.ExceptionHandlerAdvice.java
@ExceptionHandler(JsonMappingException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody/*from w w w . j a va 2 s.c om*/ public ErrorObject handleJsonMappingException(JsonMappingException e, WebRequest request) { return new ErrorObject(C.EC_INVALID_REQUEST_JSON_PAYLOAD, e.getMessage()); }
From source file:io.curly.gathering.list.GatheringController.java
@RequestMapping(value = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) public Callable<HttpEntity<?>> createList(@Valid @RequestBody ListBody body, @GitHubAuthentication User user, BindingResult bindingResult) {/*from w w w . j a v a 2 s. com*/ if (bindingResult.hasErrors()) { return () -> new ResponseEntity<>(new ModelErrors(bindingResult), HttpStatus.BAD_REQUEST); } else { return () -> { storage.save(new GatheringList(body.getName(), user.getId())); return new ResponseEntity<>(HttpStatus.CREATED); }; } }
From source file:org.bonitasoft.web.designer.controller.ResourceControllerAdvice.java
@ExceptionHandler(IllegalArgumentException.class) @ResponseStatus(value = HttpStatus.BAD_REQUEST) public ResponseEntity<ErrorMessage> handleIllegalArgumentException(IllegalArgumentException exception) { logger.error("Illegal Argument Exception", exception); return new ResponseEntity<>(new ErrorMessage(exception), HttpStatus.BAD_REQUEST); }