Custom Session ID Generator Example
Create the custom ID generator
This code snippet creates a simple custom session ID generator.
#include <rwsf/servlet/http/HttpSessionIdGenerator.h>
#include <string>
class CustomSessionIdGenerator : public rwsf::HttpSessionIdGenerator //1
{ public:
std::string generateSessionId();
};
std::string CustomSessionIdGenerator::generateSessionId() //2
{
return "Custom Session ID";
}
RWSF_DEFINE_HTTP_SESSION_ID_GENERATOR(CustomSessionIdGenerator); //3
Compile the custom generator into a loadable shared library placed in the search path of the HydraExpress Agent, for example, CustomLib.so.
Register the custom generator
Next, register the custom generator by adding the rwsf:httpSessionIdGenerator property to the servlet handler under the http handler-chain in the agent configuration file rwagent.xml, located by default in <installdir>\conf.
The value defined is the library name followed by the create function name separated by a period, CustomLib.createCustomSessionIdGenerator in this example. The following code snippet demonstrates the relevant rwagent.xml file modifications:
<rwsf:handler-chain name="http">
<rwsf:handler name="httpServer"
class="rwsf_transport_http.createHttpServerHandlerImp"
type="request"/>
<rwsf:handler name="servlet"
class="rwsf_servlet.createServletMessageInfoHandlerImp"
type="request">
<rwsf:property name="rwsf:configDir" value="${RWSF_CONF}/servlet"/>
<rwsf:property name="rwsf:webappsDir" value="${RWSF_HOME}/apps/servlets"/>
<rwsf:property name="rwsf:librarySuffix" value="19012d"/>
<rwsf:property name="rwsf:debugLibrarySuffix" value="19015d"/>
<rwsf:property name="rwsf:httpSessionIdGenerator"
value="CustomLib.createCustomSessionIdGenerator"/>
</rwsf:handler>
</rwsf:handler-chain>