本文整理汇总了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));
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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");
}
示例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;
}
示例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());
}
示例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());
}
示例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();
}
示例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);
}
示例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);
}
}
示例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");
}
}
示例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);
}
示例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;
}