Oracle9iAS Portal Developer Kit (PDK)
Implementing Session Context in PL/SQL Portlets

Last Update: Aug 04, 2003
Status: Production
Version: Any PDK Release

Introduction

Oracle9iAS Portal provides a set of APIs for extracting miscellaneous session related information. The session context includes information about the portal user including username, current session ID, IP address, and language preference. It also includes supporting information such as the Portal schema currently being used.

For an introductory overview of Session Context Services, please refer to the Primer on Session Context.

Session context services are available through the wwctx_api package.

This article describes how the Session Context services are implemented using the Services Example. It provides a guideline for adding the Session Context service to your portlet functionality.

Assumptions

Implementing Session Context

This section describes how the session context service is incorporated in a PL/SQL portlet.
  1. From the downloaded Services Example, review the services_portlet.pkb file which is the package body for this portlet. An excerpt is provided below.
  2. Scroll the file to the section that contains the procedure get_portlet_info. The Session Context API get_user is used here to derive the user information and set that value in the portlet information record. This code segment is highlighted below.

    CREATE OR REPLACE

    package body SERVICES_PORTLET

    is

    ...

    function get_portlet_info

    (

    p_provider_id in integer

    ,p_language in varchar2

    )

    return wwpro_api_provider.portlet_record

    is

    l_portlet wwpro_api_provider.portlet_record;

    begin

    ...

    l_portlet.id := services_provider.SERVICES_PORTLET_ID;

    l_portlet.provider_id := p_provider_id;

    ...

    l_portlet.created_by := wwctx_api.get_user;

    l_portlet.last_updated_by := wwctx_api.get_user;

    ...

    end get_portlet_info;

    ...

    end SERVICES_PORTLET;

    /

  3. Similarly user information is derived in various places using the get_user API. Search the code for other occurrences of the wwctx_api.get_user calls.
  4. You can also check whether the user is logged on using the is_logged_on API for security purposes as shown below. Another possibility is to derive the NLS language setting of the session using the get_nls_language API. Both these examples are highlighted below.

    CREATE OR REPLACE

    package body SERVICES_PORTLET

    is

    ...

    function is_runnable

    (

    p_provider_id in integer

    ,p_reference_path in varchar2

    )

    return boolean

    is

    begin

    /*

    Portlet security check. It allows the portlet to be visible

    if the user is logged on, i.e. the current session is not a

    public session.

    */

    return wwctx_api.is_logged_on;

    end is_runnable;

    ...

    procedure register

    (

    p_portlet_instance in wwpro_api_provider.portlet_instance_record

    )

    is

    begin

    ...

    /*

    Create the names to store the portlet preferences.

    */

    wwpre_api_name.create_name( p_path => PORTLET_PATH

    || p_portlet_instance.reference_path,

    p_name => PREFNAME_STRING,

    p_description => 'Single custom row in '

    || 'Introductory Example portlet.',

    p_type_name => 'NLSID'

    p_language => wwctx_api.get_nls_language);

    ...

    end register;

    ...

    end SERVICES_PORTLET;

    /

You can implement session context in a similar fashion but based on your functional requirements.

Other details sections & sub-sections (Optional)

  1. Create a page and add the Services portlet to your page. Click on the 'Customize' link and make changes to your preferences for the given string and title of the portlet for different session settings of NLS language ( for say, both 'US' and 'German') . Take note of how the preferences are stored and retrieved using different language settings of your browser. This is achieved with the Session Context API for deriving current browser language setting.
Revision History:
Revision No Last Update
1.0

Dec 11, 2000


Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065, USA
http://www.oracle.com/
Worldwide Inquiries:
1-800-ORACLE1
Fax 650.506.7200
Copyright and Corporate Info