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.hp.autonomy.frontend.find.hod.web.HodGlobalExceptionHandler.java

@ExceptionHandler(HodErrorException.class)
@ResponseBody/*from ww  w .  j  ava  2  s.  co m*/
public ResponseEntity<HodErrorResponse> hodErrorHandler(final HodErrorException exception) {
    final HodErrorResponse hodErrorResponse = new HodErrorResponse("HOD Error", exception.getErrorCode());

    log.error("Unhandled HodErrorException with uuid {}", hodErrorResponse.getUuid());
    log.error("Stack trace", exception);

    return new ResponseEntity<>(hodErrorResponse,
            exception.isServerError() ? HttpStatus.INTERNAL_SERVER_ERROR : HttpStatus.BAD_REQUEST);
}

From source file:com.iggroup.oss.sample.web.controller.exception.ExceptionHandler.java

/**
 * Exception handler for DuplicateReferenceExceptions
 * /*from   w  w  w.ja va  2 s  .co  m*/
 * @param dre the exception being handled
 */
@AfterThrowing(pointcut = "execution (* com.iggroup.wt.referencerest.service.*.*(..))", throwing = "dre")
public void handleDuplicateKeyException(DuplicateReferenceException dre) {
    throw new SampleException(new DuplicateReferenceError(dre.getReference()), HttpStatus.BAD_REQUEST);
}

From source file:org.trustedanalytics.kafka.adminapi.api.ExceptionHandlerAdvice.java

@ExceptionHandler
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//ww  w  . jav a  2 s.c  o  m
public String handleBadRequest(HttpMessageConversionException ex) {
    LOG.error("Handling request malformed exception", ex);
    return "Request malformed";
}

From source file:reconf.server.services.component.ReadAllComponentsService.java

@RequestMapping(value = "/product/{prod}/component", method = RequestMethod.GET)
@Transactional(readOnly = true)//  w w  w .  ja va  2s .  c  o m
public ResponseEntity<AllComponentsResult> doIt(@PathVariable("prod") String productId,
        HttpServletRequest request, Authentication auth) {

    Product fromRequest = new Product(productId);

    List<String> errors = DomainValidator.checkForErrors(fromRequest);
    if (!errors.isEmpty()) {
        return new ResponseEntity<AllComponentsResult>(new AllComponentsResult(productId, errors),
                HttpStatus.BAD_REQUEST);
    }

    Product dbProduct = products.findOne(fromRequest.getName());

    if (dbProduct == null) {
        return new ResponseEntity<AllComponentsResult>(new AllComponentsResult(productId, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    List<ComponentResult> result = new ArrayList<>();
    for (Component component : components.findByKeyProductOrderByKeyNameAsc(dbProduct.getName())) {
        result.add(new ComponentResult(component, CrudServiceUtils.getBaseUrl(request)));
    }

    return new ResponseEntity<AllComponentsResult>(
            new AllComponentsResult(dbProduct, result, CrudServiceUtils.getBaseUrl(request)), HttpStatus.OK);
}

From source file:com.coffeebeans.services.controller.base.BaseController.java

@ResponseBody
@ExceptionHandler(ValidationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
ErrorResponse handleException(ValidationException e) {
    return new ErrorResponse(HttpStatus.BAD_REQUEST.toString(), e.getMessage(), "Bad Request",
            e.getValidationErrors());//  ww w .  j  a v  a  2  s . c  o  m
}

From source file:com.ar.dev.tierra.api.controller.FacturaProductoController.java

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<FacturaProducto> list = facadeService.getFacturaProductoDAO().getAll();
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {// w w  w  . j a v a  2 s.  co  m
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:reconf.server.services.product.ReadProductService.java

@RequestMapping(value = "/product/{prod}", method = RequestMethod.GET)
@Transactional(readOnly = true)/*from   w w  w.  j  a  va  2s  . co  m*/
public ResponseEntity<ProductResult> doIt(@PathVariable("prod") String product, HttpServletRequest request,
        Authentication auth) {

    Product reqProduct = new Product(product, null);

    List<String> errors = DomainValidator.checkForErrors(reqProduct);
    if (!errors.isEmpty()) {
        return new ResponseEntity<ProductResult>(new ProductResult(reqProduct, errors), HttpStatus.BAD_REQUEST);
    }

    Product dbProduct = products.findOne(reqProduct.getName());
    if (dbProduct == null) {
        return new ResponseEntity<ProductResult>(new ProductResult(reqProduct, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    if (ApplicationSecurity.isRoot(auth)) {
        for (UserProduct userProduct : userProducts.findByKeyProduct(reqProduct.getName())) {
            dbProduct.addUser(userProduct.getKey().getUsername());
        }
    }

    return new ResponseEntity<ProductResult>(new ProductResult(dbProduct, CrudServiceUtils.getBaseUrl(request)),
            HttpStatus.OK);
}

From source file:com.chevres.rss.restapi.controller.LogoutController.java

@CrossOrigin
@RequestMapping(path = "/logout", method = RequestMethod.POST)
@ResponseBody/*from  w ww .jav a2  s  .  c  o  m*/
public ResponseEntity<String> logout(@RequestHeader(value = "User-token") String userToken) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");

    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);

    UserAuth userAuth = userAuthDAO.findByToken(userToken);
    if (userAuth == null) {
        context.close();
        return new ResponseEntity(new ErrorMessageResponse("invalid_token"), HttpStatus.BAD_REQUEST);
    }

    userAuthDAO.delete(userAuth);

    context.close();

    return new ResponseEntity(new SuccessMessageResponse("success"), HttpStatus.OK);
}

From source file:es.fdi.reservas.reserva.web.ExceptionHandlerController.java

@ExceptionHandler(UserPasswordException.class)
@ResponseBody//from   w  ww.j  a v  a 2  s  . c o  m
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResult userPasswordException(HttpServletRequest request, HttpServletResponse response, Exception e)
        throws IOException {

    return new ErrorResult(HttpStatus.BAD_REQUEST.value(), e.getMessage());
}

From source file:org.obp.web.DefaultsController.java

@RequestMapping("/secure/defaults/update")
public ResponseEntity updateDefaultValue(@RequestParam String name, @RequestParam String value) {
    try {/*from w  w w. j av a 2s  .c o  m*/
        defaultDataInstrument.updateReadout(name, new Double(value));
    } catch (Exception e) {
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity(HttpStatus.OK);
}