Portlet: Forward a ResourceRequest to show the full portal

孤街醉人 提交于 2019-12-03 20:18:11

The following is an attempt to do it using a servlet forward, and it seems to work. Still, I think it is a workaround for a feature not present in the portlet specification:

public class ResourceRequestForwardPortlet extends GenericPortlet {

    public void serveResource(ResourceRequest request, ResourceResponse response)
        throws PortletException, IOException {

        HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(portletRequest));
        PortletURL renderURL = portletResponse.createRenderURL();
        try {
            request.setAttribute("error", errorText);

            String forwardURL = renderURL.toString().replace("http://localhost:8080", "");//The generation of the forwardURL could be done nicer
            RequestDispatcher rd = request.getRequestDispatcher(forwardURL);
            rd.forward(request, PortalUtil.getHttpServletResponse(portletResponse));
        } catch (ServletException e) {
            throw new PortletException(e);
        }
    }
}

On top of that, when the forward occurs, Liferay shows a warning on the console:

14:33:51,048 WARN  [http-apr-8080-exec-112][code_jsp:128] {code="404", msg="/poc-forward-portlet/web/guest/home", uri=/web/guest/home}
X-Requested-With null
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!