This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session management in web services

 
ramesh agarwal
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic