summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeif Åstrand <leif@vaadin.com>2012-07-26 15:18:35 +0300
committerLeif Åstrand <leif@vaadin.com>2012-07-26 16:29:14 +0300
commit3409ee849396b5e54d3d61d06b048a3541426210 (patch)
tree0c45db1c581b456850878525eb057931d9aa6ac4
parenta1be41f0fcba31c20234b223e36678a8e9a30bf0 (diff)
downloadvaadin-framework-3409ee849396b5e54d3d61d06b048a3541426210.tar.gz
vaadin-framework-3409ee849396b5e54d3d61d06b048a3541426210.zip
Support connector resources in portlets (#9059)
-rw-r--r--src/com/vaadin/terminal/DeploymentConfiguration.java18
-rw-r--r--src/com/vaadin/terminal/gwt/client/ApplicationConnection.java15
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java16
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java17
-rw-r--r--src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java18
-rw-r--r--tests/testbench/com/vaadin/tests/integration/JSR286PortletApplication.java9
-rw-r--r--tests/testbench/com/vaadin/tests/integration/PortletConnectorResource.css3
7 files changed, 72 insertions, 24 deletions
diff --git a/src/com/vaadin/terminal/DeploymentConfiguration.java b/src/com/vaadin/terminal/DeploymentConfiguration.java
index 02a3f0200f..5d622cac20 100644
--- a/src/com/vaadin/terminal/DeploymentConfiguration.java
+++ b/src/com/vaadin/terminal/DeploymentConfiguration.java
@@ -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);
}
diff --git a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
index 0647f2fe96..fa769ce5b5 100644
--- a/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
+++ b/src/com/vaadin/terminal/gwt/client/ApplicationConnection.java
@@ -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;
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
index 978738a1d8..cbc6a7c717 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationPortlet.java
@@ -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) {
@@ -450,6 +455,9 @@ public abstract class AbstractApplicationPortlet extends GenericPortlet
} 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;
} else if (isDummyRequest(resourceRequest)) {
@@ -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);
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
index f0b8c7e3b1..c3e85fa50b 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractApplicationServlet.java
@@ -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;
}
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
index bf69d3bae0..19686cec55 100644
--- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
+++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java
@@ -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("/")) {
diff --git a/tests/testbench/com/vaadin/tests/integration/JSR286PortletApplication.java b/tests/testbench/com/vaadin/tests/integration/JSR286PortletApplication.java
index f0ed0f79cb..c9bcd01092 100644
--- a/tests/testbench/com/vaadin/tests/integration/JSR286PortletApplication.java
+++ b/tests/testbench/com/vaadin/tests/integration/JSR286PortletApplication.java
@@ -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
index 0000000000..7338e4708a
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/integration/PortletConnectorResource.css
@@ -0,0 +1,3 @@
+.hugeBorder {
+ border: 10px solid green;
+} \ No newline at end of file