Manipulating a Service’s Session Data
You can modify the session data in the
rwsf::CallInfo object at any point along the message handler chain. Typically, these modifications would be made in the server implementation, but you could also create a message handler specifically for manipulating the session data. For information on creating a message handler, see
Chapter 15.
The code below shows how you might modify the session data in the
rwsf::CallInfo object.
rwsf::HttpSession session; //1
rwsf::Attribute httpSession = callInfo.get("RWSF:Session"); //2
httpSession >> session; //3
std::string priority; //4
rwsf::Attribute priorityAttr; //5
if (session.isNew()) { //6
priority = "1";
}
else { //7
std::string oldAttribute;
session.getAttribute("priority") >> oldAttribute;
if(oldAttribute == "1") //8
{
priority = "2";
}
else
{
priority = "1";
}
}
priorityAttr << priority; //9
session.setAttribute("priority", priorityAttr); //10
This is all you need to do. The
rwsf::HttpSession object passed around in the
rwsf::CallInfo object is a handle to a body representing the session data held in the HydraExpress Agent. By making calls on the handle, you are directly changing the session data that will be returned to the client.
Note that
rwsf::CallInfo has an interface that allows you to add and modify SOAP and transport header elements. This general-purpose mechanism for passing metadata between client and server is an alternative way to exchange session data. For more information, see
Chapter 15.