WebService Axis2 (6): Cross-Service sessions (session) management

Source: Internet
Author: User
Tags sessions

In the "WebService" Axis2 (5): Session management, the article describes how to use AXIS2 to manage the same service session, but for a complex system, there is no single webservice service, for example, at least one administrative user WebService (User login and registration) as well as processing business webservice. In this case, it is necessary to share session state between multiple WebService services, also known as Cross Service sessions (session) management. The steps for implementing cross-service session management are similar to implementing session management for the same service, but there are still differences, and the steps for implementing cross service session management are as follows:

Implementing a cross service session management requires three steps as follows:

1. Use Messagecontext and Servicegroupcontext to obtain and set key-value pairs.

2. Add a scope property for the <service> element corresponding to the WebService class to be managed by session and set the property value to application.

3. Use Setmanagesession (TRUE) on the client to open the Session management feature.

As you can see from the steps above, there are differences in the first two steps to implementing a session management across service sessions and implementing the same service, and the 3rd step is exactly the same. The following is an instance of Session management across services. In this example there are two WebService classes: Loginservice and Searchservice, the following code:

Loginservice.java

Package service;
Import Org.apache.axis2.context.MessageContext;
Import Org.apache.axis2.context.ServiceGroupContext;
public class Loginservice
{public
    Boolean login (string username, string password)
    {
        if ("Bill". Equals (username) && "1234". Equals (password))
        {
            //  1th step: Set Key-value to
            messagecontext MC = Messagecontext.getcurrentmessagecontext ();
            Servicegroupcontext SGC = Mc.getservicegroupcontext ();
            Sgc.setproperty ("Login", "successful Login");
            return true;
        }
        else
        {return
            false;
        }
    }
    Public String getloginmsg ()
    {
       //  step 1th: Get key-value value
        Messagecontext mc = Messagecontext.getcurrentmessagecontext ();
        Servicegroupcontext SGC =  mc.getservicegroupcontext ();
        Return (String) sgc.getproperty ("login");
    }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.