You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2004/07/13 16:17:12 UTC

DO NOT REPLY [Bug 30075] New: - Struts is using request.getContextPath() to try to generate correct URLs/URIs. This fails if the server is accesed through a proxy.

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=30075>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=30075

Struts is using request.getContextPath() to try to generate correct URLs/URIs.  This fails if the server is accesed through a proxy.

           Summary: Struts is using request.getContextPath() to try to
                    generate correct URLs/URIs.  This fails if the server is
                    accesed through a proxy.
           Product: Struts
           Version: 1.1 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Custom Tags
        AssignedTo: dev@struts.apache.org
        ReportedBy: samshockey@yahoo.com


The struts tags and some other classes are using the getContextPath() method on 
the HttpServletRequest object to try to generate URIs.  This fails as the 
appserver is accessed through a proxy that uses an expanded context.

For Example:
My company uses proxy servers in front of our application servers.  To access a 
web application running on an app server the URL looks like this:
http://www.mycompany.com/jsp/webapp

The /jsp/ part of the context is what the proxy is using to trigger when it 
should proxy to the app servers. The context path that the app server uses is 
just /webapp.  So the URIs that all the struts code generates through the use 
of request.getContextPath() ends up being incorrect and looks 
like:  /webapp/SomeAction.do  Because the URI is prefaced with a / the browser 
interprets the URL as http://www.mycompany.com/webap/SomeAction.do which is 
ends up in a 404.

Suggested Solution:
Make struts configurable as to what the context path generation method should 
be.  Possible options should be: as it is today, relative paths, user supplied 
path.

Stop using the HttpServletRequest getContextPath() method to generate the 
context portion of a URI/URL and instead call a utility method to do this, 
passing in the HttpServletRequest object.  Then check what the setting is and 
return the appropriate context path.  

I have altered the struts code to work in our environment by adding a method to 
the org.apache.struts.util.RequestUtils class

public static String getContextPath(HttpServletRequest request) {
        String value = null;

        if (GENERATE_CONTEXT_PATH == HTTPSERVLETREQUEST)
            value = request.getContextPath();
        else if (GENERATE_CONTEXT_PATH == RELATIVE)
            value = ".";
        else if (GENERATE_CONTEXT_PATH == USERDEFINED)
            value = userDefinedContextPath;

        return value;
    }

Then I did replaced all instance of the HttpServletRequest getContextPath() 
method calls with RequestUtils.getContextPath(reqeust).  We are currently using 
the relative method and this has been working fine so far in testing.  This 
method allows us to either go through the proxies or hit the app servers 
directly.

Following is a list of classes that are using the HttpServletRequest  
getContextPath() that I modified:
org.apache.struts.action.RequestProcessor
org.apache.struts.config.ConfigHelper
org.apache.struts.taglib.bean.IncludeTag
org.apache.struts.taglib.html.ImageTag
org.apache.struts.taglib.html.ImgTag
org.apache.struts.taglib.logic.ForwardTag
org.apache.struts.tiles.ActionComponentServlet
org.apache.struts.upload.MultipartRequestWrapper
org.apache.struts.util.RequestUtils

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org