]> source.dussan.org Git - vaadin-framework.git/commitdiff
Prefixes GET parameters in Liferay with portlet namespace #12602
authorJohn Ahlroos <john@vaadin.com>
Mon, 23 Sep 2013 13:51:42 +0000 (16:51 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 27 Sep 2013 10:33:10 +0000 (10:33 +0000)
Change-Id: I9939a7af83482e136ed0d146accdeec0cd9f10ea

client/src/com/vaadin/client/ApplicationConfiguration.java
client/src/com/vaadin/client/ApplicationConnection.java
server/src/com/vaadin/server/VaadinPortlet.java
server/src/com/vaadin/server/communication/PortletBootstrapHandler.java
shared/src/com/vaadin/shared/ApplicationConstants.java

index da8f5217993a6ea081cb35d50b5c236c2b9fb561..7a70080c7ed3fe31315ad8d4f9e685078101c0af 100644 (file)
@@ -246,6 +246,23 @@ public class ApplicationConfiguration implements EntryPoint {
                 ApplicationConstants.SERVICE_URL_PATH_AS_PARAMETER) == Boolean.TRUE;
     }
 
+    /**
+     * Return the name of the parameter used to to send data to the service url.
+     * This method should only be called if {@link #useServiceUrlPathParam()} is
+     * true.
+     * 
+     * @since 7.1.6
+     * @return The parameter name, by default <code>v-resourcePath</code>
+     */
+    public String getServiceUrlParameterName() {
+        String prefix = getJsoConfiguration(id).getConfigString(
+                ApplicationConstants.SERVICE_URL_PARAMETER_NAMESPACE);
+        if (prefix == null) {
+            prefix = "";
+        }
+        return prefix + ApplicationConstants.V_RESOURCE_PATH;
+    }
+
     public String getRootPanelId() {
         return id;
     }
index 0d9c859ee88d8807e8c81ab222763d6e17196f50..4314602bc2932eecbcd2beee36124158876159bc 100644 (file)
@@ -2994,7 +2994,7 @@ public class ApplicationConnection {
                 if (!path.startsWith("/")) {
                     path = '/' + path;
                 }
-                String pathParam = ApplicationConstants.V_RESOURCE_PATH + "="
+                String pathParam = conf.getServiceUrlParameterName() + "="
                         + URL.encodeQueryString(path);
                 serviceUrl = addGetParameters(serviceUrl, pathParam);
                 uidlUri = serviceUrl;
index d86e5e6507841acf48c26895d706122cbf9f6b4b..093a1c9152b84cbab08b91b5de8cc414cd0f2c30 100644 (file)
@@ -422,16 +422,37 @@ public class VaadinPortlet extends GenericPortlet implements Constants,
      * @return A wrapped version of the PorletRequest
      */
     protected VaadinPortletRequest createVaadinRequest(PortletRequest request) {
-        String portalInfo = request.getPortalContext().getPortalInfo()
-                .toLowerCase();
-        if (portalInfo.contains("liferay")) {
+        if (isLiferay(request)) {
             return new VaadinLiferayRequest(request, getService());
-        } else if (portalInfo.contains("gatein")) {
+        } else if (isGateIn(request)) {
             return new VaadinGateinRequest(request, getService());
         } else {
             return new VaadinPortletRequest(request, getService());
         }
+    }
 
+    /**
+     * Returns true if the portlet request is from Liferay.
+     * 
+     * @param request
+     * @return True if Liferay, false otherwise
+     */
+    private static boolean isLiferay(PortletRequest request) {
+        String portalInfo = request.getPortalContext().getPortalInfo()
+                .toLowerCase();
+        return portalInfo.contains("liferay");
+    }
+
+    /**
+     * Returns true if the portlet request if from GateIn
+     * 
+     * @param request
+     * @return True if GateIn, false otherwise
+     */
+    private static boolean isGateIn(PortletRequest request) {
+        String portalInfo = request.getPortalContext().getPortalInfo()
+                .toLowerCase();
+        return portalInfo.contains("gatein");
     }
 
     private VaadinPortletResponse createVaadinResponse(PortletResponse response) {
index 2458951ada470f8941b003726ead067b04ba4a43..dd6d3c92835c657578c181b15b91bb0c609e74be 100644 (file)
@@ -31,6 +31,7 @@ import org.json.JSONObject;
 import com.vaadin.server.BootstrapHandler;
 import com.vaadin.server.PaintException;
 import com.vaadin.server.VaadinPortlet;
+import com.vaadin.server.VaadinPortlet.VaadinLiferayRequest;
 import com.vaadin.server.VaadinPortletRequest;
 import com.vaadin.server.VaadinPortletResponse;
 import com.vaadin.server.VaadinRequest;
@@ -98,6 +99,8 @@ public class PortletBootstrapHandler extends BootstrapHandler {
         JSONObject parameters = super.getApplicationParameters(context);
         VaadinPortletResponse response = (VaadinPortletResponse) context
                 .getResponse();
+        VaadinPortletRequest request = (VaadinPortletRequest) context
+                .getRequest();
         MimeResponse portletResponse = (MimeResponse) response
                 .getPortletResponse();
         ResourceURL resourceURL = portletResponse.createResourceURL();
@@ -108,6 +111,14 @@ public class PortletBootstrapHandler extends BootstrapHandler {
         parameters
                 .put(ApplicationConstants.SERVICE_URL_PATH_AS_PARAMETER, true);
 
+        // If we are running in Liferay then we need to prefix all parameters
+        // with the portlet namespace
+        if (request instanceof VaadinLiferayRequest) {
+            parameters.put(
+                    ApplicationConstants.SERVICE_URL_PARAMETER_NAMESPACE,
+                    response.getPortletResponse().getNamespace());
+        }
+
         return parameters;
     }
 }
\ No newline at end of file
index 104f3047a8fd97d6f9ddf9a7429f334809dcd895..4b5dc9140bb79ac6f1067e6eb32bd9f78622b0ef 100644 (file)
@@ -49,6 +49,10 @@ public class ApplicationConstants implements Serializable {
 
     public static final String SERVICE_URL_PATH_AS_PARAMETER = "usePathParameter";
 
+    // Denotes the namespace which parameters should be prefixed with when
+    // passed as GET parameters. Currently only used by Liferay.
+    public static final String SERVICE_URL_PARAMETER_NAMESPACE = "pathParameterNS";
+
     // Javadocs in ApplicationConfiguration should be updated if this is changed
     public static final String V_RESOURCE_PATH = "v-resourcePath";