• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpSession problem when client on same server

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rodger Donaphon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The real application needs the servlet to maintain session variables. The example code with the 'count' session variable is just for troubleshooting purposes.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly how is this "client program" accessing the servlet? What does the client program do to preserve cookies?


Bill
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But you really haven't answered the question. Why do you care if the session is new or not?
 
Saloon Keeper
Posts: 27807
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rodger Donaphon
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic