ICEfaces
  1. ICEfaces
  2. ICE-9808

Use of HttpServletRequest causes problems in portlets.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0.BETA
    • Fix Version/s: 4.0.BETA, 4.0
    • Component/s: ACE-Components
    • Labels:
      None
    • Environment:
      Portal
    • Assignee Priority:
      P1

      Description

      Neil from Liferay is currently seeing the following issue on the ICEfaces 4 trunk:

      java.lang.ClassCastException: com.liferay.portlet.RenderRequestImpl cannot be cast to javax.servlet.http.HttpServletRequest
      at org.icefaces.ace.util.Utils.getRequest(Utils.java:527)
      at org.icefaces.ace.util.Utils.getClientDescriptor(Utils.java:531)
      at org.icefaces.ace.component.textentry.TextEntryRenderer.encodeEnd(TextEntryRenderer.java:97)

      In reviewing the code I see that we are directly casting the request to HttpServletRequest:

          public static HttpServletRequest getRequest(FacesContext facesContext){
              return (HttpServletRequest)facesContext.getExternalContext().getRequest();
          }

      This will definitely cause problems in portlets. The two options:

      1) Use JSF APIs if possible. For example when needing to use session attributes, use ExternalContext.getSessionMap() rather than HttpServletRequest.getSession.getAttribute(). This will ensure that it uses the PortletSession when running in that environment.

      2) Use EnvUtil.getSafeRequest(FacesContext) which returns the PortletRequest wrapped to look like an HttpServletRequest. The warning here is that the full HttpServletRequest API is not implemented. In this case you might just need to change depending what parts of the request are being used.

          public static HttpServletRequest getRequest(FacesContext facesContext){
              return EnvUtils.getSafeRequest(facesContext);
      // return (HttpServletRequest)facesContext.getExternalContext().getRequest();
          }

        Activity

        Hide
        Arturo Zambrano added a comment -

        Committed fix to trunk at revision 40299. Replaced use of HttpServletRequest and other servlet objects for portlet-safe objects.

        Show
        Arturo Zambrano added a comment - Committed fix to trunk at revision 40299. Replaced use of HttpServletRequest and other servlet objects for portlet-safe objects.

          People

          • Assignee:
            Arturo Zambrano
            Reporter:
            Deryk Sinotte
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: