當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpRequestMethodNotSupportedException類代碼示例

本文整理匯總了Java中org.springframework.web.HttpRequestMethodNotSupportedException的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequestMethodNotSupportedException類的具體用法?Java HttpRequestMethodNotSupportedException怎麽用?Java HttpRequestMethodNotSupportedException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpRequestMethodNotSupportedException類屬於org.springframework.web包,在下文中一共展示了HttpRequestMethodNotSupportedException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processMethodNotSupportedException

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public ErrorVM processMethodNotSupportedException(HttpRequestMethodNotSupportedException exception) {
    log.debug("Method not supported", exception);
    return new ErrorVM(ErrorConstants.ERR_METHOD_NOT_SUPPORTED, translate(ErrorConstants.ERR_METHOD_NOT_SUPPORTED));
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:8,代碼來源:ExceptionTranslator.java

示例2: handleHttpRequestMethodNotSupportedException

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
/**
 * 405 - Method Not Allowed
 * @param e
 * @return
 */
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ReturnPureNotifyApi handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
    logger.error("[METHOD NOT ALLOWED] " + e.getMessage());
    return new ReturnPureNotifyApi(ApiStatus.METHOD_NOT_ALLOWED);
}
 
開發者ID:MasonQAQ,項目名稱:WeatherSystem,代碼行數:12,代碼來源:ExceptionAdvice.java

示例3: service

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	LocaleContextHolder.setLocale(request.getLocale());
	try {
		this.target.handleRequest(request, response);
	}
	catch (HttpRequestMethodNotSupportedException ex) {
		String[] supportedMethods = ex.getSupportedMethods();
		if (supportedMethods != null) {
			response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
		}
		response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage());
	}
	finally {
		LocaleContextHolder.resetLocaleContext();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:HttpRequestHandlerServlet.java

示例4: handleRequest

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
/**
 * Processes the incoming Burlap request and creates a Burlap response.
 */
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (!"POST".equals(request.getMethod())) {
		throw new HttpRequestMethodNotSupportedException(request.getMethod(),
				new String[] {"POST"}, "BurlapServiceExporter only supports POST requests");
	}

	try {
	  invoke(request.getInputStream(), response.getOutputStream());
	}
	catch (Throwable ex) {
	  throw new NestedServletException("Burlap skeleton invocation failed", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:BurlapServiceExporter.java

示例5: handleRequest

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
/**
 * Processes the incoming Hessian request and creates a Hessian response.
 */
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {

	if (!"POST".equals(request.getMethod())) {
		throw new HttpRequestMethodNotSupportedException(request.getMethod(),
				new String[] {"POST"}, "HessianServiceExporter only supports POST requests");
	}

	response.setContentType(CONTENT_TYPE_HESSIAN);
	try {
	  invoke(request.getInputStream(), response.getOutputStream());
	}
	catch (Throwable ex) {
	  throw new NestedServletException("Hessian skeleton invocation failed", ex);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:HessianServiceExporter.java

示例6: handleHttpRequestMethodNotSupportedException

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
/**
 * 405 - Method Not Allowed
 */
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
    LOGGER.error("不支持當前請求方法", e);
    return ResponseEntity.badRequest().body("request_method_not_supported");
}
 
開發者ID:helloworldtang,項目名稱:spring-boot-jwt-jpa,代碼行數:10,代碼來源:GlobalHandler.java

示例7: resolveException

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
                                     Exception ex) {
    FResult<String> result = null;
    if (ex instanceof HttpRequestMethodNotSupportedException) {
        HttpRequestMethodNotSupportedException newExp = (HttpRequestMethodNotSupportedException) ex;
        result = FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, newExp.getMessage());
    } else if (ex instanceof MaxUploadSizeExceededException) {
        result = FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, "上傳文件大小超出限製");
    } else if (ex instanceof SizeLimitExceededException) {
        result = FResult.newFailure(HttpResponseCode.CLIENT_PARAM_INVALID, "上傳文件大小超出限製");
    } else {
        result = FResult.newFailure(HttpResponseCode.SERVER_ERROR, ex.getMessage());
    }
    ServletUtil.responseOutWithJson(response, result);
    return null;
}
 
開發者ID:devpage,項目名稱:fastdfs-quickstart,代碼行數:18,代碼來源:ExceptionHandler.java

示例8: handleHttpRequestMethodNotSupportedException

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@ResponseStatus(value = HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
//對於接口方法不匹配的異常處理
public BasicResult handleHttpRequestMethodNotSupportedException(
    HttpRequestMethodNotSupportedException e) {
  logError("httpRequestMethodNotSupportedException", e.getMessage(), e);
  return BasicResult
      .fail(BasicResultCode.METHOD_NOT_ALLOW_ERROR.getCode(),
          BasicResultCode.METHOD_NOT_ALLOW_ERROR.getMsg(),
          e.getMessage());
}
 
開發者ID:lord-of-code,項目名稱:loc-framework,代碼行數:12,代碼來源:LocAdviceErrorAutoConfiguration.java

示例9: handleHttpRequestMethodNotSupported

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@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());
}
 
開發者ID:junneyang,項目名稱:xxproject,代碼行數:13,代碼來源:CustomRestExceptionHandler.java

