Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with stateful service

 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I was trying an example from Ivan Krizsan tutorial to maintain stateful session between requests, but HttpServletRequest is always null when I try to extract it from MessageContext.
This is client :


This is service :




and unfortunately the exception stack trace :


Why I cannot retrieve the HttpServletRequest object ?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
There is indeed an error in the example in the study notes, but somehow you seem to have figured it out anyway.
The error is that the printNumber() method in the service endpoint implementation class is annotated with @Oneway. This way, the HTTP response will be closed before the printNumber method is entered and thus no HTTP session will be created (exception will occur).

To make sure that the operation becomes a request-response operation, you can add "throws Exception" to the method declaration.

Also note that the example says that you also are supposed to call the printHTTPSessionID() method from the add() method - this to see that invocations of different operations happens within one and the same session.
Hope this solves your problems!
 
Goran Markovic
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, however thanks on yours suggestions about this issue.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I just want to add that I used the exact code that you posted above, developing the web service and client. Then I deployed the web service to GlassFish 2.1 and everything worked as it is supposed to.
If you still have problems, what are you deploying the web service to? Have you made any modifications to the default configuration of the container?
Best wishes!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic