org.springframework.http.HttpStatus#METHOD_NOT_ALLOWED源码实例Demo

下面列出了org.springframework.http.HttpStatus#METHOD_NOT_ALLOWED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xxproject   文件: CustomRestExceptionHandler.java
@Override
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(final HttpRequestMethodNotSupportedException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
    logger.info(ex.getClass().getName());
    //
    final StringBuilder builder = new StringBuilder();
    builder.append(ex.getMethod());
    builder.append(" method is not supported for this request. Supported methods are ");
    ex.getSupportedHttpMethods().forEach(t -> builder.append(t + " "));

    final ApiError apiError = new ApiError(HttpStatus.METHOD_NOT_ALLOWED, ex.getLocalizedMessage(), builder.toString());
    return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
 
/**
 * 请求方式不支持异常
 * 比如:POST方式的API, GET方式请求
 */
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
ResponseMessage handleException(HttpRequestMethodNotSupportedException exception) {
    return ResponseMessage
            .error(HttpStatus.METHOD_NOT_ALLOWED.value(), "不支持的请求方式")
            .result(exception.getSupportedHttpMethods());
}
 
源代码3 项目: EasyReport   文件: ExceptionAdvice.java
/**
 * 405 - Method Not Allowed
 */
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseResult handleHttpRequestMethodNotSupportedException(final HttpRequestMethodNotSupportedException e) {
    log.error(HttpStatus.METHOD_NOT_ALLOWED.getReasonPhrase(), e);
    return ResponseResult.failure(SystemErrorCode.METHOD_NOT_ALLOWED, e);
}
 
源代码4 项目: tutorials   文件: CustomRestExceptionHandler.java
@Override
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(final HttpRequestMethodNotSupportedException ex, final HttpHeaders headers, final HttpStatus status, final WebRequest request) {
    logger.info(ex.getClass().getName());
    //
    final StringBuilder builder = new StringBuilder();
    builder.append(ex.getMethod());
    builder.append(" method is not supported for this request. Supported methods are ");
    ex.getSupportedHttpMethods().forEach(t -> builder.append(t + " "));

    final ApiError apiError = new ApiError(HttpStatus.METHOD_NOT_ALLOWED, ex.getLocalizedMessage(), builder.toString());
    return new ResponseEntity<Object>(apiError, new HttpHeaders(), apiError.getStatus());
}
 
/**
 * Handle exceptions that result in a "operation not allowed" status.
 */
@ExceptionHandler(value = MethodNotAllowedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ResponseBody
public ErrorInformation handleOperationNotAllowedException(RuntimeException exception)
{
    return getErrorInformation(HttpStatus.METHOD_NOT_ALLOWED, exception);
}
 
源代码6 项目: Taroco   文件: DefaultExceptionAdvice.java
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler({HttpRequestMethodNotSupportedException.class})
public ResponseEntity handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
    LOGGER.error("不支持当前请求方法", e);
    Response response = Response.failure(DefaultError.METHOD_NOT_SUPPORTED);
    response.setExtMessage(e.getMessage());
    return new ResponseEntity<>(response, HttpStatus.METHOD_NOT_ALLOWED);
}
 
源代码7 项目: batchers   文件: TaxPaymentWebServiceTest.java
private HttpClientErrorException aMethodNotAllowedException() {
    return new HttpClientErrorException(HttpStatus.METHOD_NOT_ALLOWED);
}
 
源代码8 项目: find   文件: GlobalExceptionHandler.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ResponseBody
public ErrorResponse requestMethodNotSupportedHandler(final HttpRequestMethodNotSupportedException exception) throws HttpRequestMethodNotSupportedException {
    return handler(exception);
}
 
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
源代码10 项目: MicroCommunity   文件: CenterApi.java
/**
 *
 * @param request HttpServletRequest对象
 * @return
 */
@RequestMapping(path = "/service",method= RequestMethod.DELETE)
@ApiOperation(value="中心服务delete方式请求", notes="test: 返回 502 表示服务不支持DELETE 请求方式")
public ResponseEntity<String> serviceDelete(HttpServletRequest request) {
    return new ResponseEntity<String>("center服务 不支持GET 请求方式", HttpStatus.METHOD_NOT_ALLOWED);
}
 
源代码11 项目: blade-tool   文件: BladeRestExceptionTranslator.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public R handleError(HttpRequestMethodNotSupportedException e) {
	log.error("不支持当前请求方法:{}", e.getMessage());
	return R.fail(ResultCode.METHOD_NOT_SUPPORTED, e.getMessage());
}
 
/**
 * To ensure no one does login through HTTP GET.
 * returns METHOD_NOT_ALLOWED.
 */
@RequestMapping(value = "/login", method = RequestMethod.GET)
@ResponseStatus( HttpStatus.METHOD_NOT_ALLOWED )
public void get() {
	
}
 
源代码13 项目: flair-registry   文件: ExceptionTranslator.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
源代码14 项目: tutorials   文件: ExceptionTranslator.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
源代码15 项目: flair-engine   文件: ExceptionTranslator.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
源代码17 项目: tutorials   文件: ExceptionTranslator.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<ApiError> handleMethodNotSupportedException(HttpRequestMethodNotSupportedException ex) {
	ApiError apiError = new ApiError(HttpStatus.METHOD_NOT_ALLOWED, ex.getMessage(), null);
	return new ResponseEntity<>(apiError, apiError.getStatus());
}
 
源代码19 项目: klask-io   文件: ExceptionTranslator.java
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorDTO processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    return new ErrorDTO(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, exception.getMessage());
}
 
源代码20 项目: SuperBoot   文件: GlobalExceptionHandler.java
/**
 * 不支持当前请求方法
 *
 * @param e 异常信息
 * @return
 */
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public BaseMessage handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
    return pubTools.genNoMsg(StatusCode.METHOD_NOT_ALLOWED, e.getMessage());
}