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:nu.yona.server.subscriptions.service.WhiteListedNumberServiceException.java

public static WhiteListedNumberServiceException numberAlreadyWhiteListed(String mobileNumber) {
    return new WhiteListedNumberServiceException(HttpStatus.BAD_REQUEST, "error.number.already.white.listed",
            mobileNumber);/*from   w w w  .j  a v a 2s  . c o  m*/
}

From source file:io.curly.commons.config.feign.ErrorDecoderFactory.java

public static Exception create(HttpStatus httpStatus, String reason) {
    if (httpStatus.equals(HttpStatus.NOT_FOUND)) {
        return new ResourceNotFoundException(reason);
    } else if (httpStatus.equals(HttpStatus.BAD_REQUEST)) {
        return new BadRequestException(reason);
    } else if (httpStatus.equals(HttpStatus.INTERNAL_SERVER_ERROR)) {
        return new InternalServerErrorException(reason);
    } else if (httpStatus.equals(HttpStatus.UNAUTHORIZED)) {
        return new UnauthorizedException(reason);
    } else if (httpStatus.equals(HttpStatus.UNSUPPORTED_MEDIA_TYPE)) {
        return new UnsupportedMediaTypeException(reason);
    }/*w  ww.j  a v a2s .c o m*/
    return new BadRequestException(reason);

}

From source file:cn.edu.zjnu.acm.judge.util.ValueCheck.java

public static void checkUserId(String userId) {
    if (StringUtils.isEmpty(userId)) {
        throw new MessageException("User ID can not be NULL", HttpStatus.BAD_REQUEST);
    }/*  www.  j av a2  s  .  com*/
    if (userId.length() < 6) {
        throw new MessageException("User ID is too short", HttpStatus.BAD_REQUEST);
    }
    if (userId.length() > 20) {
        throw new MessageException("User ID is too long", HttpStatus.BAD_REQUEST);
    }
    if (!userId.matches("(?i)[a-z0-9_]+")) {
        throw new MessageException("User ID can only contain number, letter and '_'", HttpStatus.BAD_REQUEST);
    }
}

From source file:nu.yona.server.subscriptions.service.WhiteListedNumberServiceException.java

public static WhiteListedNumberServiceException numberNotWhiteListed(String mobileNumber) {
    return new WhiteListedNumberServiceException(HttpStatus.BAD_REQUEST, "error.number.not.white.listed",
            mobileNumber);//  w  w  w .  j a v a 2s  . c  om
}

From source file:net.maritimecloud.identityregistry.utils.ValidateUtil.java

public static void hasErrors(BindingResult bindingResult, HttpServletRequest request)
        throws McBasicRestException {
    if (bindingResult.hasErrors()) {
        String combinedErrMsg = "";
        for (ObjectError err : bindingResult.getAllErrors()) {
            if (combinedErrMsg.length() != 0) {
                combinedErrMsg += ", ";
            }//from  w  ww .  j  a v a2  s  .c o  m
            combinedErrMsg += err.getDefaultMessage();
        }
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, combinedErrMsg, request.getServletPath());
    }
}

From source file:net.lalotech.spring.mvc.rest.controller.BaseREST.java

@ExceptionHandler(Exception.class)
@ResponseBody//from ww  w. j a va  2s  . com
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public String handleException(Exception e) {
    return "System Error";
}

From source file:com.parivero.swagger.demo.controller.ControllerExceptionHandler.java

@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public void llegalArgumentExceptionHandler(IllegalArgumentException exception) {

}

From source file:org.zols.web.exceptionhandling.ApiExceptionHandlerAdvice.java

/**
 * Handle exceptions thrown by handlers.
 *
 * @param exception/*from  w  ww  .  j  a va2  s  .  com*/
 * @param request
 * @return
 */
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(Exception.class)
@ResponseBody
ErrorInfo handleBadRequest(HttpServletRequest req, Exception ex) {
    return new ErrorInfo(req.getRequestURI(), ex);
}

From source file:cn.edu.zjnu.acm.judge.util.ValueCheck.java

public static void checkPassword(String password) {
    if (StringUtils.isEmpty(password)) {
        throw new MessageException("Password can not be NULL", HttpStatus.BAD_REQUEST);
    }/*from w  w  w  .j a  va2  s  . co m*/
    if (password.length() > 20) {
        throw new MessageException("Password is too long", HttpStatus.BAD_REQUEST);
    }
    if (password.length() < 6) {
        throw new MessageException("Password is too short", HttpStatus.BAD_REQUEST);
    }
    for (int i = 0; i < password.length(); ++i) {
        if (password.charAt(i) == ' ') {
            throw new MessageException("Password can not contain spaces", HttpStatus.BAD_REQUEST);
        }
    }
    for (int i = 0; i < password.length(); ++i) {
        char ch = password.charAt(i);
        if (ch >= 127 || ch < 32) {
            throw new MessageException("Password contains invalid character", HttpStatus.BAD_REQUEST);
        }
    }
}

From source file:models.ErrorInfoTest.java

public void testToResponse() throws Exception {
    ErrorInfo errorInfo = new ErrorInfo("Bad request", HttpStatus.BAD_REQUEST);

    String expected = "{\"message\":\"Bad request\",\"status\":\"BAD_REQUEST\"}";
    String actual = errorInfo.toResponse().getEntity().toString();

    Assert.assertEquals(expected, actual);
}