Defining and Using Headers through the rwsf::CallInfo Interface
Class
rwsf::CallInfo includes a wide range of methods to add, clear, or otherwise manipulate transport and SOAP headers, in both client, server-side, and handler code.
NOTE: This section uses transport headers for illustration, but SOAP headers work the same way. HydraExpress ships with a Headers example that illustrates working with SOAP and transport headers,
SOAP Headers Example. Also see
Chapter 11 for information about transport handlers.
This section provides a few examples on using the some
rwsf::CallInfo methods. For full information on
rwsf::CallInfo, please see its entry in the reference guide.
This example shows how to retireve all the HTTP request headers:
#include <iostream>
#include <rwsf/core/Enumeration.h>
void ExampleImp::printHeaders(CallInfo& info , std::string payload) //1
{
rwsf::Enumeration<rwsf::CallInfo::TransportHeaderObject> httpHeaders = //2
info.getRequestTransportHeaders();
while( httpHeaders.hasMoreElements() ) { //3
rwsf::CallInfo::TransportHeaderObject header = httpHeaders.nextElement();
std::cout << header.name_ << ": " << header.value_ << std::endl;
}
}
Note that you can also retrieve response headers in the same way by calling getResponseTransportHeaders() on the CallInfo object.
This code simply adds a request transport header:
rwsf::CallInfo info;
info.addRequestTransportHeader("myHeader", "MyValue");
On the server side, check to see if the request header was set and add a response transport header:
rwsf::CallInfo info;
std::string set = info.isRequestTransportHeaderSet("myHeader");
std::string value = info.getRequestTransportHeaderValue("myHeader");
info.addResponseTransportHeader("myHeaderResponse", "MyValueResponse");
Use a custom transport handler to remove a transport header and then add a different one:
class MyTransportHandler1 : public rwsf::MessageHandlerImp {
public:
virtual void invoke(rwsf::CallInfo& callInfo)
{
if (!callInfo.isRequest()) {
callInfo.removeResponseTransportHeader("requestHeader");
callInfo.addResponseTransportHeader("responseHeader", "Value1");
}
}
};