Example usage for org.springframework.web HttpRequestMethodNotSupportedException getMessage

List of usage examples for org.springframework.web HttpRequestMethodNotSupportedException getMessage

Introduction

In this page you can find the example usage for org.springframework.web HttpRequestMethodNotSupportedException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:cz.jirutka.spring.exhandler.handlers.HttpRequestMethodNotSupportedExceptionHandler.java

@Override
public ResponseEntity<ErrorMessage> handleException(HttpRequestMethodNotSupportedException ex,
        HttpServletRequest req) {//from   w  ww .ja v a2s  .  c  o  m
    LOG.warn(ex.getMessage());

    return super.handleException(ex, req);
}

From source file:org.trustedanalytics.user.invite.RestErrorHandler.java

@ResponseBody
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public String userExists(HttpRequestMethodNotSupportedException e) throws IOException {
    return e.getMessage();
}

From source file:com.haulmont.restapi.idp.IdpAuthController.java

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
public ResponseEntity<OAuth2Exception> handleHttpRequestMethodNotSupportedException(
        HttpRequestMethodNotSupportedException e) throws Exception {
    log.info("Handling error: {}, {}", e.getClass().getSimpleName(), e.getMessage());
    return getExceptionTranslator().translate(e);
}

From source file:com.janrain.backplane2.server.Backplane2Controller.java

/**
 * Handle invalid HTTP request method exceptions
 *//*from   w w  w  . j  a va2  s  .c  o m*/
@ExceptionHandler
@ResponseBody
public Map<String, Object> handleInvalidRequest(final HttpRequestMethodNotSupportedException e,
        HttpServletResponse response) {
    logger.warn("Error handling backplane request: " + e.getMessage(), bpConfig.getDebugException(e));
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return new HashMap<String, Object>() {
        {
            put(ERR_MSG_FIELD, e.getMessage());
        }
    };
}

From source file:org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerSupport.java

/**
 * Customize the response for HttpRequestMethodNotSupportedException.
 * This method logs a warning, sets the "Allow" header, and delegates to
 * {@link #handleExceptionInternal(Exception, HttpHeaders, HttpStatus, WebRequest)}.
 * @param ex the exception//from   w  ww . j  a  va  2  s  .  c o m
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return an Object or {@code null}
 */
protected Object handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {

    pageNotFoundLogger.warn(ex.getMessage());

    Set<HttpMethod> mediaTypes = new HashSet<HttpMethod>();
    for (String value : ex.getSupportedMethods()) {
        mediaTypes.add(HttpMethod.valueOf(value));
    }
    if (!mediaTypes.isEmpty()) {
        headers.setAllow(mediaTypes);
    }

    return handleExceptionInternal(ex, headers, status, request);
}

From source file:org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler.java

/**
 * Customize the response for HttpRequestMethodNotSupportedException.
 * <p>This method logs a warning, sets the "Allow" header, and delegates to
 * {@link #handleExceptionInternal}.//from ww w .  j  av a  2  s  . c o m
 * @param ex the exception
 * @param headers the headers to be written to the response
 * @param status the selected response status
 * @param request the current request
 * @return a {@code ResponseEntity} instance
 */
protected ResponseEntity<Object> handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
        HttpHeaders headers, HttpStatus status, WebRequest request) {

    pageNotFoundLogger.warn(ex.getMessage());

    Set<HttpMethod> supportedMethods = ex.getSupportedHttpMethods();
    if (!CollectionUtils.isEmpty(supportedMethods)) {
        headers.setAllow(supportedMethods);
    }
    return handleExceptionInternal(ex, null, headers, status, request);
}

From source file:org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver.java

/**
 * Handle the case where no request handler method was found for the particular HTTP request method.
 * <p>The default implementation logs a warning, sends an HTTP 405 error, sets the "Allow" header,
 * and returns an empty {@code ModelAndView}. Alternatively, a fallback view could be chosen,
 * or the HttpRequestMethodNotSupportedException could be rethrown as-is.
 * @param ex the HttpRequestMethodNotSupportedException to be handled
 * @param request current HTTP request/* w  w  w .jav a2  s . c o  m*/
 * @param response current HTTP response
 * @param handler the executed handler, or {@code null} if none chosen
 * at the time of the exception (for example, if multipart resolution failed)
 * @return an empty ModelAndView indicating the exception was handled
 * @throws IOException potentially thrown from response.sendError()
 */
protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex,
        HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException {

    pageNotFoundLogger.warn(ex.getMessage());
    String[] supportedMethods = ex.getSupportedMethods();
    if (supportedMethods != null) {
        response.setHeader("Allow", StringUtils.arrayToDelimitedString(supportedMethods, ", "));
    }
    response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, ex.getMessage());
    return new ModelAndView();
}