]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support connector resources in portlets (#9059)
authorLeif Åstrand <leif@vaadin.com>
Thu, 26 Jul 2012 12:18:35 +0000 (15:18 +0300)
committerLeif Åstrand <leif@vaadin.com>
Thu, 26 Jul 2012 13:29:14 +0000 (16:29 +0300)
src/com/vaadin/terminal/DeploymentConfiguration.java
src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
tests/testbench/com/vaadin/tests/integration/JSR286PortletApplication.java
tests/testbench/com/vaadin/tests/integration/PortletConnectorResource.css [new file with mode: 0644]

index 02a3f0200fceb1737d2808348f814d61cd327084..5d622cac20fdc6e22ae497af657367e80bd0f656 100644 (file)
@@ -6,6 +6,9 @@ package com.vaadin.terminal;
 
 import java.io.Serializable;
 
+import javax.portlet.PortletContext;
+import javax.servlet.ServletContext;
+
 /**
  * Provide deployment specific settings that are required outside terminal
  * specific code.
@@ -83,4 +86,19 @@ public interface DeploymentConfiguration extends Serializable {
      * @return the class loader to use, or <code>null</code>
      */
     public ClassLoader getClassLoader();
+
+    /**
+     * Returns the MIME type of the specified file, or null if the MIME type is
+     * not known. The MIME type is determined by the configuration of the
+     * container, and may be specified in a deployment descriptor. Common MIME
+     * types are "text/html" and "image/gif".
+     * 
+     * @param resourceName
+     *            a String specifying the name of a file
+     * @return a String specifying the file's MIME type
+     * 
+     * @see ServletContext#getMimeType(String)
+     * @see PortletContext#getMimeType(String)
+     */
+    public String getMimeType(String resourceName);
 }
index 0647f2fe96fc7d49c51bfc8ab39fb6c7b21580c6..fa769ce5b5775efac2968460d300d7e948380e7b 100644 (file)
@@ -2295,6 +2295,15 @@ public class ApplicationConnection {
             }
             uidlUri = themeUri + uidlUri.substring(7);
         }
+
+        if (uidlUri.startsWith(CONNECTOR_PROTOCOL_PREFIX)) {
+            // getAppUri *should* always end with /
+            // substring *should* always start with / (connector:///foo.bar
+            // without connector://)
+            uidlUri = "app://" + CONNECTOR_RESOURCE_PREFIX
+                    + uidlUri.substring(CONNECTOR_PROTOCOL_PREFIX.length());
+            // Let translation of app:// urls take care of the rest
+        }
         if (uidlUri.startsWith("app://")) {
             String relativeUrl = uidlUri.substring(6);
             if (getConfiguration().usePortletURLs()) {
@@ -2318,12 +2327,6 @@ public class ApplicationConnection {
             } else {
                 uidlUri = getAppUri() + relativeUrl;
             }
-        } else if (uidlUri.startsWith(CONNECTOR_PROTOCOL_PREFIX)) {
-            // getAppUri *should* always end with /
-            // substring *should* always start with / (connector:///foo.bar
-            // without connector://)
-            uidlUri = getAppUri() + CONNECTOR_RESOURCE_PREFIX
-                    + uidlUri.substring(CONNECTOR_PROTOCOL_PREFIX.length());
         }
         return uidlUri;
     }
index 978738a1d87a8e83303878206bb5e729746ed6b2..cbc6a7c717b3d219734149dccb2d8a4be7d3531d 100644 (file)
@@ -298,6 +298,11 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
             // #8574)
             return null;
         }
+
+        @Override
+        public String getMimeType(String resourceName) {
+            return getPortletContext().getMimeType(resourceName);
+        }
     };
 
     @Override
@@ -434,7 +439,7 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
     }
 
     protected enum RequestType {
-        FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS;
+        FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APPLICATION_RESOURCE, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, CONNECTOR_RESOURCE;
     }
 
     protected RequestType getRequestType(WrappedPortletRequest wrappedRequest) {
@@ -449,6 +454,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                 return RequestType.BROWSER_DETAILS;
             } else if (ServletPortletHelper.isFileUploadRequest(wrappedRequest)) {
                 return RequestType.FILE_UPLOAD;
+            } else if (ServletPortletHelper
+                    .isConnectorResourceRequest(wrappedRequest)) {
+                return RequestType.CONNECTOR_RESOURCE;
             } else if (ServletPortletHelper
                     .isApplicationResourceRequest(wrappedRequest)) {
                 return RequestType.APPLICATION_RESOURCE;
@@ -546,6 +554,12 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
                 PortletCommunicationManager applicationManager = applicationContext
                         .getApplicationManager(application);
 
+                if (requestType == RequestType.CONNECTOR_RESOURCE) {
+                    applicationManager.serveConnectorResource(wrappedRequest,
+                            wrappedResponse);
+                    return;
+                }
+
                 /* Update browser information from request */
                 applicationContext.getBrowser().updateRequestDetails(
                         wrappedRequest);
index f0b8c7e3b112cadcffc6ac777e8fc64baa8c9e16..c3e85fa50bf89cd0f3c13bf7475179b111ecebf7 100644 (file)
@@ -139,6 +139,11 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                 throw new RuntimeException(e);
             }
         }
