diff options
author | Leif Åstrand <leif@vaadin.com> | 2012-11-21 08:46:43 +0000 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2012-11-21 08:46:43 +0000 |
commit | 519f95fe6999546ff23fc68296ae588cb5d5d6fc (patch) | |
tree | 0429768670f4605d9e42b6ee3fe0aefb09120b81 /server/src/com/vaadin | |
parent | b9038a9d98dad7abdbd5653030ee0034eecc659b (diff) | |
parent | 62f8f102fab8933f2209b8aa7fe9b56ef3c7fa78 (diff) | |
download | vaadin-framework-519f95fe6999546ff23fc68296ae588cb5d5d6fc.tar.gz vaadin-framework-519f95fe6999546ff23fc68296ae588cb5d5d6fc.zip |
Merge "Rename DependencyResource to PublishedFile (#10224)"
Diffstat (limited to 'server/src/com/vaadin')
6 files changed, 57 insertions, 56 deletions
diff --git a/server/src/com/vaadin/annotations/JavaScript.java b/server/src/com/vaadin/annotations/JavaScript.java index 1a2fdf7583..95e74ddc1a 100644 --- a/server/src/com/vaadin/annotations/JavaScript.java +++ b/server/src/com/vaadin/annotations/JavaScript.java @@ -29,7 +29,7 @@ import com.vaadin.server.ClientConnector; * method for the corresponding client-side connector is invoked. * <p> * Absolute URLs including protocol and host are used as is on the client-side. - * Relative urls are mapped to APP/CONNECTOR/[url] which are by default served + * Relative urls are mapped to APP/PUBLISHED/[url] which are by default served * from the classpath relative to the class where the annotation is defined. * <p> * Example: {@code @JavaScript( "http://host.com/file1.js", "file2.js"})} on the diff --git a/server/src/com/vaadin/annotations/StyleSheet.java b/server/src/com/vaadin/annotations/StyleSheet.java index e1a9efd696..18e78f3530 100644 --- a/server/src/com/vaadin/annotations/StyleSheet.java +++ b/server/src/com/vaadin/annotations/StyleSheet.java @@ -28,6 +28,10 @@ import com.vaadin.server.ClientConnector; * framework ensures the referenced style sheets are loaded before the init * method for the corresponding client-side connector is invoked. * <p> + * Absolute URLs including protocol and host are used as is on the client-side. + * Relative urls are mapped to APP/PUBLISHED/[url] which are by default served + * from the classpath relative to the class where the annotation is defined. + * <p> * Example: {@code @StyleSheet( "http://host.com/file1.css", "file2.css"})} on * the class com.example.MyConnector would load the file * http://host.com/file1.css as is and file2.css from /com/example/file2.css on diff --git a/server/src/com/vaadin/server/AbstractCommunicationManager.java b/server/src/com/vaadin/server/AbstractCommunicationManager.java index b0199a3886..731d83067e 100644 --- a/server/src/com/vaadin/server/AbstractCommunicationManager.java +++ b/server/src/com/vaadin/server/AbstractCommunicationManager.java @@ -163,7 +163,7 @@ public abstract class AbstractCommunicationManager implements Serializable { private ClientConnector highlightedConnector; - private Map<String, Class<?>> dependencyResourceContexts = new HashMap<String, Class<?>>(); + private Map<String, Class<?>> publishedFileContexts = new HashMap<String, Class<?>>(); private Map<String, Map<String, StreamVariable>> pidToNameToStreamVariable; @@ -1196,18 +1196,16 @@ public abstract class AbstractCommunicationManager implements Serializable { JavaScript jsAnnotation = class1 .getAnnotation(JavaScript.class); if (jsAnnotation != null) { - for (String resource : jsAnnotation.value()) { - scriptDependencies.add(registerDependency(resource, - class1)); + for (String uri : jsAnnotation.value()) { + scriptDependencies.add(registerDependency(uri, class1)); } } StyleSheet styleAnnotation = class1 .getAnnotation(StyleSheet.class); if (styleAnnotation != null) { - for (String resource : styleAnnotation.value()) { - styleDependencies.add(registerDependency(resource, - class1)); + for (String uri : styleAnnotation.value()) { + styleDependencies.add(registerDependency(uri, class1)); } } } @@ -1286,18 +1284,18 @@ public abstract class AbstractCommunicationManager implements Serializable { URI uri = new URI(resourceUri); String protocol = uri.getScheme(); - if (ApplicationConstants.DEPENDENCY_PROTOCOL_NAME.equals(protocol)) { + if (ApplicationConstants.PUBLISHED_PROTOCOL_NAME.equals(protocol)) { // Strip initial slash String resourceName = uri.getPath().substring(1); - return registerDependencyResource(resourceName, context); + return registerPublishedFile(resourceName, context); } if (protocol != null || uri.getHost() != null) { return resourceUri; } - // Bare path interpreted as dependency resource - return registerDependencyResource(resourceUri, context); + // Bare path interpreted as published file + return registerPublishedFile(resourceUri, context); } catch (URISyntaxException e) { getLogger().log(Level.WARNING, "Could not parse resource url " + resourceUri, e); @@ -1305,24 +1303,23 @@ public abstract class AbstractCommunicationManager implements Serializable { } } - private String registerDependencyResource(String name, Class<?> context) { - synchronized (dependencyResourceContexts) { - // Add to map of names accepted by serveDependencyResource - if (dependencyResourceContexts.containsKey(name)) { - Class<?> oldContext = dependencyResourceContexts.get(name); + private String registerPublishedFile(String name, Class<?> context) { + synchronized (publishedFileContexts) { + // Add to map of names accepted by servePublishedFile + if (publishedFileContexts.containsKey(name)) { + Class<?> oldContext = publishedFileContexts.get(name); if (oldContext != context) { getLogger().warning( - "Dependency " + name + " defined by both " - + context + " and " + oldContext - + ". Dependency from " + oldContext + name + " published by both " + context + " and " + + oldContext + ". File from " + oldContext + " will be used."); } } else { - dependencyResourceContexts.put(name, context); + publishedFileContexts.put(name, context); } } - return ApplicationConstants.DEPENDENCY_PROTOCOL_PREFIX + "/" + name; + return ApplicationConstants.PUBLISHED_PROTOCOL_PREFIX + "/" + name; } /** @@ -2623,64 +2620,64 @@ public abstract class AbstractCommunicationManager implements Serializable { /** * Serve a connector resource from the classpath if the resource has * previously been registered by calling - * {@link #registerDependency(String, Class)}. Sending arbitrary files from - * the classpath is prevented by only accepting resource names that have - * explicitly been registered. Resources can currently only be registered by - * including a {@link JavaScript} or {@link StyleSheet} annotation on a - * Connector class. + * {@link #registerPublishedFile(String, Class)}. Sending arbitrary files + * from the classpath is prevented by only accepting resource names that + * have explicitly been registered. Resources can currently only be + * registered by including a {@link JavaScript} or {@link StyleSheet} + * annotation on a Connector class. * * @param request * @param response * * @throws IOException */ - public void serveDependencyResource(VaadinRequest request, + public void servePublishedFile(VaadinRequest request, VaadinResponse response) throws IOException { String pathInfo = request.getPathInfo(); // + 2 to also remove beginning and ending slashes - String resourceName = pathInfo - .substring(ApplicationConstants.DEPENDENCY_RESOURCE_PREFIX + String fileName = pathInfo + .substring(ApplicationConstants.PUBLISHED_FILE_PATH .length() + 2); - final String mimetype = response.getService().getMimeType(resourceName); + final String mimetype = response.getService().getMimeType(fileName); // Security check: avoid accidentally serving from the UI of the // classpath instead of relative to the context class - if (resourceName.startsWith("/")) { + if (fileName.startsWith("/")) { getLogger().warning( - "Dependency resource request starting with / rejected: " - + resourceName); - response.sendError(HttpServletResponse.SC_NOT_FOUND, resourceName); + "Published file request starting with / rejected: " + + fileName); + response.sendError(HttpServletResponse.SC_NOT_FOUND, fileName); return; } // Check that the resource name has been registered Class<?> context; - synchronized (dependencyResourceContexts) { - context = dependencyResourceContexts.get(resourceName); + synchronized (publishedFileContexts) { + context = publishedFileContexts.get(fileName); } // Security check: don't serve resource if the name hasn't been // registered in the map if (context == null) { getLogger().warning( - "Dependency resource request for unknown resource rejected: " - + resourceName); - response.sendError(HttpServletResponse.SC_NOT_FOUND, resourceName); + "Rejecting published file request for file that has not been published: " + + fileName); + response.sendError(HttpServletResponse.SC_NOT_FOUND, fileName); return; } // Resolve file relative to the location of the context class - InputStream in = context.getResourceAsStream(resourceName); + InputStream in = context.getResourceAsStream(fileName); if (in == null) { getLogger().warning( - resourceName + " defined by " + context.getName() + fileName + " published by " + context.getName() + " not found. Verify that the file " + context.getPackage().getName().replace('.', '/') - + '/' + resourceName + + '/' + fileName + " is available on the classpath."); - response.sendError(HttpServletResponse.SC_NOT_FOUND, resourceName); + response.sendError(HttpServletResponse.SC_NOT_FOUND, fileName); return; } diff --git a/server/src/com/vaadin/server/ServletPortletHelper.java b/server/src/com/vaadin/server/ServletPortletHelper.java index 07218f9abd..00fdccdeb7 100644 --- a/server/src/com/vaadin/server/ServletPortletHelper.java +++ b/server/src/com/vaadin/server/ServletPortletHelper.java @@ -100,9 +100,9 @@ class ServletPortletHelper implements Serializable { return hasPathPrefix(request, UPLOAD_URL_PREFIX); } - public static boolean isDependencyResourceRequest(VaadinRequest request) { + public static boolean isPublishedFileRequest(VaadinRequest request) { return hasPathPrefix(request, - ApplicationConstants.DEPENDENCY_RESOURCE_PREFIX + "/"); + ApplicationConstants.PUBLISHED_FILE_PATH + "/"); } public static boolean isUIDLRequest(VaadinRequest request) { diff --git a/server/src/com/vaadin/server/VaadinPortlet.java b/server/src/com/vaadin/server/VaadinPortlet.java index caa15b7ffd..ac2d81b202 100644 --- a/server/src/com/vaadin/server/VaadinPortlet.java +++ b/server/src/com/vaadin/server/VaadinPortlet.java @@ -311,7 +311,7 @@ public class VaadinPortlet extends GenericPortlet implements Constants { */ @Deprecated protected enum RequestType { - FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APP, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, DEPENDENCY_RESOURCE, HEARTBEAT; + FILE_UPLOAD, UIDL, RENDER, STATIC_FILE, APP, DUMMY, EVENT, ACTION, UNKNOWN, BROWSER_DETAILS, PUBLISHED_FILE, HEARTBEAT; } /** @@ -334,8 +334,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { } else if (ServletPortletHelper.isFileUploadRequest(vaadinRequest)) { return RequestType.FILE_UPLOAD; } else if (ServletPortletHelper - .isDependencyResourceRequest(vaadinRequest)) { - return RequestType.DEPENDENCY_RESOURCE; + .isPublishedFileRequest(vaadinRequest)) { + return RequestType.PUBLISHED_FILE; } else if (ServletPortletHelper.isAppRequest(vaadinRequest)) { return RequestType.APP; } else if (ServletPortletHelper.isHeartbeatRequest(vaadinRequest)) { @@ -427,8 +427,8 @@ public class VaadinPortlet extends GenericPortlet implements Constants { PortletCommunicationManager communicationManager = (PortletCommunicationManager) vaadinSession .getCommunicationManager(); - if (requestType == RequestType.DEPENDENCY_RESOURCE) { - communicationManager.serveDependencyResource( + if (requestType == RequestType.PUBLISHED_FILE) { + communicationManager.servePublishedFile( vaadinRequest, vaadinResponse); return; } else if (requestType == RequestType.HEARTBEAT) { diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 47c2944b10..60f2fed123 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -301,8 +301,8 @@ public class VaadinServlet extends HttpServlet implements Constants { CommunicationManager communicationManager = (CommunicationManager) vaadinSession .getCommunicationManager(); - if (requestType == RequestType.DEPENDENCY_RESOURCE) { - communicationManager.serveDependencyResource(request, response); + if (requestType == RequestType.PUBLISHED_FILE) { + communicationManager.servePublishedFile(request, response); return; } else if (requestType == RequestType.HEARTBEAT) { communicationManager.handleHeartbeatRequest(request, response, @@ -1085,7 +1085,7 @@ public class VaadinServlet extends HttpServlet implements Constants { */ @Deprecated protected enum RequestType { - FILE_UPLOAD, BROWSER_DETAILS, UIDL, OTHER, STATIC_FILE, APP, DEPENDENCY_RESOURCE, HEARTBEAT; + FILE_UPLOAD, BROWSER_DETAILS, UIDL, OTHER, STATIC_FILE, APP, PUBLISHED_FILE, HEARTBEAT; } /** @@ -1098,8 +1098,8 @@ public class VaadinServlet extends HttpServlet implements Constants { protected RequestType getRequestType(VaadinServletRequest request) { if (ServletPortletHelper.isFileUploadRequest(request)) { return RequestType.FILE_UPLOAD; - } else if (ServletPortletHelper.isDependencyResourceRequest(request)) { - return RequestType.DEPENDENCY_RESOURCE; + } else if (ServletPortletHelper.isPublishedFileRequest(request)) { + return RequestType.PUBLISHED_FILE; } else if (isBrowserDetailsRequest(request)) { return RequestType.BROWSER_DETAILS; } else if (ServletPortletHelper.isUIDLRequest(request)) { |