Bug 33058 - Request session null after chain.doFilter() in Filter class
Summary: Request session null after chain.doFilter() in Filter class
Status: RESOLVED INVALID
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: 5.5.4
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL: http://www.vincebloise.info/bfg.war
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-12 10:46 UTC by Vince Bloise
Modified: 2005-01-14 01:44 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vince Bloise 2005-01-12 10:46:38 UTC
In processing the filter chain in a class that implements the Filter 
interface, the request parameter has a null session and nulled out parameters. 
This only happens after the first use of the filter. The first time the filter 
is executed the session is populated and everything works.
Comment 1 Remy Maucherat 2005-01-12 11:02:23 UTC
I don't understand what your problem is. Please submit a ready to test war.
Comment 2 Vince Bloise 2005-01-13 15:01:28 UTC
The linked war file (http://www.vincebloise.info/bfg.war) contains the source 
as well as class files. Please run the application and notice how the Filter 
implementation request has a null session when filtering from the main.jsp 
page.

The application asks for a user id and password, but it will take anything in 
these fields.
Comment 3 Remy Maucherat 2005-01-13 15:03:42 UTC
I cannot access your test case. Please attach it to the bug report (it's quite
easy to do).
Comment 4 Remy Maucherat 2005-01-13 18:22:27 UTC
I got the "test case" (which is an anything but minimal JSF-Struts webapp :( ;
this is not a user support forum, and we don't do
find-whatever-is-wrong-in-your-webapp work), and I still do not understand what
the problem could be. Please state clearly what the problem is.

Overall, I doubt there's a bug with session handling.
Comment 5 Vince Bloise 2005-01-13 19:01:05 UTC
(In reply to comment #4)
> I got the "test case" (which is an anything but minimal JSF-Struts webapp :( ;
> this is not a user support forum, and we don't do
> find-whatever-is-wrong-in-your-webapp work), and I still do not understand 
what
> the problem could be. Please state clearly what the problem is.
> Overall, I doubt there's a bug with session handling.

(In reply)
The problem:

An object is placed in the session scope via HttpSession = request.getSession() 
session.setAttribute(...) in a servlet. That servlet then forwards the request 
to a JSP page in a directory that is monitored by a filter servlet. The filter 
servlet attempts to retrieve the session attribute from the request via 
session.getSessionAttribute(...) and finds that the request's session has all 
its attributes set to null.
Comment 6 Remy Maucherat 2005-01-13 19:07:48 UTC
Then, this works for me. Please do not reopen the report.
Comment 7 Allistair Crossley 2005-01-14 10:44:13 UTC
i have also tried this out for you. i wrote 1 basic servlet that acquired the 
session and added a String attribute, 1 basic filter that attempted to acquire 
that attribute from the session, and 1 jsp that was forwarded to using a 
RequestDispatcher from the basic servlet after the session attribute was added. 
this was configured in web.xml with a filter-mapping using a url-pattern for 
the location of the jsp, i.e /tests/33058.jsp. the jsp also tries to output the 
session attribute.

test 1 revealed that the filter is not even touched when the basic servlet is 
requested. the jsp is arrived at however, and does output the correct session 
attribute.

i consulted the servlet 2.4 specification and found that in 2.4 you add an 
element called "dispatcher" to the filter-mapping so that RequestDispatchers 
work with the url-pattern (section 6.2.5)

i change the filter-mapping to 

<filter-mapping>
  <filter-name>Basic Filter</filter-name>
  <url-pattern>/views/test/*</url-pattern>
  <dispatcher>FORWARD</dispatcher>
</filter-mapping>

running this test reveals that the filter _can_ access the session value:

String myAttribute = (String) ((HttpServletRequest) request).
  getSession().getAttribute("myAttribute");

hope this helps.