1

I am trying to figure out what i might be missing here.

I have a Servlet TestServlet which is ,

Smalltalk defineClass: #TestServlet
    superclass: #{VisualWave.HttpServlet}
    indexedType: #none
    private: false
    instanceVariableNames: ''
    classInstanceVariableNames: ''
    imports: ''
    category: ''

with method for get:

doGet: aRequest response: aResponse

    aResponse write: aRequest session key

Now with this i run a workspace code

client := HttpClient new.
    Transcript
        show: (client executeRequest: (HttpRequest
                            get: 'http://localhost:8008/servlet/TestServlet'))
                    value value;
        cr.
    Transcript
        show: (client executeRequest: (HttpRequest
                            get: 'http://localhost:8008/servlet/TestServlet'))
                    value value;
        cr.
    Transcript
        show: (client executeRequest: (HttpRequest
                            get: 'http://localhost:8008/servlet/TestServlet'))
                    value value;
        cr.
    Transcript
        show: (client executeRequest: (HttpRequest
                            get: 'http://localhost:8008/servlet/TestServlet'))
                    value value;
        cr

Here every 3rd request gets be a different session key.

When i debugged i found that in the method Response => setSessionKey webRequest wont have a cookie named cookieName , so it will set the cookie. Later in the second request webRequest have a cookie name and so it wont set the cookie.So the next (third) request will initiate a new session and since it wont have cookieName in webRequest , it will set the cookieName with the new session key which will remain in the fourth session too.

Is this expected behavior and so am i missing something? Or can it be done in a different way so that this behavior wont happen?

setSessionKey

    self session
        ifNotNil: 
            [| cookieName |
            cookieName := webRequest webSite sessionCookieName.
            (webRequest cookieValueAt: cookieName)
                ifNil: [self cookieAt: cookieName put: self session key]]

Looking forward for smalltalk gurus to help me here.

Thanks in Advance.

PS: I know we can set the session cookie to the response , but i am looking for a different solution or may be a more correct one. Also i would like to get the reason why this happens.Thanks.

Thushar G R
  • 1,017
  • 9
  • 24

0 Answers0