kenny-hybris / urlrewritefilter

Automatically exported from code.google.com/p/urlrewritefilter
Other
0 stars 0 forks source link

isfilewithsize never worked! #179

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. <condition type="request-filename" operator="isfilewithsize"/>

What is the expected output? What do you see instead?
    <rule>
       <condition type="request-filename" operator="notfile"/>
       <from>/\d+\.html</from>
       <to>/index.jsp?$1</to>
    </rule>

when visit 1.html which exist it should be 1.html;
when visit 789.html which doesn't exist it should be index.jsp?798. But the 
result is 1.html or 404 page. Other operators don't work either, such as 
isfile, isfilewithsize, notfilewithsize.

What version of the product are you using? On what operating system?
4.0.3

Please provide any additional information below.

Original issue reported on code.google.com by i@luda.me on 31 Dec 2014 at 9:28

GoogleCodeExporter commented 9 years ago
In Condition.java, about line 265:

> String fileName = 
rule.getServletContext().getRealPath(hsRequest.getRequestURI);

If the app is deployed with contextpath "/test", the value of 
hsRequest.getRequestURI() will be "/test/filename.txt".

Then, the var fileName will be "/home/path/test/test/filename.txt", but it 
should be "/home/path/test/filename.txt". The key is that requestURI contains 
contextpath. 

In mapper of request, there is an attribute of mappingData named "requestPath", 
which doesn't contain contextpath info. Unfortunately, this attribute can't be 
read from request instance. So, I try to fix this like bellow:

                  String contextPath = rule.getServletContext().getContextPath(); // may be "/", "", or "/test"

                    if( contextPath != null){
                        contextPath = contextPath.replaceAll("^/", "");
                    }

                    String requestURI = hsRequest.getRequestURI();
                    requestURI = requestURI.replaceAll("^/"+contextPath, "");

                    String fileName = rule.getServletContext().getRealPath(requestURI);

And it works, that's all.

Original comment by i@luda.me on 31 Dec 2014 at 3:22

GoogleCodeExporter commented 9 years ago
btw, get the original uri:

> String originalUri = 
request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);

or with el:

> Original URI: ${requestScope['javax.servlet.forward.request_uri']}

get the full query path:

String queryPart = request.getQueryString() == null "" : 
"?"+request.getQueryString();
String fullQueryPath = originalUri + queryPart;    // or requestURI + queryPart;

Original comment by i@luda.me on 31 Dec 2014 at 3:39