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:org.trustedanalytics.utils.errorhandling.ErrorLoggerTest.java

@Test
public void logAndSendErrorResponseIsUsingGivenLoggerAndResponse() throws Exception {
    Logger logger = mock(Logger.class);
    HttpServletResponse response = mock(HttpServletResponse.class);

    Exception ex1 = new Exception("Some ex");
    ArgumentCaptor<String> capturedMessage = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Throwable> capturedEx = ArgumentCaptor.forClass(Throwable.class);
    ArgumentCaptor<Integer> capturedStatus = ArgumentCaptor.forClass(Integer.class);
    ArgumentCaptor<String> capturedReason = ArgumentCaptor.forClass(String.class);

    ErrorLogger.logAndSendErrorResponse(logger, response, HttpStatus.BAD_REQUEST, ex1);

    verify(logger, times(1)).error(capturedMessage.capture(), capturedEx.capture());
    Assert.assertTrue(capturedMessage.getValue().contains(HttpStatus.BAD_REQUEST.getReasonPhrase()));
    Assert.assertEquals("Some ex", capturedEx.getValue().getMessage());

    verify(response, times(1)).sendError(capturedStatus.capture(), capturedReason.capture());
    Assert.assertEquals(HttpStatus.BAD_REQUEST.value(), capturedStatus.getValue().intValue());
    Assert.assertTrue(capturedReason.getValue().contains(HttpStatus.BAD_REQUEST.getReasonPhrase()));
}

From source file:edu.kit.scc.RestServiceController.java

/**
 * SCIM create user endpoint.// w  w w.j  a  v  a2s.  com
 * 
 * @param authorizationHeader basic or bearer HTTP authorization
 * @param scimUser (optional) the SCIM user to create
 * @return the created {@link ScimUser}
 */
@RequestMapping(path = "/Users", method = RequestMethod.POST, consumes = "application/scim+json", produces = "application/scim+json")
public ResponseEntity<?> createUser(@RequestHeader("Authorization") String authorizationHeader,
        @RequestBody(required = false) ScimUser scimUser) {

    ScimUser user = userGenerator.createUser(scimUser);

    if (user != null) {
        return new ResponseEntity<ScimUser>(user, HttpStatus.CREATED);
    }
    return new ResponseEntity<ScimUser>(scimUser, HttpStatus.BAD_REQUEST);
}

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

@RequestMapping(value = "/list/paged", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAllPaged(
        @RequestParam(value = "page", required = false, defaultValue = "") Integer page,
        @RequestParam(value = "size", required = false, defaultValue = "") Integer size) {
    Page<FacturaProducto> paged = facadeService.getFacturaProductoService().getAllPaged(page, size);
    if (paged.getSize() != 0) {
        return new ResponseEntity<>(paged, HttpStatus.OK);
    } else {//from w w w  .  j  a va2  s. c o m
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

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

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public CustomResponseMessage addKategoriBarang(@RequestBody KategoriBarangRequest kategoriBarangRequest) {
    try {/*w  ww.j av a 2s.  c  o  m*/
        KategoriBarang kategoriBarang = new KategoriBarang();
        kategoriBarang.setJenis(kategoriBarangRequest.getJenis());
        kategoriBarangService.addKategoriBarang(kategoriBarang);
        return new CustomResponseMessage(HttpStatus.CREATED, "Kategori Barang berhasil di tambahkan");
    } catch (Exception ex) {
        return new CustomResponseMessage(HttpStatus.BAD_REQUEST, ex.toString());
    }

}

From source file:com.mycompany.projetsportmanager.spring.rest.exceptions.SportManagerResponseEntityExceptionHandler.java

@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*from  w  ww  .j  av a  2s . co  m*/
public ErrorListResource processValidationError(ConstraintViolationException ex) {
    List<ValidationErrorResource> validationErrorResources = errorListsMapper.mapEntitySetToBeanList(
            dozerBeanMapper, ex.getConstraintViolations(), ValidationErrorResource.class);
    return new ErrorListResource(validationErrorResources, HttpStatus.BAD_REQUEST);
}

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

/**
 * Handle all exceptions.//w  ww .  j  av  a  2  s .co m
 *
 * @param req
 *            the req
 * @param exception
 *            the exception
 * @return the error info
 */
@Order(Ordered.LOWEST_PRECEDENCE)
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public @ResponseBody ErrorInfo handleAllExceptions(HttpServletRequest req, Exception exception) {
    logger.error("An error occured during the processing of {}:", req.getRequestURL().toString(), exception);

    return new ErrorInfo(getCurrentTimestamp(), HttpStatus.BAD_REQUEST, req.getRequestURL().toString(),
            exception);
}

From source file:au.id.hazelwood.sos.web.controller.framework.GlobalExceptionHandlerUnitTest.java

@Test
public void testHandleIllegalArgument() throws Exception {
    WebRequest webRequest = mock(WebRequest.class);

    ResponseEntity<Object> responseEntity = handler
            .handleIllegalArgument(new IllegalArgumentException("Illegal argument"), webRequest);

    assertResponseEntity(responseEntity, HttpStatus.BAD_REQUEST, "Illegal argument");
    verifyZeroInteractions(webRequest);/*from  w  w  w.j  a  v  a 2  s  .  c  o m*/
}

From source file:com.monitor.controller.MessageController.java

@ApiOperation(value = "update", notes = "update message")
@RequestMapping(method = { RequestMethod.PUT,
        RequestMethod.PATCH }, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<Message> update(Message messageRequest) {

    Message messageSaved = service.insert(messageRequest);

    if (messageSaved != null) {
        return new ResponseEntity<>(messageSaved, HttpStatus.OK);
    } else {/*from   ww w .  j a v a 2  s  .  co  m*/
        return new ResponseEntity<>(messageSaved, HttpStatus.BAD_REQUEST);
    }

}

From source file:fi.hsl.parkandride.itest.GenericReportITest.java

@Test
public void report_incorrectType_resultsInBadRequest() {
    given().contentType(ContentType.JSON).accept(MEDIA_TYPE_EXCEL)
            .header(authorization(devHelper.login(adminUser.username).token)).body(baseParams()).when()
            .post(UrlSchema.REPORT, "foobar").then().assertThat().statusCode(HttpStatus.BAD_REQUEST.value());
}

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

@CrossOrigin
@RequestMapping(path = "/feeds/articles/{pageNumber}", method = RequestMethod.GET)
@ResponseBody/*  ww w .j  av a2  s  .  c  om*/
public ResponseEntity<String> getArticles(@RequestHeader(value = "User-token") String userToken,
        @PathVariable int pageNumber) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
    UserAuthDAO userAuthDAO = context.getBean(UserAuthDAO.class);
    FeedDAO feedDAO = context.getBean(FeedDAO.class);
    ArticleDAO articleDAO = context.getBean(ArticleDAO.class);

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

    List<Feed> feeds = feedDAO.findAll(userAuth);
    List<Article> articles = articleDAO.findArticlesByPageId(feeds, pageNumber);

    List<SuccessGetArticleWithIdResponse> finalList = new ArrayList<>();
    for (Article article : articles) {
        finalList.add(new SuccessGetArticleWithIdResponse(article.getId(), article.getFeed().getId(),
                article.getStatus().getLabel(), article.getLink(), article.getTitle(),
                article.getPreviewContent(), article.getFullContent()));
    }

    context.close();
    return new ResponseEntity(new SuccessGetFeedArticlesResponse(finalList), HttpStatus.OK);
}