示例#1
0
  void processMultipartItems(Vector /*Ptr<CMultipartItem*>&*/ arItems) throws Exception {
    for (int i = 0; i < (int) arItems.size(); i++) {
      MultipartItem oItem = (MultipartItem) arItems.elementAt(i);

      if (oItem.m_strName.length() == 0) oItem.m_strName = "blob";

      if (oItem.m_strFileName.length() == 0) {
        if (oItem.m_strFilePath.length() > 0) {
          FilePath oPath = new FilePath(oItem.m_strFilePath);
          oItem.m_strFileName = oPath.getBaseName();
        }
        // else
        //    oItem.m_strFileName = "doesnotmatter.txt";
      }

      oItem.m_strDataPrefix = i > 0 ? "\r\n" : "";
      oItem.m_strDataPrefix +=
          "------------A6174410D6AD474183FDE48F5662FCC5\r\n"
              + "Content-Disposition: form-data; name=\"";
      oItem.m_strDataPrefix += oItem.m_strName + "\"";
      if (oItem.m_strFileName.length() > 0)
        oItem.m_strDataPrefix += "; filename=\"" + oItem.m_strFileName + "\"";
      oItem.m_strDataPrefix += "\r\n";
      if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
        oItem.m_strDataPrefix += "Content-Type: " + oItem.m_strContentType + "\r\n";

      long nContentSize = 0;
      if (oItem.m_strFilePath.length() > 0) {
        SimpleFile file = null;
        try {
          file = RhoClassFactory.createFile();
          file.open(oItem.m_strFilePath, true, true);
          nContentSize = file.length();
          if (!file.isOpened()) {
            LOG.ERROR("File not found: " + oItem.m_strFilePath);
            throw new RuntimeException("File not found:" + oItem.m_strFilePath);
          }
        } finally {
          if (file != null)
            try {
              file.close();
            } catch (IOException e) {
            }
        }
      } else nContentSize = oItem.m_strBody.length();

      if (oItem.m_strContentType != null && oItem.m_strContentType.length() > 0)
        oItem.m_strDataPrefix += "Content-Length: " + nContentSize + "\r\n";

      oItem.m_strDataPrefix += "\r\n";
    }
  }
示例#2
0
  protected boolean httpGetFile(String strContType) throws IOException {
    if (!isDbFilesPath(uri.getPath())
        && !isKnownExtension(uri.getPath())
        && strContType.length() == 0) {
      String strTemp = FilePath.join(uri.getPath(), "/");

      if (RhoSupport.findClass(strTemp + "controller") != null) return false;

      int nPos = findIndex(uri.getPath());
      if (nPos >= 0) {
        String url = uri.getPath(); // + (nPos == 0 ? ".iseq" : "");
        Properties reqHash = new Properties();
        this.doDispatch(reqHash, url);
        //	RubyValue res = RhoRuby.processIndexRequest(url);//erb-compiled should load from class
        // processResponse(res);

        // RhodesApp.getInstance().keepLastVisitedUrl(url_external);
        return true;
      }

      if (httpGetIndexFile()) return true;
    }

    return httpServeFile(strContType);
  }
示例#3
0
  public NetResponse pullFile(
      String strUrl, String strFileName, IRhoSession oSession, Hashtable headers) throws Exception {
    IRAFile file = null;
    NetResponse resp = null;

    m_nMaxPacketSize = RhoClassFactory.getNetworkAccess().getMaxPacketSize();
    m_bFlushFileAfterWrite = RhoConf.getInstance().getBool("use_persistent_storage");
    m_bCancel = false;

    try {

      if (!strFileName.startsWith("file:")) {
        try {
          strFileName = FilePath.join(RhoClassFactory.createFile().getDirPath(""), strFileName);
        } catch (IOException x) {
          LOG.ERROR("getDirPath failed.", x);
          throw x;
        }
      }

      file = RhoClassFactory.createFSRAFile();
      file.open(strFileName, "rw");
      file.seek(file.size());

      do {
        resp = pullFile1(strUrl, file, file.size(), oSession, headers);
      } while (!m_bCancel
          && (resp == null || resp.isOK())
          && m_nCurDownloadSize > 0
          && m_nMaxPacketSize > 0);

    } finally {
      if (file != null) {
        file.close();
        file = null;
      }
    }

    copyHashtable(m_OutHeaders, headers);

    return resp != null && !m_bCancel
        ? resp
        : makeResponse("", IHttpConnection.HTTP_INTERNAL_ERROR);
  }