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.github.lynxdb.server.api.http.handlers.EpPut.java

@RequestMapping(path = "", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity put(Authentication _authentication, @RequestBody @Valid List<Metric> _request,
        BindingResult _bindingResult) {/*  w  w  w .ja va2 s.c  om*/

    User user = (User) _authentication.getPrincipal();

    if (_bindingResult.hasErrors()) {
        ArrayList<String> errors = new ArrayList();
        _bindingResult.getFieldErrors().forEach((FieldError t) -> {
            errors.add(t.getField() + ": " + t.getDefaultMessage());
        });
        return new ErrorResponse(mapper, HttpStatus.BAD_REQUEST, errors.toString(), null).response();
    }

    List<com.github.lynxdb.server.core.Metric> metricList = new ArrayList<>();
    _request.stream().forEach((m) -> {
        metricList.add(new com.github.lynxdb.server.core.Metric(m));
    });

    try {
        entries.insertBulk(vhosts.byId(user.getVhost()), metricList);
    } catch (Exception ex) {
        throw ex;
    }
    return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

From source file:com.wisemapping.rest.BaseController.java

@ExceptionHandler(JsonHttpMessageNotReadableException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public RestErrors handleJSONErrors(@NotNull JsonHttpMessageNotReadableException ex) {
    return new RestErrors("Communication error", Severity.SEVERE);
}

From source file:io.kahu.hawaii.util.exception.HawaiiExceptionTest.java

@Test
public void testGetStatus() throws Exception {

    ServerException e = new ServerException(TestServerError.S1);
    Assert.assertTrue(HttpStatus.INTERNAL_SERVER_ERROR.equals(e.getStatus()));

    AuthenticationException auth = new AuthenticationException();
    Assert.assertTrue(HttpStatus.FORBIDDEN.equals(auth.getStatus()));

    AuthorisationException autho = new AuthorisationException();
    Assert.assertTrue(HttpStatus.UNAUTHORIZED.equals(autho.getStatus()));

    ValidationException v = new ValidationException();
    Assert.assertTrue(HttpStatus.BAD_REQUEST.equals(v.getStatus()));
}

From source file:eu.freme.eservices.eentity.api.EEntityService.java

public String callDBpediaSpotlight(String text, String confidenceParam, String languageParam, String prefix)
        throws ExternalServiceFailedException, BadRequestException {

    try {//from w ww .  j a  v  a 2s.  com

        if (prefix.equals("http://freme-project.eu/")) {
            prefix = "http://freme-project.eu/#";
        }

        // if confidence param is not set, the default value is 0.3
        if (confidenceParam == null) {
            confidenceParam = "0.3";
        }

        HttpResponse<String> response = Unirest
                .post(dbpediaSpotlightURL + "?f=text&t=direct&confidence=" + confidenceParam + "&prefix="
                        + URLEncoder.encode(prefix, "UTF-8"))
                .header("Content-Type", "application/x-www-form-urlencoded")
                .body("i=" + URLEncoder.encode(text, "UTF-8")).asString();

        if (response.getStatus() != HttpStatus.OK.value()) {
            if (response.getStatus() == HttpStatus.BAD_REQUEST.value()) {
                throw new BadRequestException(response.getBody());
            } else {
                throw new ExternalServiceFailedException(response.getBody());
            }
        }
        String nif = response.getBody();
        //            System.out.println(nif);
        return nif;
    } catch (UnirestException e) {
        throw new ExternalServiceFailedException(e.getMessage());
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(EEntityService.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:ch.wisv.areafiftylan.exception.GlobalControllerExceptionHandler.java

@ExceptionHandler(InvalidTicketException.class)
public ResponseEntity<?> handleInvalidTicketException(InvalidTicketException ex) {
    return createResponseEntity(HttpStatus.BAD_REQUEST, ex.getMessage());
}

From source file:net.jkratz.igdb.controller.advice.ErrorController.java

@RequestMapping(produces = "application/json")
@ExceptionHandler(ConstraintViolationException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public @ResponseBody Map<String, Object> handleValidationException(ConstraintViolationException ex)
        throws IOException {
    logger.warn(ex.getMessage());//from   ww w .  j a v a2s  .c  o  m
    Map<String, Object> map = Maps.newHashMap();
    map.put("error", "Validation Failure");
    map.put("violations", convertConstraintViolation(ex.getConstraintViolations()));
    return map;
}

From source file:at.ac.tuwien.infosys.ComponentRepository.java

@RequestMapping(value = "/dependencies/{componentName}/{version}", method = RequestMethod.GET)
public ResponseEntity<List<Dependency>> getDependency(@PathVariable String componentName,
        @PathVariable String version) {

    List<Dependency> dependencies = null;
    try {/*from  w  w  w . j  av  a2 s .co  m*/
        dependencies = componentRepository
                .getDependencies(new Component(componentName, new Version(version), null, null));
    } catch (NotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if (dependencies != null)
        return new ResponseEntity<List<Dependency>>(dependencies, HttpStatus.OK);

    return new ResponseEntity<List<Dependency>>(HttpStatus.BAD_REQUEST);
}

From source file:org.fineract.module.stellar.TestCreateBridge.java

@Test
public void createBridgeWithInvalidStellarAddressMifosTenant() {
    String firstTenantId = "invalid*stellar*address";
    final String mifosAddress = testRig.getMifosAddress();

    final AccountBridgeConfiguration newAccount = new AccountBridgeConfiguration(firstTenantId,
            StellarBridgeTestHelpers.getTenantToken(firstTenantId, mifosAddress), mifosAddress);
    final Response creationResponse = given().header(StellarBridgeTestHelpers.CONTENT_TYPE_HEADER)
            .body(newAccount).post("/modules/stellarbridge");

    creationResponse.then().assertThat().statusCode(HttpStatus.BAD_REQUEST.value());
}

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

@Test
public void request_parameter_binding_errors_are_detailed_as_violations() {
    when().get(UrlSchema.FACILITIES + "?ids=foo").then()
            .spec(assertResponse(HttpStatus.BAD_REQUEST, BindException.class))
            .body("message", is("Invalid request parameters")).body("violations[0].path", is("ids"))
            .body("violations[0].message", is(
                    "Failed to convert property value of type 'java.lang.String' to required type 'java.util.Set' for property "
                            + "'ids'; nested exception is java.lang.NumberFormatException: For input string: \"foo\""));
}

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

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