Re: new session on each request
Re: new session on each request
- Subject: Re: new session on each request
- From: Chuck Hill <email@hidden>
- Date: Thu, 24 Jan 2008 13:19:39 -0800
Hi Zak,
On Jan 24, 2008, at 1:12 PM, Zak Burke wrote:
On Jan 24, 2008, at 3:15 PM, Chuck Hill wrote:
On Jan 24, 2008, at 10:40 AM, Zak Burke wrote:
I'm going a little bit mad here. I am working on a new app and
cannot get session management to work correctly. Requests to the
root of the app (.../simple.woa) generate new sessions; requests
generated from within the app (submitting a form) reuse existing
sessions. I must have some basic setting goofed up, but I cannot
figure out what it is.
Mmmmm. Is _is_ how session management is supposed to work.
I am running MacOS 10.4.x; Apache 1.3; WO 5.3; Eclipse 3.3.1.1;
WOLips 3.3.4763.
I have simplified this to the point of creating a brand new
WebObjects Application from the "File > New..." menu and doing
nothing but adding some debugging to Application.java, telling
Session.java to store info in cookies and overriding
domainForIDCookies to return "/",
And that changes things WRT session handling. OK, now I see the
problem. :-)
Besides, the same cookie is correctly read in requests two and
three, when the session is restored.
Any ideas? I'm totally stumped.
What is the default action requestion handler, component or direct
action? That stack trace may show you where this is happening.
It's a component -- Main.wo. This is literally just a straight up
default application as created by the "New WebObjects
Application..." wizard. The stacktrace does show where I'm getting
a new session, but what I don't understand is WHY. Here is my
current Application.dispatchRequest:
public WOResponse dispatchRequest(WORequest r) {
NSLog.out.appendln("REQUEST COOKIES: " + r.cookies());
NSLog.out.appendln("isSessionIDInRequest: " +
r.isSessionIDInRequest());
NSLog.out.appendln("sessionID: " + r.sessionID());
WOResponse response = super.dispatchRequest(r);
NSLog.out.appendln("RESPONSE COOKIES: " + response.cookies());
NSLog.out.appendln("\n\n");
return response;
}
The logs with that shows the sessionID is available in
dispatchRequest and that it looks like the new session is being
generated by Application._initializeSessionInContext. When I
override that as follows:
public WOSession _initializeSessionInContext(WOContext context) {
WORequest r = context.request();
NSLog.out.appendln
("_initializeSessionInContext.isSessionIDInRequest: " +
r.isSessionIDInRequest());
NSLog.out.appendln("_initializeSessionInContext.sessionID: " +
r.sessionID());
return super._initializeSessionInContext(context);
}
I get the following:
REQUEST COOKIES: (<com.webobjects.appserver.WOCookie name=woinst
value=("-1") path=null domain=null isSecure=false>,
<com.webobjects.appserver.WOCookie name=wosid value=
("6gIdXD0e75cWKpZWlkCGAM") path=null domain=null isSecure=false>)
isSessionIDInRequest: true
sessionID: 6gIdXD0e75cWKpZWlkCGAM
_initializeSessionInContext.isSessionIDInRequest: true
_initializeSessionInContext.sessionID: 6gIdXD0e75cWKpZWlkCGAM
Initialized session 2: q1KLEMrOi9scsTfIe6l7f0
java.lang.RuntimeException: Session created here
at your.app.Session.<init>(Session.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at java.lang.Class.newInstance0(Class.java:350)
at java.lang.Class.newInstance(Class.java:303)
at com.webobjects.foundation._NSUtilities.instantiateObject
(_NSUtilities.java:577)
at com.webobjects.appserver.WOApplication.createSessionForRequest
(WOApplication.java:1611)
at
com.webobjects.appserver.WOApplication._initializeSessionInContext
(WOApplication.java:1752)
at your.app.Application._initializeSessionInContext
(Application.java:64)
at
com.webobjects.appserver._private.WOComponentRequestHandler._dispatchW
ithPreparedApplication(WOComponentRequestHandler.java:309)
at
com.webobjects.appserver._private.WOComponentRequestHandler._handleReq
uest(WOComponentRequestHandler.java:358)
at
com.webobjects.appserver._private.WOComponentRequestHandler.handleRequ
est(WOComponentRequestHandler.java:435)
at com.webobjects.appserver.WOApplication.dispatchRequest
(WOApplication.java:1306)
at your.app.Application.dispatchRequest(Application.java:77)
at com.webobjects.appserver._private.WOWorkerThread.runOnce
(WOWorkerThread.java:173)
at com.webobjects.appserver._private.WOWorkerThread.run
(WOWorkerThread.java:254)
at java.lang.Thread.run(Thread.java:613)
Huh? Both dispatchRequest and _initializeSessionInContext report
the same sessionID. If we already have a sessionID, why is
_initializeSessionInContext calling createSessionForRequest?
I can't help but feel there is some trivial but arcane setting that
I have botched, but I can't for the life of me figure out what it
might be.
I am too lazy to look it up, but I'd guess that the component action
request handler creates a new session based on the URL without
looking at the cookies. Try adding this to the application constructor:
setDefaultRequestHandler(requestHandlerForKey
(directActionRequestHandlerKey()));
Make sure that DirectAction.java has something like this:
public WOActionResults defaultAction() {
return pageWithName(Main.class.getName());
}
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden