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:com.alexshabanov.springrestapi.XmlDrivenConfigTest.java
@Test public void shouldThrowHttpClientErrorExceptionWithBadRequest() { doThrow(IllegalArgumentException.class).when(profileController).deleteProfile(id); try {// ww w . ja v a 2 s . c o m restClient.delete(path(CONCRETE_PROFILE_RESOURCE), id); } catch (HttpClientErrorException e) { assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode()); } }
From source file:de.steilerdev.myVerein.server.controller.user.UserController.java
@RequestMapping(method = RequestMethod.GET, produces = "application/json") public ResponseEntity<User> getUser(@RequestParam(value = "id") String userID, @CurrentUser User currentUser) { logger.trace("[{}] Loading user with ID {}", currentUser, userID); User searchedUser;/*from w w w .j a va2 s .c o m*/ if (userID.isEmpty()) { logger.warn("[" + currentUser + "] The user ID is empty"); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } else if ((searchedUser = userRepository.findById(userID)) == null) { logger.warn("[" + currentUser + "] Unable to find user with the stated ID " + userID); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } else { logger.info("[" + currentUser + "] Returning user with ID " + userID); return new ResponseEntity<>(searchedUser.getSendingObjectInternalSync(), HttpStatus.OK); } }
From source file:se.sawano.scala.examples.scalaspringmvc.ValidationTestIT.java
@Test public void javaPostWithMissingName() { try {/* www .j a v a2 s .c o m*/ JavaIndata indata = new JavaIndata(null, 1); restTemplate.postForObject(baseUrl + "java/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.jbr.taskmgr.web.controller.GlobalExceptionHandler.java
/** * Converts one of several client-based exception into an HTTP 400 response * with an error body. The mapped exceptions are as follows: * <ul>/*from w ww . ja v a 2 s.com*/ * <li>{@link HttpMessageNotReadableException}</li> * <li>{@link ServletRequestBindingException}</li> * <li>{@link TypeMismatchException}</li> * </ul> * * @param e * the client exception * @return the error body */ @ExceptionHandler({ HttpMessageNotReadableException.class, ServletRequestBindingException.class, TypeMismatchException.class }) @RestEndpoint @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody public ResponseEntity<GenericMessage> handleClientBadRequest(final Exception e) { return createResponseEntity(e, HttpStatus.BAD_REQUEST); }
From source file:edu.pitt.dbmi.ccd.anno.error.ErrorHandler.java
@ExceptionHandler(ConstraintViolationException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) @ResponseBody// w w w.java 2 s . com public ErrorMessage handleConstraintViolationException(ConstraintViolationException ex, HttpServletRequest req) { LOGGER.info(ex.getMessage()); StringBuilder message = new StringBuilder(""); ex.getConstraintViolations().stream().forEach(e -> { message.append("Property: " + e.getPropertyPath()); message.append(" Constraint: " + e.getMessageTemplate() + " "); }); return new ErrorMessage(HttpStatus.BAD_REQUEST, message.toString(), req); }
From source file:org.swarmcom.jsynapse.controller.client.api.v1.AuthenticationRestApiTest.java
@Test public void testUnknownSchema() throws Exception { postAndCheckStatus("/_matrix/client/api/v1/login", postUnknownSchema, HttpStatus.BAD_REQUEST); postAndCheckStatus("/_matrix/client/api/v1/register", postUnknownSchema, HttpStatus.BAD_REQUEST); }
From source file:org.syncope.core.rest.data.SchemaDataBinder.java
private <T extends AbstractDerSchema> void populate(final AbstractSchema schema, final SchemaTO schemaTO) throws SyncopeClientCompositeErrorException { if (!jexlUtil.isExpressionValid(schemaTO.getMandatoryCondition())) { SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException( HttpStatus.BAD_REQUEST); SyncopeClientException invalidMandatoryCondition = new SyncopeClientException( SyncopeClientExceptionType.InvalidValues); invalidMandatoryCondition.addElement(schemaTO.getMandatoryCondition()); scce.addException(invalidMandatoryCondition); throw scce; }/*from w w w .ja va 2s .co m*/ BeanUtils.copyProperties(schemaTO, schema, IGNORE_SCHEMA_PROPERTIES); }
From source file:com.auditbucket.helper.GlobalControllerExceptionHandler.java
@ExceptionHandler(JsonParseException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) public ModelAndView handleJsonError(final JsonParseException ex) { return new JsonError(ex.getMessage()).asModelAndView(); }
From source file:plbtw.klmpk.barang.hilang.controller.RoleController.java
@RequestMapping(method = RequestMethod.POST, produces = "application/json") public CustomResponseMessage addRole(@RequestBody RoleRequest roleRequest) { try {/*from ww w. j av a2 s .c o m*/ Role role = new Role(); role.setRole(roleRequest.getRole()); roleService.addRole(role); return new CustomResponseMessage(HttpStatus.CREATED, "Role Has Been Created"); } catch (Exception ex) { return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString()); } }
From source file:br.com.mv.modulo.web.ExceptionController.java
@ResponseStatus(HttpStatus.BAD_REQUEST) @ExceptionHandler(GenericException.class) @ResponseBody// w ww. j a v a2 s . c om ExceptionInfo handleBadRequest(HttpServletRequest req, GenericException ex) { return new ExceptionInfo(req.getRequestURL(), ex); }