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:edu.pitt.dbmi.ccd.anno.error.ErrorHandler.java

@ExceptionHandler(AccessUpdateException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//from  ww  w .j a v a2s  . com
public ErrorMessage handleAccessUpdateException(AccessUpdateException ex, HttpServletRequest req) {
    LOGGER.info(ex.getMessage());
    return new ErrorMessage(HttpStatus.BAD_REQUEST, ex.getMessage(), req);
}

From source file:org.esbtools.gateway.resubmit.controller.ResubmitGateway.java

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

From source file:com.acc.controller.BaseController.java

/**
 * /*from w  ww.j a  v  a 2 s .com*/
 * @param excp
 *           to support basic exception marshaling to JSON and XML. It will determine the format based on the
 *           request's Accept header.
 * @param request
 * @param writer
 * @throws IOException
 * @return {@link ErrorData} as a response body
 */
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
@ExceptionHandler({ IllegalArgumentException.class, UnknownIdentifierException.class,
        AmbiguousIdentifierException.class, ModelSavingException.class, JaloInvalidParameterException.class,
        DuplicateUidException.class, PasswordMismatchException.class, ModelNotFoundException.class,
        ConversionException.class })
public ErrorData handleException(final Exception excp, final HttpServletRequest request, final Writer writer)
        throws IOException {
    LOG.info("Handling Exception for this request - " + excp.getClass().getSimpleName() + " - "
            + excp.getMessage());
    if (LOG.isDebugEnabled()) {
        LOG.debug(excp);
    }
    final ErrorData errorData = handleErrorInternal(excp.getClass().getSimpleName(), excp.getMessage());
    return errorData;
}

From source file:com.logsniffer.web.controller.exception.RestErrorHandler.java

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody//from  ww  w  .j a  v  a  2 s.  c o m
public ErrorResponse processValidationError(final MethodArgumentNotValidException ex,
        final HttpServletResponse response) throws IOException {
    return processFieldErrors(processExceptionResponse(ex, response, org.apache.http.HttpStatus.SC_BAD_REQUEST),
            ex.getBindingResult().getFieldErrors());
}

From source file:com.boyuanitsm.fort.web.rest.AccountResource.java

/**
 * POST  /register : register the user./* www  .j av  a2 s. c  om*/
 *
 * @param managedUserDTO the managed user DTO
 * @param request the HTTP request
 * @return the ResponseEntity with status 201 (Created) if the user is registred or 400 (Bad Request) if the login or e-mail is already in use
 */
@RequestMapping(value = "/register", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE,
        MediaType.TEXT_PLAIN_VALUE })
@Timed
public ResponseEntity<?> registerAccount(@Valid @RequestBody ManagedUserDTO managedUserDTO,
        HttpServletRequest request) {

    HttpHeaders textPlainHeaders = new HttpHeaders();
    textPlainHeaders.setContentType(MediaType.TEXT_PLAIN);

    return userRepository.findOneByLogin(managedUserDTO.getLogin().toLowerCase())
            .map(user -> new ResponseEntity<>("login already in use", textPlainHeaders, HttpStatus.BAD_REQUEST))
            .orElseGet(() -> userRepository.findOneByEmail(managedUserDTO.getEmail())
                    .map(user -> new ResponseEntity<>("e-mail address already in use", textPlainHeaders,
                            HttpStatus.BAD_REQUEST))
                    .orElseGet(() -> {
                        User user = userService.createUserInformation(managedUserDTO.getLogin(),
                                managedUserDTO.getPassword(), managedUserDTO.getFirstName(),
                                managedUserDTO.getLastName(), managedUserDTO.getEmail().toLowerCase(),
                                managedUserDTO.getLangKey());
                        String baseUrl = request.getScheme() + // "http"
                        "://" + // "://"
                        request.getServerName() + // "myhost"
                        ":" + // ":"
                        request.getServerPort() + // "80"
                        request.getContextPath(); // "/myContextPath" or "" if deployed in root context

                        mailService.sendActivationEmail(user, baseUrl);
                        return new ResponseEntity<>(HttpStatus.CREATED);
                    }));
}

From source file:org.openlmis.fulfillment.web.OrderNumberConfigurationController.java

/**
 * Saves given OrderNumberConfiguration to database.
 *
 * @param orderNumberConfigurationDto object to save.
 * @return Response entity with Http status code.
 *//*from   w w  w . j  av a 2 s  .  co m*/
@RequestMapping(value = "/orderNumberConfigurations", method = RequestMethod.POST)
public ResponseEntity<Object> saveOrderNumberConfigurations(
        @RequestBody @Valid OrderNumberConfigurationDto orderNumberConfigurationDto,
        BindingResult bindingResult) {

    LOGGER.debug("Checking right to update order number configuration");
    permissionService.canManageSystemSettings();

    if (bindingResult.hasErrors()) {
        return new ResponseEntity<>(getErrors(bindingResult), HttpStatus.BAD_REQUEST);
    }

    OrderNumberConfiguration orderNumberConfiguration = OrderNumberConfiguration
            .newInstance(orderNumberConfigurationDto);

    Iterator<OrderNumberConfiguration> it = orderNumberConfigurationRepository.findAll().iterator();

    if (it.hasNext()) {
        orderNumberConfiguration.setId(it.next().getId());
    }

    OrderNumberConfiguration savedOrderNumberConfiguration = orderNumberConfigurationRepository
            .save(orderNumberConfiguration);

    OrderNumberConfigurationDto orderNumberConfigurationDto1 = OrderNumberConfigurationDto
            .newInstance(savedOrderNumberConfiguration);

    return new ResponseEntity<>(orderNumberConfigurationDto1, HttpStatus.OK);
}

From source file:com.netflix.scheduledactions.web.controllers.ValidationController.java

@ExceptionHandler(InvalidISO8601IntervalException.class)
void handleInvalidISOExpression(HttpServletResponse response, InvalidISO8601IntervalException e)
        throws IOException {
    response.sendError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
}

From source file:com.github.cherimojava.orchidae.controller.LayoutController.java

@RequestMapping(value = "/**/{form}.form", method = POST)
public Object processForm(HttpServletRequest request, @PathVariable("form") String form) {
    switch (form.toLowerCase()) {
    case "register":
        return registerUser(request);
    default://from   ww w .ja  v a 2 s  . co  m
        return new ResponseEntity<>("Not Found", HttpStatus.BAD_REQUEST);
    }
}

From source file:com.onyxscheduler.web.JobController.java

@ExceptionHandler(Scheduler.DuplicateJobKeyException.class)
void handleBadRequests(HttpServletResponse response) throws IOException {
    response.sendError(HttpStatus.BAD_REQUEST.value());
}

From source file:edu.eci.arsw.pacm.controllers.PacmRESTController.java

@RequestMapping(path = "/{salanum}/atacantes", method = RequestMethod.GET)
public ResponseEntity<?> getAtacantes(@PathVariable(name = "salanum") String salanum) {

    try {//from  w w w.j  a  va  2s  .co  m
        return new ResponseEntity<>(services.getAtacantes(Integer.parseInt(salanum)), HttpStatus.ACCEPTED);
    } catch (ServicesException ex) {
        Logger.getLogger(PacmRESTController.class.getName()).log(Level.SEVERE, null, ex);
        return new ResponseEntity<>(ex.getLocalizedMessage(), HttpStatus.NOT_FOUND);
    } catch (NumberFormatException ex) {
        Logger.getLogger(PacmRESTController.class.getName()).log(Level.SEVERE, null, ex);
        return new ResponseEntity<>("/{salanum}/ must be an integer value.", HttpStatus.BAD_REQUEST);
    }
}