Skip to main content link. Accesskey S
  • Log In
  • Help
  • IBM Logo
  • WebSphere Portal Family wiki
  • All Wikis
  • All Forums
  • Home
  • Product Documentation
  • Community Articles
  • Learning Center
  • IBM Redbooks
Community Articles Product Documentation Learning Center IBM Redbooks This category IBM Redbooks: Building a Sample Website Using IBM Web Content Manager 7.0 IBM Redbooks: Building and Implementing a Social Portal IBM Redbooks: Developing Exceptional Multi-Channel Web Experiences V7: IBM Web Content Manager Product Documentation V7: IBM WebSphere Portal Enable for z/OS Product Documentation V7: IBM WebSphere Portal Express Product Documentation V7: WebSphere Portal Product Documentation V8: IBM Web Content Manager Product Documentation V8: IBM WebSphere Portal Express Product Documentation V8: IBM WebSphere Portal Product Documentation (includes z/OS) Custom Search Scope...
Search
Community Articles > WebSphere Portal > Developing > Implementing a global portlet filter for WebSphere Portal
  • New Article
  • Share Show Menu▼
  • Subscribe Show Menu▼

About the Original Author

IBM contributorJan-Paul Buchwald
Contribution Summary:
  • Articles authored: 6
  • Articles edited: 3
  • Comments Posted: 8

Recent articles by this author

Implementing a global portlet filter for WebSphere Portal

The JSR 286 portlet specification introduced the concept of portlet filters that allow to hook into or intercept the regular portlet request flow much like servlet filters for servlet applications. According to the specification, those filters are selfcontained within the portlet application and ...

Scenarios for Remember Me Cookie in WebSphere Portal

Version 6.1 of WebSphere Portal introduced the remember me cookie feature, which allows previously logged in Portal users to be identified based on a persistent cookie. Though the basic principle of this feature sounds rather simple, it has a couple of implications and there are multiple scenarios ...

Enforcing SSL for particular WebSphere Portal pages

Using SSL for encryption of the HTTP communication provides protection against network sniffing and man in the middle attacks. The additional protection however comes with performance overhead on both client and server side. In typical Portal scenarios it may be therefore too expensive to protect ...

IBM WebSphere Portal JavaScript API Sample Portlets

This document and attached sample gives an implementation example of an AJAXenriched portlet application to be used with WebSphere Portal 6.1 and newer. The sample shows how to benefit from client side portlet preference handling, background requests using the JSR 286 resource request feature, ...

IBM WebSphere Portal Remote State Service and Fragment Service

This document describes two REST Services available in WebSphere Portal as of version 6.1. The Remote State Service enables you to decode the navigational state information from a given WebSphere Portal URL, or, vice versa, encode an existing XML state representation to a portal URL. The Fragment ...

Community articleImplementing a global portlet filter for WebSphere Portal

Added by IBM contributor Jan-Paul Buchwald | Edited by IBM contributor Jan-Paul Buchwald on October 20, 2011 | Version 13
  • Edit
  • More Actions Show Menu▼
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars
expanded Abstract
collapsed Abstract
The JSR 286 portlet specification introduced the concept of portlet filters that allow to hook into or intercept the regular portlet request flow much like servlet filters for servlet applications. According to the specification, those filters are self-contained within the portlet application and have to be mapped to each portlet and life cycle method (render, action, event, resource requests) separately. To cover scenarios where the same portlet filter applies to a larger set of portlets from different applications, the WebSphere Application Server 7 portlet container introduced the concept of global portlet filters. The mechanism is also useful to manipulate portlet behaviour without modifying the portlet application itself. This article gives details on how to use this feature with WebSphere Portal, illustrated by a sample global portlet filter implementation to selectively switch single portlets into a maintenance mode with a special maintenance display text.
Tags: portal portlet filter maintenance
ShowTable of Contents
HideTable of Contents
  • 1 Authors
  • 2 General Concept of Global Portlet Filters
  • 3 Considerations for global portlet filters in a Portal context
  • 4 Description of the Sample Code
    • 4.1 Scenario and Use Case
    • 4.2 Implementation Details
  • 5 Resources

