|
Home > Archive > WebSphere HTTP Server > January 2004 > Re: java.lang.IllegalStateException: Context has not been prepared
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: java.lang.IllegalStateException: Context has not been prepared
|
|
| Todd Kaplinger 2004-01-19, 8:21 am |
| Are you possibly storing the request object in an instance variable?
Anony wrote:quote:
>
> I am using:
>
> IBM Websphere 4.0.5 on HP-UX
> IBM HTTP Server 2.0.x on HP-UX
> Internet Explorer 6.0 SP1
> HTTPS (SSL)
>
>
> What would cause this exception?
>
>
> java.lang.IllegalStateException: Context has not been prepared for next
> connection at
> com.ibm.servlet.engine.srt.NilSRPConnection.getCookieValue(SRTConnectionContext.java:394)
> at
> com.ibm.servlet.engine.srt.SRTSessionAPISupport. getRequestedSessionId(SRTSessionAPISuppo
rt.java:131)
> at
> com.ibm.servlet.engine.srt.SRTSessionAPISupport.getSession(SRTSessionAPISupport.java:405)
> at
> com.ibm.servlet.engine.webapp.HttpServletRequestProxy.getSession(HttpServletRequestProxy.java:105)
> at
> com.foobar.MyServletRequest.getSession(MyServletRequest.java:82)com.foobar.ControlServlet.doPost(ControlServlet.java:228)
> at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at
> com.ibm.servlet.engine.webapp.StrictServletInstance.doService(ServletManager.java:827)
> at
> com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(StrictLifecycleServlet.java:167)
> at
> com.ibm.servlet.engine.webapp.IdleServletState.service(StrictLifecycleServlet.java:297)
> at
> com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(StrictLifecycleServlet.java:110)
> at
> com.ibm.servlet.engine.webapp.ServletInstance.service(ServletManager.java:472)
> at
> com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(ServletManager.java:1012)
> at
> com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(ServletManager.java:913)
> at
> com.ibm.servlet.engine.webapp.WebAppRequestDispatcher. handleWebAppDispatch(WebAppRequestDispat
cher.java:721)
> at
> com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:374)
> at
> com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:118)
> at
> com.ibm.servlet.engine.srt.WebAppInvoker.doForward(WebAppInvoker.java:134)
> at
> com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:239)
> at
> com.ibm.servlet.engine.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:67)
> at
> com.ibm.servlet.engine.invocation.CacheableInvocationContext.invoke(CacheableInvocationContext.java:106)
> at
> com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:154)
> at
> com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(OSEListener.java:315)
> at
> com.ibm.servlet.engine.http11.HttpConnection.handleRequest(HttpConnection.java:60)
> at
> com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:323)
> at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:252) at
> com.ibm.ws.util.CachedThread.run(ThreadPool.java:138)
>
>
>
| |
|
| Todd Kaplinger wrote:quote:
> Are you possibly storing the request object in an instance variable?
>
Yes, I am.
| |
| Todd Kaplinger 2004-01-19, 8:21 am |
| The scope of the request/response is from the start of the service
method to the end of the service method. You should be passing this
object via parameters to the methods that need access to this object.
Anony wrote:quote:
> Todd Kaplinger wrote:
>
>
> Yes, I am.
>
| |
| Todd Kaplinger 2004-01-19, 8:21 am |
| Also note that storing this object as an instance variable is not
thread-safe since multiple access of this servlet can be occuring at the
same time.
Todd Kaplinger wrote:quote:
> The scope of the request/response is from the start of the service
> method to the end of the service method. You should be passing this
> object via parameters to the methods that need access to this object.
>
> Anony wrote:
>
>
| |
|
|
Kudos to Todd Kaplinger for helping me resolve this issue.
Here's why the exception occurred:
I have two classes, Bar and FooServlet
public class Bar
{
private HttpServletRequest request;
// ...
public HttpServletRequest getHttpServletRequest()
{
// ...
}
}
public class FooServlet extends javax.servlet.http.HttpServlet
{
private Bar b;
// ...
}
The servlet class, FooServlet, is not thread-safe. Each thread
was modifying the variable "b". This was the root cause of
the IllegalStateException.
Generally speaking, it is a bad idea to use instance variables in
a servlet class.
References:
1) http://www.jguru.com/faq/view.jsp?EID=150
2) Java Servlet 2.2 specification:
{{
Multithreading Issues
During the course of servicing requests from clients, a servlet
container may send multiple requests from multiple clients through the
service method of the servlet at any one time. This means that
the Developer must take care to make sure that the servlet is properly
programmed for concurrency.
If a Developer wants to prevent this default behavior, he can program
the servlet to implement the SingleThreadModel interface. Implementing
this interface will guarantee that only one request thread at a time
will be allowed in the service method. A servlet container may satisfy
this guarantee by serializing requests on a servlet or by maintaining a
pool of servlet instances. If the servlet is part of an application that
has been marked as distributable, the container may maintain a pool of
servlet instances in each VM that the application is distributed across.
If a Developer defines a service method (or methods such as doGet or
doPost which are dispatched to from the service method of the
HttpServlet abstract class) with the synchronized keyword, the servlet
container will, by necessity of the underlying Java runtime, serialize
requests through it. However, the container must not create an instance
pool as it does for servlets that implement the SingleThreadModel. It is
strongly recommended that developers not synchronize the service method
or any of the HttpServlet service methods such as doGet, doPost, etc.
}}
Todd Kaplinger wrote:[QUOTE][color=darkred]
>
> Are you possibly storing the request object in an instance variable?
>
>
|
|
|
|
|