private static boolean error(VaadinRequest request, VaadinResponse response, String logMessage)
      throws IOException {
    getLogger().log(Level.WARNING, logMessage);
    response.sendError(
        HttpServletResponse.SC_NOT_FOUND, request.getPathInfo() + " can not be found");

    // Request handled (though not in a nice way)
    return true;
  }
  @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;
  }