Esempio n. 1
0
    public Path normalize(Context ctx, HttpServletRequest request) {
      String path = request.getPathInfo();
      String queryString = request.getQueryString();
      String domain = null;
      String fileId = null;

      if (path != null && path.length() > 0) {
        int start = findStart(path);
        int pos = findPos(start, path);
        domain = path.substring(start, pos);
        fileId = path.substring(pos);
      }

      if (isNull(fileId)) {
        if (!isNull(domain)) {
          ctx.SetValue("fileId", domain);
          ctx.SetValue("domain", "default");
        }
      } else {
        if (!isNull(domain)) {
          ctx.SetValue("domain", domain);
        }
        ctx.SetValue("fileId", fileId);
      }

      if (!isNull(queryString)) {
        ctx.SetValue("query", queryString);
      }

      return new Path(proxyServiceId);
    }
Esempio n. 2
0
  public int actionProcess(Context ctx) throws Exception {
    MultiPartForm msg = (MultiPartForm) ctx.asMessage(MultiPartForm.class);

    msg.handle(this);

    return 0;
  }
Esempio n. 3
0
  public int actionProcess(Context ctx) throws Exception {
    ctx.asMessage(BlobMessage.class);

    String fileId = getArgument("fileId", ctx);
    String domain = getArgument("domain", "default", ctx);

    BlobManager manager = BlobTool.getBlobManager(domain);
    if (manager == null) {
      throw new ServantException(
          "core.blob_not_found", "Can not find a blob manager named " + domain);
    }

    BlobReader reader = manager.getFile(fileId);
    if (reader == null) {
      throw new ServantException("core.blob_not_found", "Can not find a blob file named " + fileId);
    }

    BlobInfo info = reader.getBlobInfo();

    ctx.setResponseContentType(info.contentType());

    InputStream in = reader.getInputStream(0);
    OutputStream out = ctx.getOutputStream();

    try {
      int size = 0;

      while ((size = in.read(buffer)) != -1) {
        out.write(buffer, 0, size);
      }
    } finally {
      IOTools.close(in);
    }

    return 0;
  }