Example usage for org.springframework.web.servlet.mvc.method.annotation ServletInvocableHandlerMethod setHandlerMethodArgumentResolvers

List of usage examples for org.springframework.web.servlet.mvc.method.annotation ServletInvocableHandlerMethod setHandlerMethodArgumentResolvers

Introduction

In this page you can find the example usage for org.springframework.web.servlet.mvc.method.annotation ServletInvocableHandlerMethod setHandlerMethodArgumentResolvers.

Prototype

public void setHandlerMethodArgumentResolvers(HandlerMethodArgumentResolverComposite argumentResolvers) 

Source Link

Document

Set HandlerMethodArgumentResolver HandlerMethodArgumentResolvers to use to use for resolving method argument values.

Usage

From source file:org.fao.geonet.kernel.SpringLocalServiceInvoker.java

public Object invoke(HttpServletRequest request, HttpServletResponse response) throws Exception {

    HandlerExecutionChain handlerExecutionChain = requestMappingHandlerMapping.getHandler(request);
    HandlerMethod handlerMethod = (HandlerMethod) handlerExecutionChain.getHandler();

    ServletInvocableHandlerMethod servletInvocableHandlerMethod = new ServletInvocableHandlerMethod(
            handlerMethod);/*www  .j a  va 2s .c  o m*/
    servletInvocableHandlerMethod.setHandlerMethodArgumentResolvers(argumentResolvers);
    servletInvocableHandlerMethod.setHandlerMethodReturnValueHandlers(returnValueHandlers);
    servletInvocableHandlerMethod.setDataBinderFactory(webDataBinderFactory);

    Object o = servletInvocableHandlerMethod.invokeForRequest(new ServletWebRequest(request, response), null,
            new Object[0]);
    // check whether we need to further process a "forward:" response
    if (o instanceof String) {
        String checkForward = (String) o;
        if (checkForward.startsWith("forward:")) {
            //
            // if the original url ends with the first component of the fwd url, then concatenate them, otherwise
            // just invoke it and hope for the best...
            // eg. local://srv/api/records/urn:marlin.csiro.au:org:1_organisation_name
            // returns forward:urn:marlin.csiro.au:org:1_organisation_name/formatters/xml
            // so we join the original url and the forwarded url as:
            // /api/records/urn:marlin.csiro.au:org:1_organisation_name/formatters/xml and invoke it.
            //
            String fwdUrl = StringUtils.substringAfter(checkForward, "forward:");
            String lastComponent = StringUtils.substringAfterLast(request.getRequestURI(), "/");
            if (lastComponent.length() > 0 && StringUtils.startsWith(fwdUrl, lastComponent)) {
                return invoke(request.getRequestURI() + StringUtils.substringAfter(fwdUrl, lastComponent));
            } else {
                return invoke(fwdUrl);
            }
        }
    }
    return o;
}