From 9a5643bf3b9e5a5f4578b702fab894ee9c715152 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 1 Mar 2016 20:03:16 +0200 Subject: Try to detect Liferay 7 requests correctly (#19645) Change-Id: I5bc616b216e3ecadc76b8f0ef542e74eb4493bda --- server/src/com/vaadin/server/VaadinPortlet.java | 27 ++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'server') diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index 043f95fd7b..5c91b6669c 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -180,6 +180,14 @@ public class VaadinPortlet extends GenericPortlet implements Constants, */ public static class VaadinLiferayRequest extends VaadinHttpAndPortletRequest { + /** + * The PortalUtil class to use. Set to either + * {@link #LIFERAY_6_PORTAL_UTIL} or {@link #LIFERAY_7_PORTAL_UTIL} the + * first time it is needed. + */ + private static String portalUtilClass = null; + private static final String LIFERAY_6_PORTAL_UTIL = "com.liferay.portal.util.PortalUtil"; + private static final String LIFERAY_7_PORTAL_UTIL = "com.liferay.portal.kernel.util.PortalUtil"; public VaadinLiferayRequest(PortletRequest request, VaadinPortletService vaadinService) { @@ -247,19 +255,28 @@ public class VaadinPortlet extends GenericPortlet implements Constants, @Override protected HttpServletRequest getServletRequest(PortletRequest request) { + if (portalUtilClass == null) { + try { + invokeStaticLiferayMethod(LIFERAY_7_PORTAL_UTIL, + "getHttpServletRequest", request, + "javax.portlet.PortletRequest"); + portalUtilClass = LIFERAY_7_PORTAL_UTIL; + } catch (Exception e) { + // Liferay 6 or older + portalUtilClass = LIFERAY_6_PORTAL_UTIL; + } + } try { // httpRequest = PortalUtil.getHttpServletRequest(request); HttpServletRequest httpRequest = (HttpServletRequest) invokeStaticLiferayMethod( - "com.liferay.portal.util.PortalUtil", - "getHttpServletRequest", request, + portalUtilClass, "getHttpServletRequest", request, "javax.portlet.PortletRequest"); // httpRequest = // PortalUtil.getOriginalServletRequest(httpRequest); httpRequest = (HttpServletRequest) invokeStaticLiferayMethod( - "com.liferay.portal.util.PortalUtil", - "getOriginalServletRequest", httpRequest, - "javax.servlet.http.HttpServletRequest"); + portalUtilClass, "getOriginalServletRequest", + httpRequest, "javax.servlet.http.HttpServletRequest"); return httpRequest; } catch (Exception e) { throw new IllegalStateException("Liferay request not detected", -- cgit v1.2.3