@Override public boolean handleRequest( VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { String pathInfo = request.getPathInfo(); if (pathInfo == null) { return false; } Matcher matcher = pattern.matcher(pathInfo); if (!matcher.matches()) { return false; } String uiid = matcher.group(1); String type = matcher.group(3); String key = matcher.group(2); if (key == null) { return error(request, response, pathInfo + " is not a valid global resource path"); } UI ui = session.getUIById(Integer.parseInt(uiid)); if (ui == null) { return error(request, response, "No UI found for id " + uiid); } UI.setCurrent(ui); ConnectorResource resource; if (LEGACY_TYPE.equals(type)) { resource = legacyResources.get(key); } else { return error( request, response, "Unknown global resource type " + type + " in requested path " + pathInfo); } if (resource == null) { return error(request, response, "Global resource " + key + " not found"); } DownloadStream stream = resource.getStream(); if (stream == null) { return error(request, response, "Resource " + resource + " didn't produce any stream."); } stream.writeResponse(request, response); return true; }
@Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { DownloadStream stream = null; String[] parts = path.split("/", 2); String key = parts[0]; VaadinSession session = getSession(); session.lock(); try { ConnectorResource resource = (ConnectorResource) getResource(key); if (resource == null) { return false; } stream = resource.getStream(); } finally { session.unlock(); } stream.writeResponse(request, response); return true; }