aspose file tools*
The moose likes Web Services and the fly likes session management in web services Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "session management in web services" Watch "session management in web services" New topic
Author

session management in web services

ramesh agarwal
Greenhorn

Joined: Jun 10, 2008
Posts: 19
In Servlets, we used to say session.setAttribute() and session.getAttribute() to put/get session data, and also had session timeout for prolonged idle time.

Though using sessions in Web Services may not be a good idea, technically is there any container provided way to handle sessions in web services?

What is the associated API?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
First of all, stateful web services are something that is best avoided - it will seriously affect the scalability of your service.

If you despite this want to go down that road, you have the following choices, as far as I know:
1. If your web service endpoint is a servlet based endpoint, you can use the same mechanism as you would use in a servlet:


2. If your web service endpoint is EJB based or if you do not want to use the above mechanism for some other reason.
You can implement your own session mechanism by adding a parameter to the requests in your web service. This new parameter is to identify the session that the client participates in. Session data can be stored in memory, alternatively written to database etc.

Best wishes!
ramesh agarwal
Greenhorn

Joined: Jun 10, 2008
Posts: 19
Ok thanks. Yes, I will try to avoid sessions as it is an anti-pattern for SOA.

1. "Servlet-based" end-point. Is there any Java framework that allows that?

2. I am running JAX-WS examples from Netbeans where plain Java classes are being annotated using @WebService. Can I use sessions in such a scenario.


Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
ramesh agarwal wrote:2. I am running JAX-WS examples from Netbeans where plain Java classes are being annotated using @WebService. Can I use sessions in such a scenario.

Yes. This is a servlet-based endpoint. Unless the class you annotate with @WebService is an EJB, your endpoint is considered to be servlet-based.
Best wishes!
Kanika Sud
Greenhorn

Joined: May 09, 2011
Posts: 21
I need to write code that authenticates a user in a web service by generating some kind of a ticket.
Next, as soon as the user is authenticated, a session should start.

As I am completely new to web services, (all I managed till now is a helloworld service.), I need help with this.... what interfaces to implement and so on...
A small snippet would be extremely helpful...

Thanks in advance,
Kanika.

Kanika Sud
Greenhorn

Joined: May 09, 2011
Posts: 21
more specifically, I am doing this:



And this is the url I am using:
http://localhost:8080/axis/SessionMngmt.jws?method=authenticate&username=wsusr&password=wspwd

The output shows a nul pointer exception
Specifically:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.lang.NullPointerException</faultstring>
<detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">KANIKASUD-PC</ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

What could be wrong?
Any help would be apreciated...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session management in web services