Reading URL parameters in a JSR286 portlet on Websphere Portal 8.5

2.3k Views Asked by At

In IBM Websphere Portal 8.5, how can I get retrieve query string parameters from the URL, inside a JSR286 portlet ?

It seems that the HTTPServletRequest is not passed through to the PortletRequest. Do I need to use the configuration in the portlet.xml ? That seems to be used to manage communication between portlets, but anyway I've tried to use it but without success, every ParameterNames and ParameterMap is coming empty.

Do I need to set some interceptor/filter to pre-process the parameters ?

Not sure how much of this question is specific about IBM Websphere Portal or just plain JSR286 portlets.

3

There are 3 best solutions below

2
On

Try (Another option):

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

public HttpServletRequest getHttpServletRequest(PortletRequest request) {
        return PortletUtils.getHttpServletRequest(request);
    }

You must install the jar (com.ibm.ws.portletcontainer.jar) in your local maven repository.

This jar is in: WebSphere / AppServer / plugins

2
On

Using just the portlet spec, I don't believe there is anyway to get access to the HttpRequest. The idea behind that is that since the portlet doesn't have full control over the entire HTTP Request / Response (the portlet container does), the portlet shouldn't be able to have access to those objects.

IBM Portal does have an API you can call to get to it though should you need it for scenarios like yours. Here is an abbreviated code sample from one my projects that we run on Portal 8.0. Double check the docs for if the API changed in 8.5.

import com.ibm.wps.pb.utils.portlet.PortletUtils;

...

public void doView(RenderRequest request, RenderResponse response) {

    HttpServletRequest httpRequest = PortletUtils.getHttpServletRequest(request)
}
0
On

be careful when working with primefaces bridge, which gives us the method PortletUtils.getHttpServletRequest is an object of type RenderRequestWrapper, so there are q do the following:

HttpServletRequest requestInsideThePortlet = PortletUtils
.getHttpServletRequest (((RenderRequestWrapper) PortletRequest)
.getPortletRequest ());

with this we get the HttpServletRequest and not null :)