Forums de discussion

RenderRequestImpl cannot be cast to HttpServletRequest

Tim Solka, modifié il y a 10 années.

RenderRequestImpl cannot be cast to HttpServletRequest

New Member Publications: 13 Date d'inscription: 03/05/13 Publications récentes
Hi,

I wanted to enable session replication for my jsf-portlet. It seems that this needs a PhaseListener that takes the session and re-adds the LogicalViewMap, like suggested here: http://stackoverflow.com/questions/12094077/jsf-session-fail-over-and-partial-state-saving
This will trigger the session replication because the setAttribute() is called.
So the Listener would look like this:
public class ViewPhaseListener implements PhaseListener {
public void afterPhase(PhaseEvent phaseEvent){ }
public void beforePhase(PhaseEvent phaseEvent) {
HttpServletRequest request = ((HttpServletRequest) phaseEvent.getFacesContext().getExternalContext().getRequest());
HttpSession session = request.getSession();
session.setAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap", session.getAttribute("com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap"));
}
public PhaseId getPhaseId() { return PhaseId.RENDER_RESPONSE; }
}

(For better formatting click the link above)

I got this working in simple jsf application on tomcat, but when I try to add this to my jsf-liferay-portlet it throws following error:
com.liferay.portlet.RenderRequestImpl cannot be cast to javax.servlet.http.HttpServletRequest

What would be the appropiate way to do this in Liferay? What jars would I need to compile this and where do I get them (e.g. that contains the RenderRequestImpl or what will be needed for this)?

- Liferay 6.1 bundled with tomcat
- Eclipse Juno and Maven for developing (no Liferay IDE)

Thanks!
Tim
thumbnail
David H Nebinger, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
You need to use PortalUtil.getHttpRequest(phaseEvent.getFacesContext().getExternalContext().getRequest());
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
This might work too:
PortletRequest portletRequest = (PortletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
PortletSession portletSession = portletRequest.getPortletSession();


Having said that, I would recommend that you upgrade from Mojarra 2.0.9 to something newer like 2.1.21 and see if this is still a problem. If it is, it sounds like a bug in Mojarra that should be fixed.
Tim Solka, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

New Member Publications: 13 Date d'inscription: 03/05/13 Publications récentes
Thanks for your code snippets. I tried with the jsf-jars from the liferay-jsf-portlet-example and with the current Mojarra jars (2.1)

I can't get the session replication to work in Liferay. I have the most simple JSF app, where you can set a session-scope and
an app-scoped string. The replication works fine on a pure tomcat, but not on Liferay (with or without above re-setting of the session).

Attached is the jsf-app as liferay portlet. It was created by taking the example from Liferay and modifying it. It is very simple.
The <distributable/> tag is set in the app and in Liferay. The beans are serializable. Liferay cluster works in the way that
when changes are made on one instance (e.g. creating a page) it is reflected on the other. Also switching between servers
keeps the user logged in, but the session bean value is resetted.

The attached file doesn't have the PhaseListener because I think it is supposed to work without it.

Thanks for any help!

EDIT: added the portal-ext.properties file, just in case. It's a testing environment, so no privacy issues involved.
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Thanks so much for attaching the WAR project to this thread. I noticed the following dependencies in your WEB-INF/lib folder:

  • jsf-api-2.1.3-b02.jar
  • jsf-impl-2.1.3-b02.jar
  • liferay-faces-alloy-3.1.1-ga2.jar
  • liferay-faces-bridge-api-3.1.1-ga2.jar
  • liferay-faces-bridge-impl-3.1.1-ga2.jar
  • liferay-faces-util-3.1.1-ga2.jar


When you get a chance, please upgrade to Mojarra 2.1.21 and Liferay Faces 3.1.2-ga3 and see if that helps.
Tim Solka, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

New Member Publications: 13 Date d'inscription: 03/05/13 Publications récentes
Hi Neil,

thanks for looking into the war-file. My WEB-INF/lib now contains

  • javax.faces-2.1.24.jar
  • liferay-faces-alloy-3.1.2-ga3.jar
  • liferay-faces-bridge-api-3.1.2-ga3.jar
  • liferay-faces-bridge-impl-3.1.2-ga3.jar
  • liferay-faces-util-3.1.2-ga3.jar


instead of the ones you listed. To redeploy without leftovers I first deleted the folders {tomcat}/work, {tomcat}/temp and {tomcat}/webapps/{mywebapp}.
Still the session replication is not working. I checked the JSESSIONID cookie and it correctly stays the same when switching servers (thanks to the loadbalancer HAproxy).

It seems to me that Liferay causes the replication to fail, since the example works on a simple tomcat.

If you need further information please let me know. I'd really like the replication to work.

Thanks
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Hi Tim,

We have reproduced a similar problem with Tomcat session replication. For news and updates, please click on the "watch" link in JIRA for FACES-1687.

FWIW, our tests are working in GlassFish, and we hope to author a Clustering JSF Portlets on GlassFish wiki article this week.

Kind Regards,

Neil
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Also, in general I would recommend that you downgrade to Mojarra 2.1.21 since there is a Servlet-API ClassCastException that can occur with Mojarra 2.1.24.
Tim Solka, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

New Member Publications: 13 Date d'inscription: 03/05/13 Publications récentes
Thanks for the update and tipps.

I'm looking forward to the glassfish cluster guide.
thumbnail
Neil Griffin, modifié il y a 10 années.

RE: RenderRequestImpl cannot be cast to HttpServletRequest

Liferay Legend Publications: 2655 Date d'inscription: 27/07/05 Publications récentes
Juan has finished the GlassFish wiki article that I mentioned in the post above.