Authors

Jan-Paul Buchwald - Advisory IT Specialist IBM WebSphere Portal Lab Services
Hauke Juhls - Solution Architect IBM Software Services for Lotus

General Concept of Global Portlet Filters


The full description of global portlet filters can be found in the respective section of the WebSphere Application Server Information Centerexternal link. This feature is available since WebSphere Application Server version 7, but is documented in detail and supported as a public plug-point only since version 8 (meaning that you have to contact IBM for a special agreement in order to receive official full support using this concept with WebSphere Portal on Application Server 7). Although the portlet filter concept has been introduced with JSR 286, global filters work for JSR 168 and JSR 286 portlets, but not with legacy IBM API portlets (IBM API based portlets can be filtered using an alternative mechanism described in a developerWorks articleexternal link). The basic principle of global portlet filters is to package the implementations of the JSR 286 portlet filter interfaces in an application and register them with the help of a plugin.xml file. Besides the implementation class, the plugin.xml can specify to which portlet life cycle methods the filter applies, and a set of init parameters to configure the filter during deployment time.

Considerations for global portlet filters in a Portal context


When configuring global portlet filters in a WebSphere Portal environment, a few considerations should be spent in which situation each filter should become active. Being a global concept, each filter applies to all portlets deployed on the system. This includes all product default portlets as well as custom portlets. There is no way to influence that by configurative means. Therefore all distinctions and checks have to be realized by code in the filter implementation.
The first aspect to consider is that code executed in the init method of the global portlet filter must be written in a way that it runs anywhere and does not rely on context information or libraries that are available only to a subset of the portlets installed on the server. For example, it is not recommended to look up any WebSphere Portal portlet services since they most likely have dependencies on classes that are only available in the Portal shared library, so they will not be found for portlets directly used in the Application Server context (such as the portlets of the Integrated Solutions Console). Instead, those kinds of lookups or initialization steps should be done in a lazy manner once the code verified the correct context.
Ensuring the correct context or performing checks whether the filter should step in can be done in a couple of ways:
  1. Check the portal info of the portal context (request.getPortalContext().getPortalInfo()). This way, requests to portlets running in the context of WebSphere Portal can be detected by matching the portal info to a regular expression like “IBM WebSphere Portal/.*”.
  2. Check the context path of the current request. This allows to detect requests to the Integrated Solutions Console, which can be ignored by the filter if it is intended for the Portal only. Other distinctions might be to explicitly detect portlets that have been deployed to WebSphere Portal directly and thus all have the same context root like the Portal (by default /wps/PA...), or pre-deployed portlets with a shared context root prefix (e.g. /predeployed/...).
  3. Check a particular portlet preference on the portlet addressed with the current portlet request. This is the most elegant way to control the filter applicability on a per portlet basis. Portlet preferences can be set or modified during runtime in the Portal admin interface or using the XML configuration interface.
The attached sample code contains implementation examples for all of these concepts to control filter execution.
It is the responsibility of the developer who writes the filter to choose the method that matches the use-case. For example in the scenario described below, the 3rd option using the portlet preference is very well suited as it allows to select individual portlets for filtering.
An example that matches the 1st option could be post-processing portlet output to filter for certain keywords.
Another aspect to consider when filtering calls to the render method of portlets is the two-phase rendering feature. This capability is available starting with WebSphere Portal 7, and enables the usage of the container runtime option javax.portlet.renderHeaders that causes the render method to be invoked twice per request, once to allow the portlet to set response headers first and once to render the actual markup (see section PLT.11.1.4.3 of the JSR 286 specificationexternal link). If a portlet makes use of two-phase rendering, the portlet filter for the render phase is called twice. Therefore the filter implementation should include a check for the render headers phase (by checking the respective request attribute) and return without writing any markup in this case. The sample in the scenario also contains an example how to do this.

Description of the Sample Code

Scenario and Use Case