示例10: handleHttpRequestMethodNotSupported

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@Loggable
@ResponseStatus(code = HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ErrorDto handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex) {
    return ErrorDto.builder()
            .errorCode(ErrorCodes.METHOD_NOT_ALLOWED)
            .errors(Collections.singleton(HttpRequestMethodErrorDto.builder()
                    .actualMethod(ex.getMethod())
                    .supportedMethods(ex.getSupportedHttpMethods())
                    .build()))
            .message(ex.getLocalizedMessage())
            .build();
}
 
開發者ID:rozidan,項目名稱:project-template,代碼行數:14,代碼來源:GlobalErrorHandlers.java

示例11: handleHttpRequestMethodNotSupportedException

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
/**
 * 405 - Method Not Allowed
 */
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public Response handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
    logger.error("不支持當前請求方法", e);
    return new Response().failure(ReturnStatus.METHOD_NOT_ALLOWED);
}
 
開發者ID:WinstonZheng,項目名稱:wtem,代碼行數:10,代碼來源:ExceptionAdvice.java

示例12: process

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@Override
public void process(PluginContext ctx, PluginRestMsg msg) {
  try {
    log.debug("[{}] Processing REST msg: {}", ctx.getPluginId(), msg);
    HttpMethod method = msg.getRequest().getMethod();
    switch (method) {
    case GET:
      handleHttpGetRequest(ctx, msg);
      break;
    case POST:
      handleHttpPostRequest(ctx, msg);
      break;
    case DELETE:
      handleHttpDeleteRequest(ctx, msg);
      break;
    default:
      msg.getResponseHolder().setErrorResult(new HttpRequestMethodNotSupportedException(method.name()));
    }
    log.debug("[{}] Processed REST msg.", ctx.getPluginId());
  } catch (Exception e) {
    log.warn("[{}] Exception during REST msg processing: {}", ctx.getPluginId(), e.getMessage(), e);
    msg.getResponseHolder().setErrorResult(e);
  }
}
 
開發者ID:osswangxining,項目名稱:iotplatform,代碼行數:25,代碼來源:DefaultRestMsgHandler.java

示例13: validateMapping

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
/**
 * Validate the given type-level mapping metadata against the current request,
 * checking HTTP request method and parameter conditions.
 * @param mapping the mapping metadata to validate
 * @param request current HTTP request
 * @throws Exception if validation failed
 */
protected void validateMapping(RequestMapping mapping, HttpServletRequest request) throws Exception {
	RequestMethod[] mappedMethods = mapping.method();
	if (!ServletAnnotationMappingUtils.checkRequestMethod(mappedMethods, request)) {
		String[] supportedMethods = new String[mappedMethods.length];
		for (int i = 0; i < mappedMethods.length; i++) {
			supportedMethods[i] = mappedMethods[i].name();
		}
		throw new HttpRequestMethodNotSupportedException(request.getMethod(), supportedMethods);
	}

	String[] mappedParams = mapping.params();
	if (!ServletAnnotationMappingUtils.checkParameters(mappedParams, request)) {
		throw new UnsatisfiedServletRequestParameterException(mappedParams, request.getParameterMap());
	}

	String[] mappedHeaders = mapping.headers();
	if (!ServletAnnotationMappingUtils.checkHeaders(mappedHeaders, request)) {
		throw new ServletRequestBindingException("Header conditions \"" +
				StringUtils.arrayToDelimitedString(mappedHeaders, ", ") +
				"\" not met for actual request");
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:30,代碼來源:DefaultAnnotationHandlerMapping.java

示例14: handleHttpRequestMethodNotSupported

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@Override
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(final HttpRequestMethodNotSupportedException ex, final HttpHeaders headers,
        final HttpStatus status, final WebRequest request) {
    logger.info(ex.getClass().getName());
    //
    final ErrorDetail errorDetail = new ErrorDetail();
    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 + " "));

    errorDetail.setTimeStamp(new Date().getTime());
    errorDetail.setStatus(status.value());
    errorDetail.setTitle("Method not supported");
    errorDetail.setDetail(builder.toString());
    errorDetail.setDeveloperMessage(ex.getClass().getName());

    return handleExceptionInternal(ex, errorDetail, headers, status, request);
}
 
開發者ID:tvajjala,項目名稱:interview-preparation,代碼行數:20,代碼來源:GlobalExceptionHandler.java

示例15: postContent

import org.springframework.web.HttpRequestMethodNotSupportedException; //導入依賴的package包/類
@StoreType("contentstore")
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.POST, headers = "content-type!=multipart/form-data")
@ResponseBody
public ResponseEntity<Resource<?>> postContent(HttpServletRequest request,
		        							   HttpServletResponse response,
					        				   @PathVariable String repository, 
											   @PathVariable String id, 
											   @PathVariable String contentProperty) 
								throws IOException, HttpRequestMethodNotSupportedException, InstantiationException, IllegalAccessException {
	
	Object newContent = this.saveContentInternal(repositories, storeService, repository, id, contentProperty, request.getRequestURI(), request.getHeader("Content-Type"), request.getInputStream());
	if (newContent != null) {
		Resource<?> contentResource = toResource(request, newContent);
		return new ResponseEntity<Resource<?>>(contentResource, HttpStatus.CREATED);
	}
	return null;
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:18,代碼來源:ContentPropertyCollectionRestController.java


注:本文中的org.springframework.web.HttpRequestMethodNotSupportedException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。