Example usage for org.springframework.web.servlet HandlerMapping getHandler

List of usage examples for org.springframework.web.servlet HandlerMapping getHandler

Introduction

In this page you can find the example usage for org.springframework.web.servlet HandlerMapping getHandler.

Prototype

@Nullable
HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception;

Source Link

Document

Return a handler and any interceptors for this request.

Usage

From source file:org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.java

private Object getHandler(HttpServletRequest request) throws Exception {
    HttpServletRequest wrapper = new UnmodifiableAttributesRequestWrapper(request);
    for (HandlerMapping mapping : getMappingIntrospector().getHandlerMappings()) {
        HandlerExecutionChain chain = mapping.getHandler(wrapper);
        if (chain != null) {
            if (mapping instanceof MatchableHandlerMapping) {
                return chain.getHandler();
            }/*from  w ww . java  2 s .c o  m*/
            return null;
        }
    }
    return null;
}

From source file:org.springframework.web.portlet.DispatcherPortlet.java

/**
 * Return the HandlerExecutionChain for this request.
 * Try all handler mappings in order.// w  w w .j  a  v  a 2 s.co  m
 * @param request current portlet request
 * @return the HandlerExecutionChain, or null if no handler could be found
 */
protected HandlerExecutionChain getHandler(PortletRequest request) throws Exception {
    for (HandlerMapping hm : this.handlerMappings) {
        if (logger.isDebugEnabled()) {
            logger.debug("Testing handler map [" + hm + "] in DispatcherPortlet with name '" + getPortletName()
                    + "'");
        }
        HandlerExecutionChain handler = hm.getHandler(request);
        if (handler != null) {
            return handler;
        }
    }
    return null;
}

From source file:org.springframework.web.servlet.DispatcherServlet.java

/**
 * Return the HandlerExecutionChain for this request.
 * <p>Tries all handler mappings in order.
 * @param request current HTTP request/*  w w  w  .j  a va  2  s. c o  m*/
 * @return the HandlerExecutionChain, or {@code null} if no handler could be found
 */
@Nullable
protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception {
    if (this.handlerMappings != null) {
        for (HandlerMapping hm : this.handlerMappings) {
            if (logger.isTraceEnabled()) {
                logger.trace("Testing handler map [" + hm + "] in DispatcherServlet with name '"
                        + getServletName() + "'");
            }
            HandlerExecutionChain handler = hm.getHandler(request);
            if (handler != null) {
                return handler;
            }
        }
    }
    return null;
}

From source file:org.springframework.web.servlet.SimpleDispatcherServlet.java

/**
 * Return the HandlerExecutionChain for this request. Try all handler mappings in order.
 * @param request current HTTP request//from   w w  w.  ja va  2  s.com
 * @param cache whether to cache the HandlerExecutionChain in a request attribute
 * @return the HandlerExceutionChain, or <code>null</code> if no handler could be found
 */
public HandlerExecutionChain getHandler(HttpServletRequest request, boolean cache) throws Exception {
    HandlerExecutionChain handler = (HandlerExecutionChain) request
            .getAttribute(HANDLER_EXECUTION_CHAIN_ATTRIBUTE);
    if (handler != null) {
        if (!cache) {
            request.removeAttribute(HANDLER_EXECUTION_CHAIN_ATTRIBUTE);
        }
        return handler;
    }

    for (HandlerMapping hm : this.handlerMappings) {
        if (logger.isTraceEnabled()) {
            logger.trace("Testing handler map [" + hm + "] in DispatcherServlet with name '" + getServletName()
                    + "'");
        }
        handler = hm.getHandler(request);
        if (handler != null) {
            if (cache) {
                request.setAttribute(HANDLER_EXECUTION_CHAIN_ATTRIBUTE, handler);
            }
            return handler;
        }
    }
    return null;
}