WebSphere Portal: How to get HttpServletRequest and HttpServletResponse from Portlet Request?

Like most portlet developments, there are some scenarios where you might need to retrieve HttpServletRequest and HttpServletResponse from Portlet Request (RenderRequest/RenderResponse/ActionRequest/ActionResponse etc).

In WebSphere Portal, there is a PortletUtils utility class that provides the method you need:

import com.ibm.ws.portletcontainer.portlet.PortletUtils;

// call the respective methods to get HttpServletRequest/HttpServletResponse you need
PortletUtils.getHttpServletRequest(request);

[10/9/2014]: As highlighted by Stefan Schmitt, the above mentioned method is not supported by IBM. We found out about this class when we de-compiled “Sitemap” portlet. There is 7 or more PortletUtils types if you viewed it from your RAD “Quick fix”, use it at your own discretion.

2 thoughts on “WebSphere Portal: How to get HttpServletRequest and HttpServletResponse from Portlet Request?”

    1. Hi Stefan Schmitt, thanks for highlighting!

      You are right, we found out about PortletUtils when we were trying to figure out on how “Sitemap” portlet works. That is where we discovered that the portlet is using PortletUtils to retrieve the servlet response and response for com.ibm.portal.model.NavigationSelectionModelProvider method.

      Any chances that IBM will release PortletUtils as part of the SPI? Let me put a note to “warn” others.

Leave a Reply

Your email address will not be published. Required fields are marked *