File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes How to implement Stateful webservices? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "How to implement Stateful webservices?" Watch "How to implement Stateful webservices?" New topic
Author

How to implement Stateful webservices?

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 518
    
    2

Hi All,

I was reading through an article on www.java.net on how to implement the state across multiple conversations with webservices.

My initial understanding was ws-addressing combined with ws-reliablemessaging provides a very good support of session management. Please correct me If I'm wrong here.

and certain annotations like @Stateful can be used along with StatefulWebServiceManager also support session management.

Now out of these various methods, the one presented in java.net seem to be very simple. But can some one guide me, which of the above options are actually correct and usable and if yes, any justification of each.

Also, apart from the above, are there any other ways of managing sessions. Also, I see that Ivan's notes which talks about the session management in chapter 4 (JAX-WS) resembles the one posted in the java.net article. Is this the widely adopted process ?


Regards
KumarRaja

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Managing state with a web service means that some data that should have been stored in the requests is stored on the web service side. Commonly, but not always, statefulness is used due to a design flaw.
Stateful example:
When client A sends its first request to a stateful web service, the state is established and for every subsequent request from client A, the web service retains the state associated with client A.
Compare this to patients going to see the doctor. Statelessness is a patient going to see the doctor at a big hospital; the patient cannot choose which doctor to see, but sees a random doctor each time.
Statefulness is a patient going to see a specific doctor - the patient returns to the same clinic each visit and sees the same doctor.

I cannot see how WS-Addressing and WS-ReliableMessaging would be able to facilitate stateful web services.

Also, as far as I know, @Stateful is used to annotate a stateful session bean and in section 3.2.4 of the EJB 3.1 specification it says:
Stateless session beans and Singleton session beans may have web service clients.

Thus you cannot expose a stateful session beans as a web service.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3211
    
    6
Ivan Krizsan wrote:
Also, as far as I know, @Stateful is used to annotate a stateful session bean and in section 3.2.4 of the EJB 3.1 specification it says:
Stateless session beans and Singleton session beans may have web service clients.

Thus you cannot expose a stateful session beans as a web service.


I guess, above was mentioned [probably] another @Stateful annotation:
http://www.docjar.com/docs/api/com/sun/xml/internal/ws/developer/Stateful.html
But it's not part of JAX-WS, and is not portable (and not tested on the exam )


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Mikalai Zaikin wrote:
I guess, above was mentioned [probably] another @Stateful annotation:
http://www.docjar.com/docs/api/com/sun/xml/internal/ws/developer/Stateful.html
But it's not part of JAX-WS, and is not portable (and not tested on the exam )

Ah, thanks for pointing this out!
Best wishes!
Tom mmeke
Greenhorn

Joined: Jul 19, 2011
Posts: 10

Kumar Raja wrote:
Also, apart from the above, are there any other ways of managing sessions.


You could extract the HTTPSESSION in your webservice.



When you first call this method you'll receive a response with a "Set-Cookie" parameter in its header.
Copy this value, paste it in the "Cookie" header in your next request, and tataaaa ... counter is 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to implement Stateful webservices?