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:reconf.server.services.component.ReadComponentService.java

@RequestMapping(value = "/product/{prod}/component/{comp}", method = RequestMethod.GET)
@Transactional(readOnly = true)/*from  w  w w  . j  a v a2s  .c  om*/
public ResponseEntity<ComponentResult> doIt(@PathVariable("prod") String productId,
        @PathVariable("comp") String componentId, HttpServletRequest request, Authentication auth) {

    ComponentKey key = new ComponentKey(productId, componentId);
    Component reqComponent = new Component(key);

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

    Component dbComponent = components.findOne(key);
    if (dbComponent == null) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    return new ResponseEntity<ComponentResult>(
            new ComponentResult(dbComponent, CrudServiceUtils.getBaseUrl(request)), HttpStatus.OK);
}

From source file:com.github.woki.payments.adyen.simulator.web.controller.PaymentController.java

@RequestMapping(value = { "/pal/servlet/Payment/v30/authorise",
        "/pal/servlet/Payment/v30/authorise3d" }, method = RequestMethod.POST)
public ResponseEntity<PaymentResponse> authorize(@RequestBody PaymentRequest request) {
    PaymentResponse res = new PaymentResponse();
    if ("gimme_500".equals(request.getReference())) {
        res.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return new ResponseEntity<>(res, HttpStatus.INTERNAL_SERVER_ERROR);
    }/*from   w  w  w  .  ja  v  a2 s  . c  o m*/
    if ("gimme_400".equals(request.getReference())) {
        res.setStatus(HttpStatus.BAD_REQUEST.value());
        return new ResponseEntity<>(res, HttpStatus.BAD_REQUEST);
    }
    if ("gimme_422".equals(request.getReference())) {
        res.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return new ResponseEntity<>(res, HttpStatus.UNPROCESSABLE_ENTITY);
    }
    if ("gimme_401".equals(request.getReference())) {
        res.setStatus(HttpStatus.UNAUTHORIZED.value());
        return new ResponseEntity<>(res, HttpStatus.UNAUTHORIZED);
    }
    if ("gimme_403".equals(request.getReference())) {
        res.setStatus(HttpStatus.FORBIDDEN.value());
        return new ResponseEntity<>(res, HttpStatus.FORBIDDEN);
    }
    if ("gimme_404".equals(request.getReference())) {
        res.setStatus(HttpStatus.NOT_FOUND.value());
        return new ResponseEntity<>(res, HttpStatus.NOT_FOUND);
    }
    if ("gimme_200".equals(request.getReference())) {
        res.setStatus(HttpStatus.OK.value());
        return new ResponseEntity<>(res, HttpStatus.OK);
    }
    res.setStatus(HttpStatus.NON_AUTHORITATIVE_INFORMATION.value());
    return new ResponseEntity<>(res, HttpStatus.NON_AUTHORITATIVE_INFORMATION);
}

From source file:com.softcrylic.dockeryamlcatalog.controller.tomcat7jdk7.java

@RequestMapping(value = "/tm7jd7", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody ResponseEntity<String> post_Tomcat7Jdk7_Yml(@RequestBody String inputJson) {

    FigCommandClassDef fccd = new FigCommandClassDef();

    StringBuilder sb = new StringBuilder();

    try {//w w w.  j  av a2 s.c  o  m
        /**
         * Get the Json and Assigned to class definition
         */
        fccd = gson.fromJson(inputJson, FigCommandClassDef.class);

        /**
         * Check parent should be present
         */
        if (fccd.getContainer_id().equals("") || fccd.getContainer_id().equals(null)) {
            return new ResponseEntity<String>("Container_Id can't be null or left blank",
                    HttpStatus.BAD_REQUEST);
        }

        /**
         * Generate the Yaml
         */

        sb = YmlBuilder.buildYaml(fccd);

    } catch (Exception e) {
        return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
    }
    return new ResponseEntity<String>(sb.toString(), HttpStatus.OK);
}

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

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}", method = RequestMethod.DELETE)
@Transactional/*  ww w .  j  a  v a  2  s  . co  m*/
public ResponseEntity<PropertyResult> global(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property, Authentication auth) {

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

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

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

From source file:br.eti.danielcamargo.backend.common.rest.handlers.GlobalExceptionHandler.java

@ExceptionHandler({ BusinessException.class })
public ResponseEntity<List<Mensagem>> handleBadRequest(final BusinessException ex, final WebRequest request) {
    List<ValidationOccurrence> ocorrencias = ex.getOccurrences();
    List<Mensagem> mensagens = new ArrayList<>();
    for (ValidationOccurrence validationOccurrence : ocorrencias) {
        if (validationOccurrence.isConstraintViolation()) {
            mensagens.add(MessageUtils.criarMensagemErroValidacao(ex.getModulo(), validationOccurrence));
        } else {//from  www  . j  a  va 2  s  .  co  m
            mensagens.add(MessageUtils.criarMensagemErro(ex.getModulo(), validationOccurrence));
        }
    }

    ResponseEntity<List<Mensagem>> responseEntity = new ResponseEntity<>(mensagens, HttpStatus.BAD_REQUEST);
    return responseEntity;
}

From source file:org.openwms.tms.StateChangeException.java

/**
 * {@inheritDoc}
 */
@Override
public HttpStatus getStatus() {
    return HttpStatus.BAD_REQUEST;
}

From source file:org.wallride.web.controller.guest.comment.CommentRestController.java

@ExceptionHandler(BindException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public RestValidationErrorModel bindException(BindException e) {
    logger.debug("BindException", e);
    return RestValidationErrorModel.fromBindingResult(e.getBindingResult(), messageSourceAccessor);
}

From source file:com.fabionoth.rest.RobotRest.java

/**
 *
 * @param command//www .j a v  a 2 s. c  o m
 * @return
 */
@RequestMapping(value = { "rest/mars/", "/rest/mars/{command}" }, method = { RequestMethod.GET,
        RequestMethod.POST })
public ResponseEntity<String> sendCommand(@PathVariable Optional<String> command) {
    Robot robot;
    robot = new Robot(new Long(1), 0, 0, CardinalPoints.N);

    HttpHeaders responseHeaders = new HttpHeaders();
    responseHeaders.setContentType(MediaType.TEXT_HTML);

    if (command.isPresent()) {
        try {
            robot = new RobotController(robot, command.get()).getRobot();
        } catch (Exception ex) {
            Logger.getLogger(RobotRest.class.getName()).log(Level.SEVERE, null, ex);
            return new ResponseEntity<>("Erro", responseHeaders, HttpStatus.BAD_REQUEST);
        }
    }

    String response = "(" + robot.getX() + ", " + robot.getY() + ", " + robot.getC().toString() + ")";
    return new ResponseEntity<>(response, responseHeaders, HttpStatus.OK);

}

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

@Test
public void invalidSortField() {
    ResponseEntity<RestError> response = get("/api/v1/integrations?sort=invalid_field", RestError.class,
            HttpStatus.BAD_REQUEST);/*from  w w w.  j a v  a  2  s.c o  m*/
    assertThat(response.getBody().getErrorCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());
    assertThat(response.getBody().getUserMsg()).isEqualTo("Please check your sorting arguments");
    assertThat(response.getBody().getDeveloperMsg()).startsWith("Illegal Argument on Call");
}

From source file:reconf.server.services.component.DeleteComponentService.java

@RequestMapping(value = "/product/{prod}/component/{comp}", method = RequestMethod.DELETE)
@Transactional//from   w w w  .  j a v  a2s .co  m
public ResponseEntity<ComponentResult> doIt(@PathVariable("prod") String productId,
        @PathVariable("comp") String componentId, Authentication auth) {

    ComponentKey key = new ComponentKey(productId, componentId);
    Component reqComponent = new Component(key);

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

    if (!products.exists(key.getProduct())) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    Component dbComponent = components.findOne(key);
    if (dbComponent == null) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, Component.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }

    components.delete(dbComponent);
    properties.deleteByKeyProductAndKeyComponent(key.getProduct(), key.getName());
    return new ResponseEntity<ComponentResult>(HttpStatus.OK);
}