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.EpVhost.java

@RequestMapping(value = "", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity createVhost(Authentication _authentication, @RequestBody @Valid VhostCreationRequest _vcr,
        BindingResult _bindingResult) {/* ww w  . j  a v a 2 s  .  c  o  m*/

    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()).response();
    }

    Vhost v = new Vhost(_vcr);

    vhosts.save(v);

    return ResponseEntity.ok(v);
}

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

private ResponseEntity<PropertyRuleResult> checkForErrors(Property reqProperty) {
    List<String> errors = DomainValidator.checkForErrors(reqProperty);

    if (!errors.isEmpty()) {
        return new ResponseEntity<PropertyRuleResult>(new PropertyRuleResult(reqProperty, errors),
                HttpStatus.BAD_REQUEST);
    }//from w ww  .  jav  a 2 s  . c  o m
    if (!products.exists(reqProperty.getKey().getProduct())) {
        return new ResponseEntity<PropertyRuleResult>(new PropertyRuleResult(reqProperty, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    if (!components
            .exists(new ComponentKey(reqProperty.getKey().getProduct(), reqProperty.getKey().getComponent()))) {
        return new ResponseEntity<PropertyRuleResult>(new PropertyRuleResult(reqProperty, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    PropertyKey globalKey = new PropertyKey(reqProperty.getKey().getProduct(),
            reqProperty.getKey().getComponent(), reqProperty.getKey().getName());
    if (!properties.exists(globalKey)) {
        return new ResponseEntity<PropertyRuleResult>(
                new PropertyRuleResult(reqProperty, Property.GLOBAL_NOT_FOUND), HttpStatus.NOT_FOUND);
    }

    if (StringUtils.equalsIgnoreCase(reqProperty.getKey().getRuleName(), Property.DEFAULT_RULE_NAME)) {
        return new ResponseEntity<PropertyRuleResult>(
                new PropertyRuleResult(reqProperty, Property.GLOBAL_UPDATE), HttpStatus.BAD_REQUEST);
    }

    return null;
}

From source file:org.osiam.addons.self_administration.registration.RegistrationController.java

@RequestMapping(method = RequestMethod.POST)
public String register(@Valid final RegistrationUser registrationUser, final BindingResult bindingResult,
        final Model model, final HttpServletRequest request, final HttpServletResponse response) {

    if (bindingResult.hasErrors()) {
        model.addAttribute("allowedFields", registrationService.getAllAllowedFields());
        response.setStatus(HttpStatus.BAD_REQUEST.value());
        return "registration";
    }//from  w ww.  j av a2s. c o m

    User user = registrationService.convertToScimUser(registrationUser);

    try {
        callbackPlugin.performPreRegistrationActions(user);
    } catch (CallbackException e) {
        model.addAttribute("errorMessage", e.getMessage());
        model.addAttribute("allowedFields", registrationService.getAllAllowedFields());

        response.setStatus(HttpStatus.BAD_REQUEST.value());
        return "registration";
    }

    user = registrationService.saveRegistrationUser(user);

    registrationService.sendRegistrationEmail(user, request);

    model.addAttribute("user", user);

    response.setStatus(HttpStatus.CREATED.value());
    try {
        callbackPlugin.performPostRegistrationActions(user);
    } catch (CallbackException p) {
        LOGGER.error("An exception occurred while performing post registration actions for user with ID: "
                + user.getId(), p);
    }
    return "registrationSuccess";
}

From source file:ch.wisv.areafiftylan.extras.rfid.controller.RFIDController.java

@ExceptionHandler(InvalidRFIDException.class)
public ResponseEntity<?> handleInvalidRFIDException(InvalidRFIDException e) {
    return createResponseEntity(HttpStatus.BAD_REQUEST, e.getMessage());
}

From source file:org.trustedanalytics.servicebroker.h2o.service.H2oProvisionerClientTest.java

@Test
public void provisionInstance_provisionerEndsWithStatus500_exceptionThrown() throws Exception {
    // arrange/* ww  w.ja  v a  2s  . c  o m*/
    expectedException.expect(ServiceBrokerException.class);
    expectedException.expectMessage("Unable to provision h2o for: " + INSTANCE_ID);
    when(h2oRestMock.createH2oInstance(INSTANCE_ID, H2O_NODES, H2O_MEMORY, KERBEROS, YARN_CONF))
            .thenReturn(new ResponseEntity<>(HttpStatus.BAD_REQUEST));

    // act
    h2oProvisioner.provisionInstance(INSTANCE_ID);
}

From source file:org.syncope.core.rest.data.SchemaDataBinder.java

public void update(final SchemaTO schemaTO, final AbstractSchema schema,
        final AttributableUtil attributableUtil) throws SyncopeClientCompositeErrorException {

    SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(
            HttpStatus.BAD_REQUEST);

    List<AbstractAttr> attrs = schemaDAO.getAttributes(schema, attributableUtil.attributeClass());
    if (!attrs.isEmpty()) {
        if (schema.getType() != schemaTO.getType()) {
            SyncopeClientException e = new SyncopeClientException(
                    SyncopeClientExceptionType.valueOf("Invalid" + schema.getClass().getSimpleName()));
            e.addElement("Cannot change type since " + schema.getName() + " has attributes");

            scce.addException(e);// w  ww.  j a v a  2  s. co  m
        }
        if (schema.isUniqueConstraint() != schemaTO.isUniqueConstraint()) {
            SyncopeClientException e = new SyncopeClientException(
                    SyncopeClientExceptionType.valueOf("Invalid" + schema.getClass().getSimpleName()));
            e.addElement("Cannot alter unique contraint since " + schema.getName() + " has attributes");

            scce.addException(e);
        }
    }

    if (scce.hasExceptions()) {
        throw scce;
    }

    populate(schema, schemaTO);
}

From source file:se.skltp.cooperation.web.rest.exception.DefaultExceptionHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*from   w  ww  . j a v  a  2s  . c  o m*/
public ProblemDetail processValidationError(HttpServletRequest request, MethodArgumentNotValidException e) {
    log.debug("Handling form validation error");

    ValidationError error = new ValidationError();
    buildErrorMessage(request, e, HttpStatus.BAD_REQUEST, error);

    BindingResult result = e.getBindingResult();
    List<FieldError> fieldErrors = result.getFieldErrors();

    for (FieldError fieldError : fieldErrors) {
        log.debug("Adding error message: {} to field: {}", fieldError.getDefaultMessage(),
                fieldError.getField());
        error.addFieldError(fieldError.getField(), fieldError.getCode(), fieldError.getDefaultMessage());
    }

    return error;
}

From source file:org.syncope.core.rest.data.DerivedSchemaDataBinder.java

public AbstractDerSchema update(final DerivedSchemaTO derivedSchemaTO, final AbstractDerSchema derivedSchema) {

    return populate(derivedSchema, derivedSchemaTO,
            new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST));
}

From source file:org.easyj.rest.controller.AbstractController.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(BadRequestException.class)
public ModelAndView handleBadRequest(BadRequestException ex) {
    return handleModelAndView(ex);
}

From source file:com.cfitzarl.cfjwed.controller.ApiExceptionHandler.java

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler({ MappingException.class, BadRequestException.class, IllegalArgumentException.class,
        MethodArgumentNotValidException.class })
public void handleBadRequestExceptions(Exception e, HttpServletResponse response) throws IOException {
    String code = "errors.bad.data";

    // Use provided message code if present and valid
    if (localizationService.codeExists(e.getMessage())) {
        code = e.getMessage();//from w w w. j a v a  2  s.co  m
    }

    respond(e, code, response);
}