axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Deepal jayasinghe <>
Subject Re: axis2 session scopes
Date Sun, 23 Jan 2011 20:51:51 GMT
The problem is not sending the servicegroupID or the session related
information. When you keep sending request it always create a new
instances, only way to stop is to copy the servicegroupID from the
previous request and send it alone with the next request.

One another way to get this work is try following, then you will see the
expected behavior.

ServiceClient client = new ServiceClient();
Options options = new Options();

If we do the above, you only get one service instances.


> The article describes how to keep session, without needing to reuse
> the same ServiceClient object. I.e. keep session using different
> ServiceClient objects.
> My question was, why is the web service class being re-instantiated
> for each web service invocation for ALL scopes except application.
> I have configured client to manage session (and engaged addressing for
> soapsession) and the web service class keeps-on re-instantiated for
> each web service call. So, I am not having a problem on keeping/using
> session (I am using messageContext and serviceContext for session
> related data).
> I can not understand why the web service class is re-instantiated.
> Is this a bug in Axis2? If not, what is the logic for this? I think
> that for enterprise level application this is too costly.
> Is some sample code needed for this?
> Thank you
> ------------------------------------------------------------------------
> *From:* Deepal jayasinghe <>
> *To:*
> *Sent:* Sun, January 23, 2011 10:25:50 PM
> *Subject:* Re: axis2 session scopes
> Now, I got the point. For that you need to try the following.
> Deepal
>> Hi Deepal,
>> I have tried all scopes. In client side I have set manage session to
>> true.
>> For instance. I set the session scope in services.xml to
>> "transportsession".
>> In the web service I use
>> MessageContext messageContext =
>> MessageContext.getCurrentMessageContext();
>> ServiceContext scontext = messageContext.getServiceContext();
>> To store values to last per session. e.g.
>> scontext.setProperty("SUM","" + sum); and I re-use sum across
>> invocations.
>> Also in client I do:
>> ServiceClient client = new ServiceClient();
>> Options options = new Options();
>> options.setTo(new
>> EndpointReference(""));
>> options.setManageSession(true);
>> client.setOptions(opts);
>> I can see that the data I place in MessageContext persist across
>> invocations but I also see that a new web service instance is created
>> per invocation. 
>> So my question is, that the session data will persist but I should
>> expect the web service to be re-instantiated per invocation? 
>> In the example of transport session I have in the web service:
>> public class MyLittleWebService{
>>     publicMyLittleWebService(){
>>         System.out.println("MyLittleService constructor called! New
>> Instance created!");
>>     }
>> And the constructor is being called across all invocations for all
>> types of session except application. 
>> So I understand I must use session data, but this is the expected
>> behavior as well? Re-instantiate the WS per invocation? Isn't it
>> expensive for enterprise level web services?
>> If I am confused on this, please help me out understand what am I
>> doing wrong here.
>> Thank you
>> ------------------------------------------------------------------------
>> *From:* Deepal Jayasinghe <>
>> *To:*
>> *Sent:* Sun, January 23, 2011 4:08:04 PM
>> *Subject:* Re: axis2 session scopes
>> On 1/23/2011 7:11 AM, am am wrote:
>>> I am starting on axis2 (1.5.4).
>>> I am looking into the various session scopes for web services
>>> (request, soapsession etc).
>>> By experimenting, I notice that in all scopes except the application
>>> scope, there is a new instance of my web service being created per
>>> service call.
>>> Only by setting the scope to "application" in the services.xml, the
>>> web service is instantiated only once, and being re-used across all
>>> web service calls.
>>> My testing for this, was actually a print statement in the web
>>> service constructor. The constructor was called for scope="request"
>>> or scope="soapsession" or scope="transportsession" for each ws call.
>>> So my question is the following: Is this the case in axis2? And if
>>> yes, for non-trivial web services, isn't it very costly (to
>>> re-instantiate per service call)?
>>> Is the recommended approach to use application scope services? Or my
>>> understanding is wrong here?
>> Nope, this is not the way Axis2 does the session. As I can see you
>> have not send session related information to manage the session. For
>> example, when you use soapsession you need to send the session ID,
>> which you can  do simply by engaging addressing module to both client
>> and server side and setting the setManageSession(true) in the option
>> object. Similarly, when you use transport session you are required to
>> send the cookies, which can also done by setting the above property.
>> For the request session, it creates service instance for each
>> invocation.
>> Deepal
>>> Thank you!

View raw message