twarne / xebia-france

Automatically exported from code.google.com/p/xebia-france
0 stars 0 forks source link

fr.xebia.servlet.filter.XForwardedFilter.matchesOne(XForwardedFilter.java:654) #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.add xebia-servlet-extras-1.0.2.jar 0r xebia-servlet-extras-1.0.3.jar
 to war folder
2. add filter entry in web.xml
3. run the application

What is the expected output? What do you see instead?

It should not throw java.lang.NullPointerException

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

xebia-servlet-extras-1.0.2.jar 0r xebia-servlet-extras-1.0.3.jar
with
jdk 1.6
on windows xp
Please provide any additional information below.
I did little search and found that"In the 1.4.2 version of the jdk/jre it would 
allow you to use null as the parameter of java.util.regex.Pattern::matcher( 
String ).  In jdk/jre 1.5 or above it throws a NullPointerException"
Error Log**********************

org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet ViewRendererServlet threw exception
java.lang.NullPointerException
    at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
    at java.util.regex.Matcher.reset(Matcher.java:291)
    at java.util.regex.Matcher.<init>(Matcher.java:211)
    at java.util.regex.Pattern.matcher(Pattern.java:888)
    at fr.xebia.servlet.filter.XForwardedFilter.matchesOne(XForwardedFilter.java:654)
    at fr.xebia.servlet.filter.XForwardedFilter.doFilter(XForwardedFilter.java:705)
    at fr.xebia.servlet.filter.XForwardedFilter.doFilter(XForwardedFilter.java:790)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

Original issue reported on code.google.com by ranjansu...@gmail.com on 14 Feb 2011 at 1:52

GoogleCodeExporter commented 9 years ago
Exception comming only when used with all dispatcher element like

<filter-mapping>
            <filter-name>XForwardedFilter</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
                    <dispatcher>FORWARD</dispatcher>
                    <dispatcher>INCLUDE</dispatcher>
                    <dispatcher>ERROR</dispatcher>
      </filter-mapping>
Changed filter-mapping element to 

<filter-mapping>
         <filter-name>XForwardedFilter</filter-name>
         <url-pattern>/*</url-pattern>
         <dispatcher>REQUEST</dispatcher>
</filter-mapping>
will resolve it.

Original comment by ranjansu...@gmail.com on 15 Feb 2011 at 6:10

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The method "request.getRemoteAddr()" returned "null" instead of "a String 
containing the IP address of the client that sent the request" (1).

Can you attach the full stacktrace to ease understanding this behavior. I see 
two scenarios :
 * a FORWARD or INCLUDE or ERROR dispatcher returns 'null',
 * a custom filter returns null.

The normal usage should be to only associate the XForwardedFilter with the 
REQUEST dispatcher.

(1) 
http://download.oracle.com/javaee/5/api/javax/servlet/ServletRequest.html#getRem
oteAddr()

Original comment by cyrille....@gmail.com on 21 Feb 2011 at 10:24

GoogleCodeExporter commented 9 years ago
stacktrace attached.

Original comment by ranjansu...@gmail.com on 23 Feb 2011 at 1:13

Attachments:

GoogleCodeExporter commented 9 years ago
Can you enable "fr.xebia.servlet.filter.XForwardedFilter" logs to see what 
remoteAddr is set by the last XForwardedForFilter execution that does not break 
(1) ?

The important information is the "newRemoteAddr" of the debug line :
 "Incoming request ... will be seen as newRemoteAddr='...' ..."

1 : 
http://code.google.com/p/xebia-france/issues/attachmentText?id=7&aid=-7830560026
493920097&name=stacktrace.txt&token=6f8311008b3dcdc5124b209eb17d4563#29

Original comment by cyrille....@gmail.com on 3 Mar 2011 at 12:31

GoogleCodeExporter commented 9 years ago
we are fine with only Dispatcher type "Request" which is not throwing any 
error.But the major isssue is that it still not providing the correct Remote 
IP.Is it possible to get the correct remote IP within a company network.
We tried with RemoteIpValve,XForwardedFilter.

Debug Log:
16:44:45,390 DEBUG [XForwardedFilter:769] Incoming request /c/portal/layout 
with originalRemoteAddr '127.0.0.1', originalRemoteHost='127.0.0.1', 
originalSecure='false', originalScheme='http', original[X-Forwarded-For]='null, 
original[null]='null'
will be seen as newRemoteAddr='127.0.0.1', newRemoteHost='127.0.0.1', 
newScheme='http', newSecure='false', new[X-Forwarded-For]='null, 
new[X-Forwarded-By]='null'

Original comment by ranjansu...@gmail.com on 3 Mar 2011 at 11:38

GoogleCodeExporter commented 9 years ago
Reason why you don't have the correct remote ip address : the header 
X-Forwarded-For is missing in the request ("original[X-Forwarded-For]='null'").

What is the layer in front of your java servlet container ? 
apache+mod_proxy_http ?

Original comment by cyrille....@gmail.com on 3 Mar 2011 at 3:32

GoogleCodeExporter commented 9 years ago
Thanks a lot. I will work on this hint.

In testing environment its Liferay 6 + tomcat-6.0.29 only.

Original comment by ranjansu...@gmail.com on 7 Mar 2011 at 5:35