aspose file tools*
The moose likes Tomcat and the fly likes HttpSession problem when client on same server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "HttpSession problem when client on same server" Watch "HttpSession problem when client on same server" New topic
Author

HttpSession problem when client on same server

Rodger Donaphon
Greenhorn

Joined: Jan 23, 2009
Posts: 4
In my application, a java client program is accessing a servlet. Debugging the servlet I discovered that HttpSession.isNew() always returns TRUE when the client is on the same host as the servlet. The servlet returns XML data. The client is treating the servlet as an InputStream.

It works OK when the client is on a different machine, like my desktop PC. I access the servlet using a fully qualified domain name, but it is locally resolved. The final domain name is TBD and not yet on a DNS server.

I started using Tomcat5. Upgraded to Tomcat 6. No improvement.

According to my research, my problem can occur if the client refuses to accept the session. Not sure what that means. I tried using the HttpClient library, but it did not help.

For debugging, this is a BIG problem since all develop and unit test are on the same server.

To isolate the problem I am using the following simple test. processRequest simply returns the value of 'count'. Normally, it should increment each time the servlet is accessed. But when the client is on the same machine as Tomcat, it is stuck at 1 because httpSession.isNew() is always returning TRUE.



Any input would be appreciated.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Why do you care whether the session is new or not? Sounds like you might be trying to use the session lifecycle in an inappropriate manner.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rodger Donaphon
Greenhorn

Joined: Jan 23, 2009
Posts: 4
The real application needs the servlet to maintain session variables. The example code with the 'count' session variable is just for troubleshooting purposes.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12821
    
    5
Exactly how is this "client program" accessing the servlet? What does the client program do to preserve cookies?


Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

But you really haven't answered the question. Why do you care if the session is new or not?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16228
    
  21

Bear Bibeault wrote:But you really haven't answered the question. Why do you care if the session is new or not?


Huh? Because if the session is new, the session variables set in earlier requests aren't going to be there. It will be a blank session.

It sounds like one of 2 possibilities, neither of which actually depends on whether or not the client and server are on the same machine:

1. The failing client has cookies disabled and there's no URL rewriting in effect, so there's no place to pass the session ID back and forth between client and server. Since all HTTP requests are "one-off" with no enduring connection, there's no other way to keep the session identity in sync.

2. The client is doing low-level "brute force" HTTP. The HttpURLConnection can automatically handle cookies, but straight do-it-yourself network read/write logic would only handle the cookies with the session ID in them if the client implemented the low-level cookie logic explicitly.


Customer surveys are for companies who didn't pay proper attention to begin with.
Rodger Donaphon
Greenhorn

Joined: Jan 23, 2009
Posts: 4
Thanks for your input.

The problem is that I did not understand how cookies are used to maintain session.

Once I added code to save the JSESSION cookie and put it in subsequent requests, the problem went away.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpSession problem when client on same server