Example usage for org.springframework.http HttpStatus BAD_REQUEST

List of usage examples for org.springframework.http HttpStatus BAD_REQUEST

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus BAD_REQUEST.

Prototype

HttpStatus BAD_REQUEST

To view the source code for org.springframework.http HttpStatus BAD_REQUEST.

Click Source Link

Document

400 Bad Request .

Usage

From source file:com.expedia.seiso.web.controller.ExceptionHandlerAdvice.java

@ExceptionHandler(BindException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public @ResponseBody ValidationErrorMap handleBindException(BindException bindException) {

    ValidationErrorMap validationErrorMap = ValidationErrorMapFactory.buildFrom(bindException);

    return validationErrorMap;
}

From source file:plbtw.klmpk.barang.hilang.controller.RoleController.java

@RequestMapping(method = RequestMethod.PUT, produces = "application/json")
public CustomResponseMessage updateRole(@RequestBody RoleRequest roleRequest) {
    try {/*from w ww.  j a  v a2  s. c  om*/
        Role role = roleService.getRole(roleRequest.getId());
        System.out.println(role.toString());
        role.setRole(roleRequest.getRole());
        roleService.updateRole(role);
        return new CustomResponseMessage(HttpStatus.CREATED, "Update Role Succesfull");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }
}

From source file:org.ow2.proactive.procci.rest.MixinRest.java

@RequestMapping(value = "{mixinTitle}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<MixinRendering> getMixin(@PathVariable("mixinTitle") String mixinTitle) {
    logger.debug("Getting Mixin " + mixinTitle);

    try {/*  ww w .j a  va  2  s .  c o  m*/
        return new ResponseEntity(mixinService.getMixinByTitle(mixinTitle).getRendering(), HttpStatus.OK);
    } catch (ClientException ex) {
        return new ResponseEntity(ex.getJsonError(), HttpStatus.BAD_REQUEST);
    } catch (ServerException exception) {
        return new ResponseEntity(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}

From source file:br.eti.danielcamargo.backend.common.rest.handlers.GlobalExceptionHandler.java

@ExceptionHandler
public ResponseEntity<List<Mensagem>> handleException(DataIntegrityViolationException ex) {

    String constraint = null;/* www.ja v  a2s.  c om*/
    Mensagem mensagem = null;

    String msg = ex.getMessage();
    Pattern p = Pattern.compile("\\[(\\w+_ukey)\\]");
    Matcher m = p.matcher(msg);

    if (m.find()) {
        constraint = m.group(1);
        mensagem = MessageUtils.criarMensagemViolacaoUnicidade("common", constraint);
    }

    p = Pattern.compile("\\[(\\w+_pkey)\\]");
    m = p.matcher(msg);

    if (m.find()) {
        constraint = m.group(1);
        mensagem = MessageUtils.criarMensagemViolacaoChavePrimaria("common", constraint);
    }

    p = Pattern.compile("\\[(\\w+_fkey)\\]");
    m = p.matcher(msg);

    if (m.find()) {
        constraint = m.group(1);
        mensagem = MessageUtils.criarMensagemViolacaoChaveEstrangeira("common", constraint);
    }

    List<Mensagem> list = new ArrayList<>();
    list.add(mensagem);

    ResponseEntity<List<Mensagem>> responseEntity = new ResponseEntity<>(list, HttpStatus.BAD_REQUEST);
    return responseEntity;

}

From source file:com.intel.databackend.handlers.ErrorHandler.java

@ExceptionHandler(BindException.class)
public ResponseEntity handleError(BindException ex) {
    Map<String, String> errors = new HashMap<>();
    for (FieldError error : ex.getFieldErrors()) {
        errors.put(error.getField(), error.getDefaultMessage());
    }/*from  w w  w.  j a v a 2 s  .c o m*/
    logger.error("Validation error: ", errors);
    return new ResponseEntity<Map<String, String>>(errors, HttpStatus.BAD_REQUEST);
}

From source file:org.syncope.core.rest.data.DerivedSchemaDataBinder.java

public <T extends AbstractSchema> AbstractDerSchema create(final DerivedSchemaTO derivedSchemaTO,
        final AbstractDerSchema derivedSchema) {

    return populate(derivedSchema, derivedSchemaTO,
            new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST));
}

From source file:com.envision.envservice.rest.CourseResource.java

@POST
@Path("/feedback/{courseId}")
@Produces(MediaType.APPLICATION_JSON)// w w w  .  j  av a 2 s.  com
public Response feedback(@PathParam("courseId") int courseId, CourseFeedbackBo feedback)
        throws ServiceException {
    HttpStatus status = HttpStatus.ACCEPTED;
    String response = StringUtils.EMPTY;

    if (checkParam(feedback)) {
        courseService.feedback(courseId, feedback);
    } else {
        status = HttpStatus.BAD_REQUEST;
        response = FailResult.toJson(Code.PARAM_ERROR, "??star");
    }

    return Response.status(status.value()).entity(response).build();
}

From source file:com.netflix.scheduledactions.web.controllers.ValidationController.java

@ExceptionHandler(InvalidCronExpressionException.class)
void handleInvalidCronExpression(HttpServletResponse response, InvalidCronExpressionException e)
        throws IOException {
    response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
}

From source file:com.ns.retailmgr.connector.gmaps.GMapConnectorTest.java

@Test(expected = RuntimeException.class)
public void test_getLngLatByAddress_Failure() {
    when(restTemplate.getForObject(anyString(), eq(GeoCodeLocInfo.class)))
            .thenThrow(new HttpClientErrorException(HttpStatus.BAD_REQUEST));
    gmapConnector.getLngLatByAddress("TestShop");
}

From source file:net.ljcomputing.core.controler.GlobalExceptionController.java

/**
 * Handle all null pointer exceptions./*w  ww . j  ava 2  s.c om*/
 *
 * @param req the req
 * @param exception the exception
 * @return the error info
 */
@Order(Ordered.HIGHEST_PRECEDENCE)
@ExceptionHandler(NullPointerException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public @ResponseBody ErrorInfo handleAllNullPointerExceptions(HttpServletRequest req, Exception exception) {
    logger.error("The data sent for processing had errors {}:", req.getRequestURL().toString(), exception);

    return new ErrorInfo(getCurrentTimestamp(), HttpStatus.BAD_REQUEST, req.getRequestURL().toString(),
            new Exception("An invalid value was sent or requested."));
}