public static ActionResult strutsLookup( ServletContext context, ServletRequest request,
HttpServletResponse response, String actionOverride,
String[] autoResolveExtensions )
throws Exception
{
ScopedRequest scopedRequest = ScopedServletUtils.unwrapRequest( request );
ScopedResponse scopedResponse = ScopedServletUtils.unwrapResponse( response );
assert scopedRequest != null : request.getClass().getName();
assert scopedResponse != null : response.getClass().getName();
assert request instanceof HttpServletRequest : request.getClass().getName();
if ( scopedRequest == null )
{
throw new IllegalArgumentException( "request must be of type " + ScopedRequest.class.getName() );
}
if ( scopedResponse == null )
{
throw new IllegalArgumentException( "response must be of type " + ScopedResponse.class.getName() );
}
ActionServlet as = InternalUtils.getActionServlet( context );
if ( actionOverride != null )
{
// The action must be fully-qualified with its module path.
assert actionOverride.charAt( 0 ) == '/' : actionOverride;
InternalStringBuilder uri = new InternalStringBuilder( scopedRequest.getContextPath() );
uri.append( actionOverride );
uri.append( PageFlowConstants.ACTION_EXTENSION );
scopedRequest.setRequestURI( uri.toString() );
}
//
// In case the request was already forwarded once, clear out the recorded forwarded-URI. This
// will allow us to tell whether processing the request actually forwarded somewhere.
//
scopedRequest.setForwardedURI( null );
//
// Now process the request. We create a PageFlowRequestWrapper for pageflow-specific request-scoped info.
//
PageFlowRequestWrapper wrappedRequest = PageFlowRequestWrapper.wrapRequest( ( HttpServletRequest ) request );
wrappedRequest.setScopedLookup( true );
if (as != null)
{
as.doGet( wrappedRequest, scopedResponse ); // this just calls process() -- same as doPost()
}
else
{
// The normal servlet initialization has not completed yet
// so rather than call doGet() directly, aquire the request
// dispatcher from the unwrapped outer request and call
// forward to trigger the servlet initialization.
HttpServletRequest req = scopedRequest.getOuterRequest();
RequestDispatcher rd = req.getRequestDispatcher(scopedRequest.getRequestURI());
rd.forward(wrappedRequest, scopedResponse);
}
String returnURI;
if ( ! scopedResponse.didRedirect() )
{
returnURI = scopedRequest.getForwardedURI();
if ( autoResolveExtensions == null )
{
autoResolveExtensions = DEFAULT_AUTORESOLVE_EXTENSIONS;
}
if ( returnURI != null )
{
for ( int i = 0; i < autoResolveExtensions.length; ++i )
{
if ( FileUtils.uriEndsWith( returnURI, autoResolveExtensions[i] ) )
{
scopedRequest.doForward();
return strutsLookup( context, wrappedRequest, scopedResponse, null, autoResolveExtensions );
}
}
}
}