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.wisemapping.rest.BaseController.java

@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/* w ww .j ava2s. co  m*/
public RestErrors handleClientErrors(@NotNull IllegalArgumentException ex) {
    System.err.println(ex.getMessage());
    return new RestErrors(ex.getMessage(), Severity.WARNING);
}

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

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}", method = RequestMethod.PUT)
@Transactional//from   ww w.j av  a2s  . c om
public ResponseEntity<PropertyResult> global(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property,
        @RequestBody String value, @RequestParam(value = "desc", required = false) String description,
        HttpServletRequest request, Authentication auth) {

    PropertyKey key = new PropertyKey(product, component, property);
    Property reqProperty = new Property(key, value, description);

    List<String> errors = DomainValidator.checkForErrors(reqProperty);

    if (!errors.isEmpty()) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, errors),
                HttpStatus.BAD_REQUEST);
    }
    if (!products.exists(key.getProduct())) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    if (!components.exists(new ComponentKey(key.getProduct(), key.getComponent()))) {
        return new ResponseEntity<PropertyResult>(new PropertyResult(reqProperty, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    HttpStatus status = null;
    Property dbProperty = properties.findOne(key);
    if (dbProperty != null) {
        dbProperty.setValue(value);
        dbProperty.setDescription(description);
        status = HttpStatus.OK;

    } else {
        dbProperty = reqProperty;
        properties.save(dbProperty);
        status = HttpStatus.CREATED;
    }
    return new ResponseEntity<PropertyResult>(
            new PropertyResult(dbProperty, CrudServiceUtils.getBaseUrl(request)), status);
}

From source file:org.easy.spring.web.ValidationSupport.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//w  ww  .j av  a 2s.  c o  m
public ValidationError processValidationError(MethodArgumentNotValidException ex) {
    BindingResult errors = ex.getBindingResult();
    ValidationError result = new ValidationError(errors.getObjectName(), errors.getNestedPath(),
            errors.getErrorCount(), errors.getFieldErrors());

    return result;//processFieldErrors(fieldErrors);
}

From source file:gt.dakaik.rest.impl.CountryImpl.java

@Override
public ResponseEntity<Country> doCreate(Country country, int idUsuario, String token)
        throws EntidadDuplicadaException {
    if (country == null) {
        return new ResponseEntity(HttpStatus.BAD_REQUEST);
    }//  w w w .  ja  v a  2  s  .  com
    Country c = country.getIdCountry() != null ? repoCountry.findOne(country.getIdCountry()) : null;

    if (c == null) {
        c = new Country();
        c.setTxtName(country.getTxtName());
        //            c.set(true);
        repoCountry.save(c);
    }

    for (State st : country.getStates()) {
        State stN = st.getIdState() != null ? repoState.findOne(st.getIdState()) : null;
        if (stN == null) {
            stN = new State();
            stN.setTxtName(st.getTxtName());
            //stN.setSnActive(true);
            stN.setCountry(c);
            repoState.save(stN);
        }
        for (City ct : st.getCities()) {
            City ctN = ct.getIdCity() != null ? repoCity.findOne(ct.getIdCity()) : null;
            if (ctN == null) {
                ctN = new City();
                ctN.setTxtName(ct.getTxtName());
                //                    ctN.setSnActive(true);
                ctN.setState(stN);
                repoCity.save(ctN);
            }
        }
    }

    return new ResponseEntity(c, HttpStatus.OK);
}

From source file:com.auditbucket.helper.GlobalControllerExceptionHandler.java

@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ModelAndView handleIAException(IllegalArgumentException ex) {
    return new JsonError(ex.getMessage()).asModelAndView();
}

From source file:com.sentinel.web.controllers.RequestController.java

@RequestMapping(value = "", method = RequestMethod.POST)
@PreAuthorize(value = "hasRole('SIMPLE_USER_PRIVILEGE')")
@ResponseBody/*w w w  .  ja v  a  2  s. co m*/
public ResponseEntity<Void> createRequest(@RequestBody UserRequest userRequest) {
    LOG.debug("creating new Request ");
    try {
        new ObjectMapper().readValue(userRequest.getRequestDetails().trim(), OrientRequestDetails.class);
    } catch (Exception e) {
        LOG.error("Exception while performing operation in createRequest", e);
        return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
    }
    UserAuthentication authentication = (UserAuthentication) SecurityContextHolder.getContext()
            .getAuthentication();
    String userEmail = authentication.getName();
    User user = userRepository.findByEmail(userEmail);
    Collection<User> collection = new ArrayList<User>();
    collection.add(user);
    userRequest.setUsers(collection);
    userRequestRepository.saveAndFlush(userRequest);
    return new ResponseEntity<Void>(HttpStatus.CREATED);
}

From source file:io.onedecision.engine.OneDecisionExceptionHandler.java

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(ConstraintViolationException.class)
@ResponseBody/*from   w  w w  .  j a  v a 2  s  . c  o  m*/
public InvalidDmnException handleInvalidDmn(ConstraintViolationException e) {
    LOGGER.error(e.getMessage(), e);
    return InvalidDmnException.wrap((e.getConstraintViolations()));
}

From source file:org.openlmis.fulfillment.web.errorhandler.WebErrorHandling.java

@ExceptionHandler(ValidationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody/*from  w w w .j  a v a  2 s  .  com*/
public Message.LocalizedMessage handleSingleValidationException(ValidationException ex) {
    return logErrorAndRespond("Validation exception", ex);
}

From source file:com.solace.demos.cloudfoundry.scaling.aggregator.controller.AggregatorController.java

@RequestMapping(value = "/jobs", method = RequestMethod.POST)
public ResponseEntity<String> createJobs(@RequestBody JobRequest jobRequest) {

    log.warn("Entering createJobs");
    try {//from ww  w .  j  av  a 2s  . co m
        solaceController.startJobRequest(jobRequest);
    } catch (Exception e) {
        log.error("Service Creation failed.", e);
        return new ResponseEntity<>("{'description': '" + e.getMessage() + "'}", HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity<>("{}", HttpStatus.OK);
}

From source file:reconf.server.services.security.UpsertUserService.java

@RequestMapping(value = "/user", method = RequestMethod.PUT)
@Transactional//w ww  .  j  a  v  a2  s .  c o  m
public ResponseEntity<Client> doIt(@RequestBody Client client, Authentication authentication) {

    List<String> errors = DomainValidator.checkForErrors(client);
    if (!errors.isEmpty()) {
        return new ResponseEntity<Client>(new Client(client, errors), HttpStatus.BAD_REQUEST);
    }
    HttpStatus status = null;

    List<GrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority("USER"));

    if (ApplicationSecurity.isRoot(authentication)) {
        if (ApplicationSecurity.isRoot(client.getUsername())) {
            return new ResponseEntity<Client>(new Client(client, cannotChangeRootPassword),
                    HttpStatus.BAD_REQUEST);
        }
        status = upsert(client, authorities);

    } else if (StringUtils.equals(client.getUsername(), authentication.getName())) {
        if (!userDetailsManager.userExists(client.getUsername())) {
            return new ResponseEntity<Client>(new Client(client, mustBeRoot), HttpStatus.BAD_REQUEST);
        }
        User user = new User(client.getUsername(), client.getPassword(), authorities);
        userDetailsManager.updateUser(user);
        status = HttpStatus.OK;

    } else {
        return new ResponseEntity<Client>(HttpStatus.FORBIDDEN);
    }

    return new ResponseEntity<Client>(new Client(client), status);
}