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
//1 Create an rwsf::HttpSession object.
//2 Retrieve the rwsf::Attribute containing the rwsf::HttpSession.
//3 Shift the contents of httpSession into the rwsf::HttpSession object.
//4 Create a string object called priority.
//5 Create an rwsf::Attribute instance for the priority attribute.
//6 If this is a new session, i.e. the first request from a particular client proxy, set the value of priority to 1.
//7 If this is not the first request for a particular client, then the priority attribute has likely already been set, so get it using the getAttribute() method, and then shift its value into the string oldAttribute.
//8 If priority had been set to 1, confirming that this is not a new session, set it to 2, otherwise, set it to 1.
//9 Shift the priority value into priorityAttr.
//10 Call setAttribute() to set the priority attribute and its value.
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.