Previous Page | Next Page

Hints and Tips for Creating Custom Portlets

Obtaining a User and Session Context

The SAS Foundation Services user context and session context provide a mechanism for managing information while a user is authenticated to the SAS Intelligence Platform middle tier. For details about using SAS Foundation Services, see the class documentation at http://support.sas.com/92api.

A local portlet has access to the SAS Information Delivery Portal's local user and session context. By using the local user and session context that is shared with the portal, all Java objects created when accessing SAS Foundation Services will be local objects and will be shared by the portal and the portlets.

A remote portlet is implemented as a separate Web application and does not have access to the SAS Information Delivery Portal's local user and session context. A remote user and session context are available to the remote portlet to support single sign-on and passing information from the portal to the remote portlet.

The remote contexts should be used when the remote portlet does not make extensive use of SAS Foundation Services, as illustrated in SampleRemote: Remote Portlet. If more extensive use of SAS Foundation Services is required, the remote portlet should have its own local user and session context. One reason for creating a local user and session context for a remote portlet is to improve efficiency. Java calls will then be local to the Web application's JVM rather than directed to remote services. Another reason for creating a local user and session context for a remote portlet is to improve scalability. A Web application can run in a load-balanced cluster, but there can be only one instance of the remote services application. In addition, the remote contexts are limited to accessing the repositories that are defined in the remote services deployment. Because additional repositories might be defined in the local services deployment, you should use the local session context whenever possible. The process of developing a remote portlet with its own local user and session context requires additional portlet configuration files. Additional metadata must also be created. This document does not include a sample that illustrates these additional steps.

The preferred ways to obtain the user and session contexts are from the HttpSession. The easiest way to obtain the HttpSession in portlet code is from the request, as in the following example:

HttpSession session = request.getSession();

If the request is not available, the HttpSession can also be obtained from the portlet context, as in the following example:

HttpSession session = portletContext.getHttpSession();


Obtaining a Local User and Session Context

The following example obtains both the local user and session contexts from the HttpSession:

UserContextInterface userContext =
   (UserContextInterface)session.getAttribute(CommonKeys.USER_CONTEXT); 
SessionContextInterface sessionContext =
   (SessionContextInterface)session.getAttribute(CommonKeys.SESSION_CONTEXT); 


Obtaining a Remote User and Session Context

The following example obtains both the remote user and session contexts from the HttpSession:

UserContextInterface userContext =
   (UserContextInterface)session.getAttribute(CommonKeys.REMOTE_USER_CONTEXT);
SessionContextInterface sessionContext =
   (SessionContextInterface)session.getAttribute(
      CommonKeys.REMOTE_SESSION_CONTEXT);

Previous Page | Next Page | Top of Page