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");
}