Esempio n. 1
0
        public NetResponse pullFile(String strUrl, String strFileName, IRhoSession oSession, Hashtable <String, String> headers)
        {
            NetResponse resp = null;

            m_isPullFile = true;

            m_bCancel = false;

            try{
                if (!strFileName.startsWith("file:"))
                {
                    try{
                        strFileName = CFilePath.join(CRhodesApp.getRhoRootPath(), strFileName);
                    } catch (IOException e) {
                        LOG.ERROR("getDirPath failed.", e);
                    }
                }

                m_pulledFile = RhoClassFactory.createFile();
                m_pulledFile.open(strFileName, CRhoFile.EOpenModes.OpenForReadWrite);
                m_pulledFile.setPosTo(m_pulledFile.size());

                do
                {
                    resp = doRequest("GET", strUrl, null, oSession, headers, m_pulledFile.size());
                }while(!m_bCancel && (resp == null || resp.isOK()) && m_nCurDownloadSize > 0);
            }finally{
                if (m_pulledFile != null)
                {
                    try { m_pulledFile.close(); }
                    catch (IOException e)
                    {
                        LOG.ERROR("file closing failed.", e);
                    }
                    m_pulledFile = null;
                }
            }

            copyHashtable(m_OutHeaders, headers);

            m_isPullFile       = false;
            m_nCurDownloadSize = 0;
            return(resp != null && !m_bCancel ? resp : makeResponse("", Convert.ToInt32(HttpStatusCode.InternalServerError)));
        }
Esempio n. 2
0
        public void writeLogMessage(String strMsg)
        {
            try{
                int len = strMsg.length();

                if (m_pFile == null)
                {
                    m_pFile = new CRhoFile();
                }

                if (!m_pFile.isOpened())
                {
                    m_pFile.open(getLogConf().getLogFilePath(), CRhoFile.EOpenModes.OpenForAppend);
                    m_nFileLogSize = (int)m_pFile.size();
                    loadLogPosition();
                }

                if (getLogConf().getMaxLogFileSize() > 0)
                {
                    if ((m_nCirclePos >= 0 && m_nCirclePos + len > getLogConf().getMaxLogFileSize()) ||
                        (m_nCirclePos < 0 && m_nFileLogSize + len > getLogConf().getMaxLogFileSize()))
                    {
                        m_pFile.movePosToStart();
                        m_nFileLogSize = 0;
                        m_nCirclePos   = 0;
                    }
                }

                //int nWritten = m_pFile.writeString(strMsg);
                m_pFile.writeString(strMsg);
                m_pFile.flush();

                if (m_nCirclePos >= 0)
                {
                    m_nCirclePos += len;
                }
                else
                {
                    m_nFileLogSize += len;
                }

                saveLogPosition();
            }catch (Exception exc) {
                log(exc.Message);
            }
        }
Esempio n. 3
0
        void processMultipartItems(Vector <MultipartItem> arItems)
        {
            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)
                    {
                        oItem.m_strFileName = CFilePath.getBaseName(oItem.m_strFilePath);
                    }
                    //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)
                {
                    CRhoFile file = null;
                    try{
                        file = RhoClassFactory.createFile();
                        file.open(oItem.m_strFilePath, CRhoFile.EOpenModes.OpenReadOnly);
                        nContentSize = file.size();
                        if (!file.isOpened())
                        {
                            LOG.ERROR("File not found: " + oItem.m_strFilePath);
                            throw new Exception("File not found:" + oItem.m_strFilePath);
                        }
                    }finally{
                        if (file != null)
                        {
                            try{ file.close(); }catch (IOException e)
                            {
                                LOG.ERROR("file closing failed.", 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";
            }
        }