Accessing Sessions from your CA Plex / WebClient application

Since WebClient applications are running on web servers, the concept of the session tracking can be important. Session tracking is a mechanism that is used to maintain state about a series of requests from the same user (that is, requests originating from the same browser) across some period of time. Typical session data that can be of interest is the authenticated user (if any), the URL used to start the web application, the session id, method (GET or POST), query parameters, etc. In this blog entry, we will show you the basics of accessing this information, including supplying an CA Plex XML import file so you can import the example directly into your model.

Technical Details

Your CA Plex application under WebClient has access to the session information from the action diagram by using source” code. The mechanism used is the getFromUserStorage and SetToUserStorage CA Plex API’s (See topic “Storing and Using Third Party Class Instances” in the Plex help). You use the key “javax.servlet.http.HttpServletRequest” to access the session information. The API information can be obtained from a Java Servlet reference, for example here.

Here is an example CA Plex Source Code object to get session information:

Here is the source code to cut and paste:

//Initialize class with parameter
 import javax.servlet.*;
javax.servlet.http.HttpServletRequest MyReq = (javax.servlet.http.HttpServletRequest)(getApp().getFromUserStorage("javax.servlet.http.HttpServletRequest"));
javax.servlet.http.HttpSession MySess = MyReq.getSession();
if(MyReq != null)

And the end result:

You can also access the CA Plex model import XML from this link. This will create a session entity object in your model with the source code object and the simple user interface seen above.