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.ar.dev.tierra.api.controller.EntidadBancariaController.java

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

From source file:com.github.iexel.fontus.web.mvc.GlobalControllerAdviceMvc.java

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(Throwable.class)
public String handle(Throwable ex) {

    logger.error(null, ex);/*from   w  w  w. ja  v a 2 s.  c om*/
    AjaxError ajaxError = new AjaxError();
    ajaxError.setGlobalErrorCode("error_unexpected");
    return "forward:/error/error_unexpected";
}

From source file:de.zib.gndms.GORFX.service.TaskFlowServiceAux.java

public static <T extends Order> HttpStatus validateOrder(TaskFlowFactory<T, ?> factory,
        DelegatingOrder<T> delegate) {
    final AbstractQuoteCalculator<T> qc;
    try {/*  ww  w  .j  a v a2  s  .c  om*/
        qc = factory.getQuoteCalculator();
    } catch (MandatoryOptionMissingException e) {
        return HttpStatus.BAD_REQUEST;
    }
    qc.setOrder(delegate);

    try {
        if (qc.validate())
            return HttpStatus.OK;
    } catch (Exception e) {
        return HttpStatus.BAD_REQUEST;
    }

    return HttpStatus.BAD_REQUEST;
}

From source file:com.sms.server.controller.UserController.java

@RequestMapping(value = "/{username}", method = RequestMethod.PUT, headers = {
        "Content-type=application/json" })
@ResponseBody/* w  w w .  j  a  va2  s .c  o m*/
public ResponseEntity<String> updateUser(@RequestBody User update, @PathVariable("username") String username) {
    User user = userDao.getUserByUsername(username);

    if (user == null) {
        return new ResponseEntity<String>("Username does not exist.", HttpStatus.BAD_REQUEST);
    }

    if (username.equals("admin")) {
        return new ResponseEntity<String>("You are not authenticated to perform this operation.",
                HttpStatus.FORBIDDEN);
    }

    // Update user details
    if (update.getUsername() != null) {
        // Check username is available
        if (userDao.getUserByUsername(user.getUsername()) != null) {
            return new ResponseEntity<String>("Username already exists.", HttpStatus.NOT_ACCEPTABLE);
        } else {
            user.setUsername(update.getUsername());
        }
    }

    if (update.getPassword() != null) {
        user.setPassword(update.getPassword());
    }

    if (update.getEnabled() != null) {
        user.setEnabled(update.getEnabled());
    }

    // Update database
    if (!userDao.updateUser(user, username)) {
        LogService.getInstance().addLogEntry(LogService.Level.ERROR, CLASS_NAME,
                "Error updating user '" + user.getUsername() + "'.", null);
        return new ResponseEntity<String>("Error updating user details.", HttpStatus.INTERNAL_SERVER_ERROR);
    }

    LogService.getInstance().addLogEntry(LogService.Level.INFO, CLASS_NAME,
            "User '" + user.getUsername() + "' updated successfully.", null);
    return new ResponseEntity<String>("User details updated successfully.", HttpStatus.ACCEPTED);
}

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

@Test
public void validation_errors_are_detailed_as_violations() {
    devHelper.createOrUpdateUser(new NewUser(1l, "admin", Role.ADMIN, "admin"));
    givenWithContent(devHelper.login("admin").token).body(new Facility()).when().post(UrlSchema.FACILITIES)
            .then().spec(assertResponse(HttpStatus.BAD_REQUEST, ValidationException.class))
            .contentType(ContentType.JSON).body("message", startsWith("Invalid data. Violations in"))
            .body("violations", is(notNullValue()));
}

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

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<Proveedor> proveedor = facadeService.getProveedorDAO().getAll();
    if (!proveedor.isEmpty()) {
        return new ResponseEntity<>(proveedor, HttpStatus.OK);
    } else {/*w  ww.  java  2 s . c o m*/
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

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

@RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getAll() {
    List<TipoProducto> tipoProducto = facadeService.getTipoProductoDAO().getAll();
    if (!tipoProducto.isEmpty()) {
        return new ResponseEntity<>(tipoProducto, HttpStatus.OK);
    } else {/*from   w  ww.ja  v  a  2  s. com*/
        return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
    }
}

From source file:io.syndesis.runtime.ConnectionsITCase.java

@Test
public void emptyNamesShouldNotBeAllowed() {
    final Connection connection = new Connection.Builder().name(" ").build();

    final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection,
            RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);

    assertThat(got.getBody()).containsExactly(
            new Violation.Builder().property("name").error("NotNull").message("Value is required").build());
}

From source file:org.centralperf.controller.BaseController.java

/**
 * Return an error 400 Bad Request when validation fails
 * @param e   Validation Exception thrown 
 * @return A message as JSON/*from  w  w  w.  j a  va  2  s  .co  m*/
 * @see ControllerValidationException
 */
@ExceptionHandler(ControllerValidationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public @ResponseBody String handleValidationException(ControllerValidationException e) {
    return e.getMessageAsJSON();
}

From source file:org.nebula.service.exception.NebulaExceptionHandler.java

@ExceptionHandler({ IllegalArgumentException.class, GeneralSecurityException.class })
protected ResponseEntity<Object> badRequest(IllegalArgumentException ex, WebRequest request) {
    String bodyOfResponse = ex.getMessage();

    ResponseEntity<Object> response = handleExceptionInternal(null, bodyOfResponse, new HttpHeaders(),
            HttpStatus.BAD_REQUEST, request);

    logger.error("Exception:" + response.toString(), ex);

    return response;
}