Many requests may share the same Filter instance, so having instance
variables to store the state of a request is a bad idea. You should look at
re-coding your Filter to remove any instance variables.

Andy

-----Original Message-----
From: Bradley Beddoes [mailto:[EMAIL PROTECTED] 
Sent: 28 October 2003 09:55
To: Tomcat Users List
Subject: RE: Servlet.Service() NullPointer on Filter - Really need some he
lp on this one...


Hi Andy,
I was considering that also however the req and res objects are specified
as private members of the overall class that has been created (extends
filter obviously) and i would have assumed that each request would
instatiate a new object.

Certainly willing to try them as local variables if you think that may
help.

cheers,
Bradley

> Where are your req and res variables defined? They should be
> local to the doFilter() method or you could get concurrency
> issues.
> 
> Andy
> 
> -----Original Message-----
> From: Bradley Beddoes [mailto:[EMAIL PROTECTED] 
> Sent: 28 October 2003 07:50
> To: [EMAIL PROTECTED]
> Subject: Servlet.Service() NullPointer on Filter - Really need
> some help on this one...
> 
> 
> Hi All,
> I am hoping that someone is able to assist with some problems I
> am currently having with a filter I have written. The filter is
> designed to deal with authentication for users to check they have
> a particular cookie set then place an object into the session for
> further use. I have researched this error extensively online and
> can't find any documentation on correcting it.
> 
> The error presented below only occurs on around 12% of requests
> (sometimes a few percent either side of this) according to my
> profiler when the code is put under some load - I am wondering if
> it may be caused by some form of concurrent request error in the
> filters whereby the Servlet object is being reset or otherwise
> nulled out.
> 
> The codebase looks like:
> public void doFilter( ServletRequest request, ServletResponse
> response, FilterChain chain )throws IOException, ServletException
>     {
>         try
>         {
>             req = (HttpServletRequest)request;
>             res = (HttpServletResponse)response;
> 
>             ......
> 
>             //Create Session object
>             HttpSession session = req.getSession( true );
>             session.setAttribute( QutClientObject.NAME,
> qutClient );
>             sessionCreated = true;
> 
>             //set REMOTE_USER
>     
> res.addHeader("REMOTE_USER",qutClient.getUserName());
> 
>               // Filter chaining completed, move to next filter
> in chain
>             chain.doFilter( request, response );
> 
>             return;
>                  }
>          }
> 
> Error occurs on line: req.getSession( true );
> 
> The error from tomcat(both 4.1.24 and 4.1.27) is: 
> 
> 2003-10-28 17:35:35 StandardWrapperValve[jsp]: Servlet.service()
> for servlet jsp threw exception
> java.lang.NullPointerException
>         at
> org.apache.coyote.tomcat4.CoyoteRequestFacade.getSession(CoyoteRe
> questFacade .java:365)
>         at
> au.edu.qut.jauth.client.JAuthFilter.doFilter(JAuthFilter.java:197
> )
>         at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
> Application FilterChain.java:213)
>         at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicat
> ionFilterCh ain.java:193)
>         at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrap
> perValve.ja va:256)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveCo
> ntext.invok eNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline
> .java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
> 995)
>         at
> org.apache.catalina.core.StandardContextValve.invoke(StandardCont
> extValve.ja va:191)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveCo
> ntext.invok eNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline
> .java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
> 995)
>         at
> org.apache.catalina.core.StandardContext.invoke(StandardContext.j
> ava:2416)
>         at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostVal
> ve.java:180 )
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveCo
> ntext.invok eNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispa
> tcherValve. java:171)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveCo
> ntext.invok eNext(StandardPipeline.java:641)
>         at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportVal
> ve.java:172 )
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveCo
> ntext.invok eNext(StandardPipeline.java:641)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline
> .java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
> 995)
>         at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngin
> eValve.java :174)
>         at
> org.apache.catalina.core.StandardPipeline$StandardPipelineValveCo
> ntext.invok eNext(StandardPipeline.java:643)
>         at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline
> .java:480)
>         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:
> 995)
>         at
> org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.jav
> a:223)
>         at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.
> java:601)
>         at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.p
> rocessConne ction(Http11Protocol.java:392)
>         at
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.
> java:565)
>         at
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Thr
> eadPool.jav a:619)
>         at java.lang.Thread.run(Thread.java:534)
> 
> 
> Any help would be very much appreciated I am almost out of ideas
> for this one...
> 
> cheers,
> Bradley.
> 
> 
> 
> 
> -----------------------------------------------------------------
> ---- To unsubscribe, e-mail:
>[EMAIL PROTECTED] For additional
> commands, e-mail: [EMAIL PROTECTED]
> 
> -----------------------------------------------------------------
> ---- To unsubscribe, e-mail:
>[EMAIL PROTECTED] For additional
> commands, e-mail: [EMAIL PROTECTED]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to