+
+        @Override
+        public String getMimeType(String resourceName) {
+            return getServletContext().getMimeType(resourceName);
+        }
     };
 
     /**
@@ -402,17 +407,7 @@ public abstract class AbstractApplicationServlet extends HttpServlet implements
                     .getApplicationManager(application, this);
 
             if (requestType == RequestType.CONNECTOR_RESOURCE) {
-                String pathInfo = getRequestPathInfo(request);
-                // + 2 to also remove beginning and ending slashes
-                String resourceName = pathInfo
-                        .substring(ApplicationConnection.CONNECTOR_RESOURCE_PREFIX
-                                .length() + 2);
-
-                final String mimetype = getServletContext().getMimeType(
-                        resourceName);
-
-                applicationManager.serveConnectorResource(resourceName,
-                        request, response, mimetype);
+                applicationManager.serveConnectorResource(request, response);
                 return;
             }
 
index bf69d3bae09d36d8f54d550948068fcf6f32fe1d..19686cec55867e69d1eb8fe1a82e305800c500f6 100644 (file)
@@ -2471,15 +2471,23 @@ public abstract class AbstractCommunicationManager implements Serializable {
      * including a {@link JavaScript} or {@link StyleSheet} annotation on a
      * Connector class.
      * 
-     * @param resourceName
      * @param request
      * @param response
-     * @param mimetype
+     * 
      * @throws IOException
      */
-    public void serveConnectorResource(String resourceName,
-            WrappedRequest request, WrappedResponse response, String mimetype)
-            throws IOException {
+    public void serveConnectorResource(WrappedRequest request,
+            WrappedResponse response) throws IOException {
+
+        String pathInfo = request.getRequestPathInfo();
+        // + 2 to also remove beginning and ending slashes
+        String resourceName = pathInfo
+                .substring(ApplicationConnection.CONNECTOR_RESOURCE_PREFIX
+                        .length() + 2);
+
+        final String mimetype = response.getDeploymentConfiguration()
+                .getMimeType(resourceName);
+
         // Security check: avoid accidentally serving from the root of the
         // classpath instead of relative to the context class
         if (resourceName.startsWith("/")) {
index f0ed0f79cb8aa8cdebd3e61499f168b269e6286f..c9bcd010928f27e34316d731378dc1c89193f3d3 100644 (file)
@@ -19,6 +19,7 @@ import javax.portlet.ResourceResponse;
 import javax.portlet.WindowState;
 
 import com.vaadin.Application;
+import com.vaadin.annotations.StyleSheet;
 import com.vaadin.terminal.ExternalResource;
 import com.vaadin.terminal.gwt.client.ui.label.ContentMode;
 import com.vaadin.terminal.gwt.server.PortletApplicationContext2;
@@ -38,7 +39,12 @@ import com.vaadin.ui.Upload.Receiver;
  */
 public class JSR286PortletApplication extends Application.LegacyApplication {
 
-    LegacyWindow main = new LegacyWindow();
+    @StyleSheet("PortletConnectorResource.css")
+    public final class LegacyWindowWithStylesheet extends LegacyWindow {
+
+    }
+
+    LegacyWindow main = new LegacyWindowWithStylesheet();
     TextField tf = new TextField("Some value");
     Label userInfo = new Label();
     Link portletEdit = new Link();
@@ -56,6 +62,7 @@ public class JSR286PortletApplication extends Application.LegacyApplication {
         Embedded specialNameResourceTest = new Embedded(
                 "Test ApplicationResources with special names",
                 new SpecialNameResource(this));
+        specialNameResourceTest.addStyleName("hugeBorder");
         main.addComponent(specialNameResourceTest);
 
         userInfo.setCaption("User info");
diff --git a/tests/testbench/com/vaadin/tests/integration/PortletConnectorResource.css b/tests/testbench/com/vaadin/tests/integration/PortletConnectorResource.css
new file mode 100644 (file)
index 0000000..7338e47
--- /dev/null
@@ -0,0 +1,3 @@
+.hugeBorder {
+       border: 10px solid green;
+}
\ No newline at end of file