users@jax-ws.java.net

Re: FW: stateful behavior of web service implementing Provider<Source>

From: Peter Hendry <peter.hendry_at_capeclear.com>
Date: Wed, 18 Apr 2007 01:11:05 +1200
By default one instance of the service class is created and receives all requests. This is what you are seeing. This is because the InstanceResolver (com.sun.xml.ws.api.server.InstanceResolver) used is the SingletonResolver. This creates one instance and returns that same instance each time an instance is requested. This is the only model put forward by the JAX-WS spec I think.

To change the implementation of InstanceResolver used you need to create an annotation that in turn has the @InstanceResolverAnnotation on it with the new InstanceResolver class as its value. You then use this new annotation on your SEI class.

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@InstanceResolverAnnotation(value=PerRequestInstanceResolver.class)
public @interface PerRequestPolicyAnnotation {
}

On your SEI class you then have

@WebService(...)
@PerRequestPolicyAnnotation
public class .... {

Attached is an implementation of a resolver that creates a new instance for each request - I think what you want. There are also resolvers supplied in the RI that work on Cookies and HTTP sessions.

Drop the attached jar into your server's lib dir (shared/lib on tomcat for example - the same place the jaxws jars live). Then you can use the @PerRequestPolicyAnnotation on your service classes. The jar also includes the source code so you can change the package or whatever.

Pete


Sajit - SDTPL wrote:
Message
Hi,
 
We eagerly await a response to understand that the behavior we experience is not unusual and we can consider this when we design and develop our solution further.
 
In case there is a need to provide with an example to explain what we mean, do let us know and we shall forward the same immediately.
 

Thanks and Regards,

Sajit

------------------------------------------------------------------------------------------------------------------

-----Original Message-----
From: Sajit - SDTPL [mailto:sajit.dayanandan@stpdomain.com]
Sent: Saturday, April 14, 2007 4:43 PM
To: users@jax-ws.dev.java.net
Subject: stateful behavior of web service implementing Provider<Source>

Hi,
 
We are developing Web Services implementing Provider<Source>.
 
We notice that these Web Services maintains its state across service requests. This was noticed when we realized that the constructor associated to the class implementing this Web Service was being invoked only once (whenever GlassFish is being started or at the time of Web Service deployment). The constructor had code to initialize the fields in this Class, some of which were also being populated from an SQL database.
 
Is this behavior to maintain the state across multiple client service requests correct (and as expected)? Can we assume that this would be supported in the final / subsequent releases of JAX-WS. I would hasten to add that this is a good feature to have for our application, as we would be happy to avoid accessing the database for every request that is being received by the Web Service :-).
 
I hope my query is clear and we look forward to your response.... In case of trouble in understanding our concern, do let us know and we shall respond with an example explaining the experience better.
 
 
Note that we are using GlassFish v2b41 and nightly build of JAX-WS 2.1.
 
Thanks and Regards,

Sajit

------------------------------------------------------------------------------------------------------------------