How to get portlet and page name in a portlet filter

Solution Verified - Updated -


  • Red Hat JBoss Portal (JPP)
    • 6.1


We have some filters (ActionFilter, RenderFilter, ...) defined in our portlet application’s portlet.xml. From these classes we want to write some log entries that tell the user which portlet and page belongs the log entry to, but we don’t know how or where to get this information at this point. Is there any portlet utils class or property where we can get this?


The following sample filter shows how to get various information about the portal as well as the portlet inside a PortletFilter. Note that the information is retrieved through objects defined by the portlet spec, using the Portal API 1 as well as GateIn specific components.



import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.filter.ActionFilter;
import javax.portlet.filter.FilterChain;
import javax.portlet.filter.FilterConfig;
import javax.portlet.filter.RenderFilter;

import org.gatein.api.PortalRequest;
import org.gatein.pc.api.invocation.PortletInvocation;

public class InfoFilter implements ActionFilter, RenderFilter {

    public void destroy() {

    public void init(FilterConfig config) throws PortletException {

    public void doFilter(ActionRequest request, ActionResponse response,
            FilterChain chain) throws IOException, PortletException {
        printInfo(request, response);
        chain.doFilter(request, response);

    public void doFilter(RenderRequest request, RenderResponse response,
            FilterChain chain) throws IOException, PortletException {
        printInfo(request, response);
        chain.doFilter(request, response);

    private void printInfo(PortletRequest request, PortletResponse response) {

        StringBuffer buf = new StringBuffer("Filter[");

        // get portlet name from portlet config
        PortletConfig portletConfig = (PortletConfig) request.getAttribute("javax.portlet.config");
        if(portletConfig != null)
            buf.append("portlet=" + portletConfig.getPortletName() + ", ");

        // get phase from request attribute
        String phase = (String) request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
        if(phase != null)
            buf.append("phase=" + phase + ", ");

        // get PortletInvocation using org.gatein.pc:pc-api 
        PortletInvocation portletInvocation = (PortletInvocation) request.getAttribute(" org.jboss.portal.attribute.component_invocation");
        if(portletInvocation != null) {
            // get portlet mode
            buf.append("mode=" + portletInvocation.getMode().toString() + ", ");

            // get window state
            buf.append("windowState=" + portletInvocation.getWindowState().toString() + ", ");

        // get portal information using Portal API
        PortalRequest portalRequest = PortalRequest.getInstance();      
        if(portalRequest != null) {
            // get portal page
            if(portalRequest.getPage() != null)
                buf.append("page=" + portalRequest.getPage().getName() + ", ");

            // get site name
            if(portalRequest.getSite() != null)
                buf.append("site=" + portalRequest.getSite().getName() + ", ");

            // get user name
            if(portalRequest.getUser() != null)
                buf.append("user=" + portalRequest.getUser().getId());




In order to apply this filter to all deployed portlets, add the filter definition to $JPP_HOME/standalone/configuration/gatein/portlet.xml :


This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.