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:technology.tikal.gae.service.template.RestControllerTemplate.java

@ExceptionHandler(NotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public BasicErrorMessage handleException(NotValidException ex, HttpServletRequest request,
        HttpServletResponse response) {//from www  .ja v a 2  s  .c o  m
    response.setHeader("Content-Type", "application/json;charset=UTF-8");
    BasicErrorMessage result = new BasicErrorMessage();
    BindingResult detail = ex.getDetails();
    String[] msg = new String[detail.getAllErrors().size()];
    String[][] code = new String[detail.getAllErrors().size()][];
    String[][] args = new String[detail.getAllErrors().size()][];
    int index = 0;
    Locale locale = LocaleContextHolder.getLocale();
    for (ObjectError x : detail.getAllErrors()) {
        Object[] tmpArgs = resolveArgumentMessage(x.getCodes(), x.getArguments());
        msg[index] = getValidationMessage(x.getDefaultMessage(), x.getCodes(), tmpArgs, locale);
        code[index] = x.getCodes();
        String[] tmp = new String[tmpArgs.length];
        args[index] = tmp;
        int j = 0;
        for (Object y : tmpArgs) {
            args[index][j] = y.toString();
            j = j + 1;
        }
        index = index + 1;
    }
    result.setType(ex.getClass().getSimpleName());
    result.setMessage(msg);
    result.setCode(code);
    result.setArguments(args);
    return result;
}

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

public static ResponseSpecification assertResponse(HttpStatus status, Class<?> exClass) {
    Matcher<Integer> statusMatcher = (status == null) ? is(greaterThanOrEqualTo(HttpStatus.BAD_REQUEST.value()))
            : is(status.value());/*from ww w.  jav a  2 s. c om*/
    return new ResponseSpecBuilder().expectStatusCode(statusMatcher).expectBody("status", statusMatcher)
            .expectBody("exception", is(exClass.getCanonicalName()))
            .expectBody("timestamp", new ISO8601UTCTimestampMatcher()).build();
}

From source file:org.esbtools.gateway.resync.controller.ResyncGateway.java

@ExceptionHandler(InvalidSystemException.class)
private ResponseEntity<ResyncResponse> invalidSystemExceptionHandler(InvalidSystemException e) {
    ResyncResponse resyncResponse = new ResyncResponse(ResyncResponse.Status.Error, e.getMessage());
    return new ResponseEntity<>(resyncResponse, HttpStatus.BAD_REQUEST);
}

From source file:org.mifos.module.sms.controller.MifosSmsController.java

@RequestMapping(value = "/sms/configuration", method = RequestMethod.POST, consumes = {
        "application/json" }, produces = { "application/json" })
public ResponseEntity<String> createSMSBridgeConfig(@RequestBody final SMSBridgeConfig smsBridgeConfig) {
    if (this.smsBridgeService.findSmsBridgeConfigByTenantId(smsBridgeConfig.getTenantId()) != null) {
        return new ResponseEntity<>("Tenant " + smsBridgeConfig.getTenantId() + " already exists!",
                HttpStatus.BAD_REQUEST);
    }/*w w w . ja  v  a 2s  .  c om*/
    final String newApiKey = this.securityService.generateApiKey(smsBridgeConfig.getTenantId(),
            smsBridgeConfig.getMifosToken(), smsBridgeConfig.getSmsProviderAccountId(),
            smsBridgeConfig.getSmsProviderToken());
    smsBridgeConfig.setApiKey(newApiKey);
    this.smsBridgeService.createSmsBridgeConfig(smsBridgeConfig);

    return new ResponseEntity<>(newApiKey, HttpStatus.CREATED);
}

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

@Test
public void unsupported_request_methods_are_detected() {
    givenWithContent().body(new Facility()).when().put(UrlSchema.FACILITIES).then()
            .spec(assertResponse(HttpStatus.BAD_REQUEST, HttpRequestMethodNotSupportedException.class))
            .body("message", is("Request method 'PUT' not supported"));
}

From source file:com.xyxy.platform.examples.showcase.demos.hystrix.web.HystrixExceptionHandler.java

/**
 * ?Hystrix ClientException(404)./*w  w  w . j a v  a 2 s. com*/
 * ClientException?, ?
 */
@ExceptionHandler(value = { HystrixBadRequestException.class })
public final ResponseEntity<?> handleException(HystrixBadRequestException e, WebRequest request) {
    String message = Exceptions.getErrorMessageWithNestedException(e);
    logger.error(message, e);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(MediaTypes.TEXT_PLAIN_UTF_8));
    return handleExceptionInternal(e, message, headers, HttpStatus.BAD_REQUEST, request);
}

From source file:reconf.server.services.property.DeletePropertyService.java

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}/rule/{rule}", method = RequestMethod.DELETE)
@Transactional//  ww w . java  2s .  co m
public ResponseEntity<PropertyResult> resticted(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property,
        @PathVariable("rule") String rule) {

    PropertyKey key = new PropertyKey(product, component, property, rule);
    Property fromRequest = new Property(key, null);

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

    if (!properties.exists(key)) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(fromRequest, Property.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    properties.delete(key);
    return new ResponseEntity<PropertyResult>(HttpStatus.OK);
}

From source file:zarg.bank.rest.web.BankRestController.java

@ExceptionHandler(ExecutionException.class)
public ResponseEntity<String> handleIOException(final ExecutionException ex) {
    Throwable cause = ex;/*from   ww  w .  ja  v a2  s  . co  m*/
    while (cause.getCause() != null) {
        cause = cause.getCause();
    }
    return new ResponseEntity<>("{\"error\": \"" + cause.getMessage() + "\"}", HttpStatus.BAD_REQUEST);
}

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

/**
 * Handler for illegal argument exceptions. Spring will convert this to an
 * HTTP 400 error.//ww  w.j av  a2s .  c om
 */
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST, reason = "validation error")
public void veryBadRequest() {
}