summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2013-05-10 11:36:46 +0300
committerVaadin Code Review <review@vaadin.com>2013-05-10 09:58:12 +0000
commit3f5d022e7fca887341cc7ffb0ff48ac99ed558b4 (patch)
tree2c7bf6f5e36ec4f95e001c9042a5a5c241342ac9 /server
parentce9c818b8c1cd290747d841166008898187e7a58 (diff)
downloadvaadin-framework-3f5d022e7fca887341cc7ffb0ff48ac99ed558b4.tar.gz
vaadin-framework-3f5d022e7fca887341cc7ffb0ff48ac99ed558b4.zip
Liferay 6.2 compatibility (#11751)
Change-Id: I5a14aba47f3e92249b245392acaf5ff9bda62083
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/VaadinPortlet.java69
1 files changed, 63 insertions, 6 deletions
diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java
index 7d4618d58e..ac4e904898 100644
--- a/server/src/com/vaadin/server/VaadinPortlet.java
+++ b/server/src/com/vaadin/server/VaadinPortlet.java
@@ -21,6 +21,7 @@ import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.security.GeneralSecurityException;
@@ -47,7 +48,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
-import com.liferay.portal.kernel.util.PortalClassInvoker;
+import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.vaadin.server.AbstractCommunicationManager.Callback;
import com.vaadin.ui.UI;
@@ -178,19 +179,75 @@ public class VaadinPortlet extends GenericPortlet implements Constants,
return PropsUtil.get(name);
}
+ /**
+ * Simplified version of what Liferay PortalClassInvoker did. This is
+ * used because the API of PortalClassInvoker has changed in Liferay
+ * 6.2.
+ *
+ * This simply uses reflection with Liferay class loader. Parameters are
+ * Strings to avoid static dependencies and to load all classes with
+ * Liferay's own class loader. Only static utility methods are
+ * supported.
+ *
+ * This method is for internal use only and may change in future
+ * versions.
+ *
+ * @param className
+ * name of the Liferay class to call
+ * @param methodName
+ * name of the method to call
+ * @param parameterClassName
+ * name of the parameter class of the method
+ * @throws Exception
+ * @return return value of the invoked method
+ */
+ private static Object invokeStaticLiferayMethod(String className,
+ String methodName, Object argument, String parameterClassName)
+ throws Exception {
+ Thread currentThread = Thread.currentThread();
+
+ ClassLoader contextClassLoader = currentThread
+ .getContextClassLoader();
+
+ try {
+ // this should be available across all Liferay versions with no
+ // problematic static dependencies
+ ClassLoader portalClassLoader = PortalClassLoaderUtil
+ .getClassLoader();
+ // this is in case the class loading triggers code that
+ // explicitly
+ // uses current thread class loader
+ currentThread.setContextClassLoader(portalClassLoader);
+
+ Class<?> targetClass = portalClassLoader.loadClass(className);
+ Class<?> parameterClass = portalClassLoader
+ .loadClass(parameterClassName);
+ Method method = targetClass.getMethod(methodName,
+ parameterClass);
+
+ return method.invoke(null, new Object[] { argument });
+ } catch (InvocationTargetException ite) {
+ throw (Exception) ite.getCause();
+ } finally {
+ currentThread.setContextClassLoader(contextClassLoader);
+ }
+ }
+
private static HttpServletRequest getOriginalRequest(
PortletRequest request) {
try {
// httpRequest = PortalUtil.getHttpServletRequest(request);
- HttpServletRequest httpRequest = (HttpServletRequest) PortalClassInvoker
- .invoke("com.liferay.portal.util.PortalUtil",
- "getHttpServletRequest", request);
+ HttpServletRequest httpRequest = (HttpServletRequest) invokeStaticLiferayMethod(
+ "com.liferay.portal.util.PortalUtil",
+ "getHttpServletRequest", request,
+ "javax.portlet.PortletRequest");
// httpRequest =
// PortalUtil.getOriginalServletRequest(httpRequest);
- httpRequest = (HttpServletRequest) PortalClassInvoker.invoke(
+ httpRequest = (HttpServletRequest) invokeStaticLiferayMethod(
"com.liferay.portal.util.PortalUtil",
- "getOriginalServletRequest", httpRequest);
+ "getOriginalServletRequest", httpRequest,
+ "javax.servlet.http.HttpServletRequest");
return httpRequest;
} catch (Exception e) {
throw new IllegalStateException("Liferay request not detected",