HTTP Request, Session, and Principal
When you use the servlet-based report server (Repository Servlet) you can access the http request and session objects via script. Use the parameter array to access the HttpServiceRequest/HttpServiceResponse object, which are wrappers, respectively, for the HttpServletRequest/HttpServletResponse objects.
Note: Although you can set HttpSession properties directly, the it is best to set them on the SRPrincipal. SRPrincipal can be accessed universally within the script of a report or a VPM trigger.
For example, the script below handles the http session attributes and request parameters via the HttpServiceRequest object.
//accessing the service request object
var serReq = parameter['__service_request__'];
// getting session attributes
var sessAttr = serReq.getAttribute('attribute_name');
// setting session attributes
serReq.setAttribute('attribute_name', value_object);
// setting HTTP request parameter
serReq.setParameter('param_name', 'param_value');
// getting the SRPrincipal object
var p = parameter['__principal__'];
// getting a standard SRPrincipal property
var locale = p.getProperty(inetsoft.sree.security.SRPrincipal.LOCALE);
// getting a custom principal property
var prop = p.getProperty("myprop");
To get a direct handle on the HttpServletRequest object, use the following syntax:
var httpReq = serReq.getRequest();
Use the following simplified syntax to acquire the current username:
var userName = parameter['_USER_'];