]> source.dussan.org Git - vaadin-framework.git/commitdiff
Try to detect Liferay 7 requests correctly (#19645)
authorArtur Signell <artur@vaadin.com>
Tue, 1 Mar 2016 18:03:16 +0000 (20:03 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 8 Mar 2016 15:37:10 +0000 (15:37 +0000)
Change-Id: I5bc616b216e3ecadc76b8f0ef542e74eb4493bda

server/src/com/vaadin/server/VaadinPortlet.java

index 043f95fd7ba55ec7a4e2d6f4e6eafcc88c45c908..5c91b6669cc7e0d8bdfe1fbacd0c9b145f6bb1ce 100644 (file)
@@ -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",