The sample filter realizes a mechanism that allows to switch particular portlets into a maintenance mode where only markup with a maintenance message is displayed instead of regular invocation of the  portlet . A typical use case is that there are maintenance activities or downtimes on a critical backend system that is used by particular portlets, and you want to avoid that there are a lot of failing backend calls in the portlet involving error messages or timeouts for the end user. After deploying the filter, single portlets can be switched to maintenance mode during runtime by setting a portlet preference. In addition to returning a maintenance message for the render method, the portlet filter makes sure that none of the other portlet life cycle methods is called when the preference is set.
The following picture gives an example of a Portal page where the portlet on the right-hand side is switched to maintenance mode.
Screenshot of Portal page with portlet switched to maintenance mode

Implementation Details


The sample code can be downloaded from Lotus Greenhouseexternal link and is packaged as project interchange file for a web application project and associated enterprise application project. The resulting enterprise application can be directly deployed to the Application Server. The code has been developed with Rational Software Architect 8 and tested with both WebSphere Portal 6.1.5 on WebSphere Application Server 7 and WebSphere Portal 7.
The basic logic is contained in the filter implementation itself (Java class com.ibm.portal.sample.MaintenanceFilter). It first reads the name of the portlet preference from an input parameter in the init method. In the actual doFilter methods, the code first checks if it is running in the context of WebSphere Portal. If so, it reads the portlet preference to check whether the portlet addressed in the current request is configured for maintenance. For the render case, it writes the markup of a maintenance message to the output before quitting the normal render request processing. For the other portlet life cycle methods, it logs a warning and quits the regular request processing. If the preference is not set or a portlet outside of the Portal context is requested, the filter just dispatches to the regular execution of the respective portlet life cycle methods.

Resources

WebSphere Application Server 8 Information Center on Global Portlet Filtersexternal link

  • Edit
  • More Actions Show Menu▼


expanded Attachments (1)
collapsed Attachments (1)
Edit the article to add or modify attachments.
File TypeSizeFile NameCreated On
image/x-png 90 KB MaintenanceFilterScreenshot.png 10/13/11 8:35 AM
expanded Versions (13)
collapsed Versions (13)
Version Comparison     
VersionDateChanged by              Summary of changes
This version (13)Oct 20, 2011 2:11:28 PMJan-Paul Buchwald  IBM contributor
12Oct 19, 2011 3:44:09 PMJan-Paul Buchwald  IBM contributorMinor change
11Oct 19, 2011 3:43:36 PMJan-Paul Buchwald  IBM contributor
10Oct 14, 2011 4:47:12 AMJan-Paul Buchwald  IBM contributorMinor change
9Oct 13, 2011 11:51:42 AMJan-Paul Buchwald  IBM contributorMinor change
8Oct 13, 2011 11:17:26 AMJan-Paul Buchwald  IBM contributorMinor change
7Oct 13, 2011 11:14:11 AMJan-Paul Buchwald  IBM contributorMinor change
6Oct 13, 2011 11:13:49 AMJan-Paul Buchwald  IBM contributorMinor change
5Oct 13, 2011 8:51:41 AMJan-Paul Buchwald  IBM contributorMinor change
4Oct 13, 2011 8:43:34 AMJan-Paul Buchwald  IBM contributorMinor change
3Oct 13, 2011 8:42:37 AMJan-Paul Buchwald  IBM contributor
2Oct 13, 2011 8:38:44 AMJan-Paul Buchwald  IBM contributorMinor change
1Oct 13, 2011 8:35:55 AMJan-Paul Buchwald  IBM contributorInitial version
expanded Comments (0)
collapsed Comments (0)
Copy and paste this wiki markup to link to this article from another article in this wiki.
Go ElsewhereStay ConnectedHelpAbout
  • IBM Collaboration Solutions wikis
  • IBM developerWorks
  • IBM Software support
  • Twitter LinkIBMSocialBizUX on Twitter
  • FacebookIBMSocialBizUX on Facebook
  • ForumsLotus product forums
  • BlogsIBM Social Business UX blog
  • Community LinkIBM Collaboration Solutions
  • Wiki Help
  • Forgot user name/password
  • Wiki design feedback
  • Content feedback
  • About the wiki
  • About IBM
  • Privacy
  • Accessibility
  • IBM Terms of use
  • Wiki terms of use