Ejemplo n.º 1
0
        String processDispatch(CRoute route, String method, String uri, String query, String body)
        {
            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServe(rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";

            if (route.id.Length > 0)
            {
                strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
            }

            CRhoFile.recursiveCreateDir(strFilePath);
            CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strFilePath);
        }
Ejemplo n.º 2
0
        //public static IDBResult createResult(){
        //	return getInstance().m_dbStorage.createResult();
        //}

        public String makeBlobFolderName()
        {
            String fName = CFilePath.join(CRhodesApp.getRhoRootPath(), "db/db-files");

            CRhoFile.recursiveCreateDir(fName);

            return(fName);
        }
Ejemplo n.º 3
0
        public boolean processBrowserRequest(Uri uri)
        {
            if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) &&
                (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:")))
            {
                return(false);
            }

            String query = "";
            String url   = uri.OriginalString;

            url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url;

            int nFrag = url.LastIndexOf('#');

            if (nFrag >= 0)
            {
                url = url.Substring(0, nFrag);
            }

            int nQuery = url.IndexOf('?');

            if (nQuery >= 0)
            {
                query = url.Substring(nQuery + 1);
                url   = url.Substring(0, nQuery);
            }

            if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root)))
            {
                return(false);
            }

            CRoute route = new CRoute();

            if (dispatch(url, route))
            {
                addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scDispatch));

                return(true);
            }

            String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                addQueueCommand(new CServerCommand(this, route, "GET", url, query, "", CServerCommand.scIndex));

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        String getIndex(String path)
        {
            String[] index_files = { "index_erb.rb", "index.html", "index.htm", "index.php", "index.cgi" };

            if (CFilePath.getExtension(path).Length == 0)
            {
                return(CFilePath.join(path, index_files[0]));
            }

            String strFileName = CFilePath.getBaseName(path);

            return(find_in_string_array(strFileName, index_files) ? path : "");
        }
Ejemplo n.º 5
0
        IDictionary processIndex(CRoute route, String method, String uri, Dictionary <String, String> headers, String query, String body)
        {
            Object rhoResp = new Dictionary <String, String>();

            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strFilePath;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "404";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Not Found";
                return((IDictionary)rhoResp);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH]  = strIndexFile;
                ((IDictionary)rhoResp)[RESPONSE_STATUS]         = "200";
                ((IDictionary)rhoResp)[RESPONSE_STATUS_MESSAGE] = "Ok";
                return((IDictionary)rhoResp);
            }

            Object rhoReq = create_request_hash(route, method, uri, query, headers, body);

            rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strRedirectUrl;
                return((IDictionary)rhoResp);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            ((IDictionary)rhoResp)[RESPONSE_BODY_FILEPATH] = strIndexFile;
            return((IDictionary)rhoResp);
        }
Ejemplo n.º 6
0
        public String getServerQueryUrl(String strAction)
        {
            String strUrl = RhoConf.getInstance().getPath("syncserver");

            if (strAction.length() > 0)
            {
                strUrl = CFilePath.join(strUrl, strAction);
            }
            else
            {
                strUrl = strUrl.substring(0, strUrl.length() - 1);
            }

            return(strUrl);
        }
Ejemplo n.º 7
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)));
        }
Ejemplo n.º 8
0
        String processIndex(CRoute route, String method, String uri, String query, String body)
        {
            String fullPath     = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);
            String strIndexFile = getIndex(fullPath);

            if (!CRhoFile.isResourceFileExist(strIndexFile))
            {
                String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeStringToFile(strFilePath, error);
                return(strFilePath);
            }

            if (CFilePath.getExtension(fullPath).Length > 0)
            {
                return(strIndexFile);
            }

            Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
            Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

            String strRedirectUrl = getRedirectUrl(rhoResp);

            if (strRedirectUrl.Length > 0)
            {
                return(strRedirectUrl);
            }

            strIndexFile += ".gen.html";
            CRhoFile.recursiveCreateDir(strIndexFile);
            CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

            if (method == "GET")
            {
                RHODESAPP().keepLastVisitedUrl(uri);
            }

            return(strIndexFile);
        }
Ejemplo n.º 9
0
        public CResponse decide(String method, String uri, String query, String body)
        {
            if (uri.EndsWith(".gen.html") || (isknowntype(uri) && uri.StartsWith(m_root)))
            {
                return(new CResponse(false));
            }

            if (process_registered(uri))
            {
                return(new CResponse(false));
            }

            CRoute route = new CRoute();

            if (dispatch(uri, route))
            {
                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServe(rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                String strFilePath = RHODESAPP().canonicalizeRhoPath(uri) + ".gen.html";
                if (route.id.Length > 0)
                {
                    strFilePath = CFilePath.join(m_root, route.application + "/" + route.model + "/" + route.action) + ".gen.html";
                }

                CRhoFile.recursiveCreateDir(strFilePath);
                CRhoFile.writeDataToFile(strFilePath, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strFilePath));
            }

            String fullPath = uri.StartsWith(m_root) ? uri : CFilePath.join(m_root, uri);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                if (!CRhoFile.isResourceFileExist(strIndexFile))
                {
                    String error       = "<html><font size=\"+4\"><h2>404 Not Found.</h2> The file " + uri + " was not found.</font></html>";
                    String strFilePath = CFilePath.join(m_root, "rhodes_error") + ".gen.html";
                    CRhoFile.recursiveCreateDir(strFilePath);
                    CRhoFile.writeStringToFile(strFilePath, error);
                    return(new CResponse(strFilePath));
                }

                if (CFilePath.getExtension(fullPath).Length > 0)
                {
                    return(new CResponse(strIndexFile));
                }

                Object rhoReq  = create_request_hash(route, method, uri, query, null, body);
                Object rhoResp = RhoRuby.callServeIndex(strIndexFile, rhoReq);

                String strRedirectUrl = getRedirectUrl(rhoResp);
                if (strRedirectUrl.Length > 0)
                {
                    return(new CResponse(strRedirectUrl));
                }

                strIndexFile += ".gen.html";
                CRhoFile.recursiveCreateDir(strIndexFile);
                CRhoFile.writeDataToFile(strIndexFile, getResponseBody(rhoResp));

                if (method == "GET")
                {
                    RHODESAPP().keepLastVisitedUrl(uri);
                }

                return(new CResponse(strIndexFile));
            }

            return(new CResponse(false));
        }
Ejemplo n.º 10
0
        void loadBulkPartition(String strPartition)
        {
            DBAdapter dbPartition = getDB(strPartition);
            String    serverUrl = RhoConf.getInstance().getPath("syncserver");
            String    strUrl = serverUrl + "bulk_data";
            String    strQuery = "?client_id=" + m_clientID + "&partition=" + strPartition;
            String    strDataUrl = "", strCmd = "", strCryptKey = "";

            getNotify().fireBulkSyncNotification(false, "start", strPartition, RhoAppAdapter.ERR_NONE);

            while (strCmd.length() == 0 && isContinueSync())
            {
                NetResponse resp = getNet().pullData(strUrl + strQuery, this);
                if (!resp.isOK() || resp.getCharData() == null)
                {
                    LOG.ERROR("Bulk sync failed: server return an error.");
                    stopSync();
                    getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp));
                    return;
                }

                LOG.INFO("Bulk sync: got response from server: " + resp.getCharData());

                String    szData     = resp.getCharData();
                JSONEntry oJsonEntry = new JSONEntry(szData);
                strCmd = oJsonEntry.getString("result");
                if (oJsonEntry.hasName("url"))
                {
                    strDataUrl = oJsonEntry.getString("url");
                }

                if (strCmd.compareTo("wait") == 0)
                {
                    int nTimeout = RhoConf.getInstance().getInt("bulksync_timeout_sec");
                    if (nTimeout == 0)
                    {
                        nTimeout = 5;
                    }

                    SyncThread.getInstance().wait(nTimeout);
                    strCmd = "";
                }
            }

            if (strCmd.compareTo("nop") == 0)
            {
                LOG.INFO("Bulk sync return no data.");
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_NONE);
                return;
            }

            if (!isContinueSync())
            {
                return;
            }

            getNotify().fireBulkSyncNotification(false, "download", strPartition, RhoAppAdapter.ERR_NONE);

            String fDataName     = makeBulkDataFileName(strDataUrl, dbPartition.getDBPath(), "");
            String strZip        = ".rzip";
            String strSqlDataUrl = CFilePath.join(getHostFromUrl(serverUrl), strDataUrl) + strZip;

            LOG.INFO("Bulk sync: download data from server: " + strSqlDataUrl);
            {
                NetResponse resp1 = getNet().pullFile(strSqlDataUrl, fDataName + strZip, this, null);
                if (!resp1.isOK())
                {
                    LOG.ERROR("Bulk sync failed: cannot download database file.");
                    stopSync();
                    getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.getErrorFromResponse(resp1));
                    return;
                }
            }

            if (!isContinueSync())
            {
                return;
            }

            LOG.INFO("Bulk sync: unzip db");

            if (!RHODESAPP().unzip_file(fDataName + strZip))
            {
                CRhoFile.deleteFile(fDataName + strZip);
                LOG.ERROR("Bulk sync failed: cannot unzip database file.");
                stopSync();
                getNotify().fireBulkSyncNotification(true, "", strPartition, RhoAppAdapter.ERR_UNEXPECTEDSERVERRESPONSE);
                return;
            }
            CRhoFile.deleteFile(fDataName + strZip);

            LOG.INFO("Bulk sync: start change db");
            getNotify().fireBulkSyncNotification(false, "change_db", strPartition, RhoAppAdapter.ERR_NONE);

            dbPartition.setBulkSyncDB(fDataName, strCryptKey);
            processServerSources("{\"partition\":\"" + strPartition + "\"}");

            LOG.INFO("Bulk sync: end change db");
            getNotify().fireBulkSyncNotification(false, "", strPartition, RhoAppAdapter.ERR_NONE);
        }
Ejemplo n.º 11
0
        public boolean processBrowserRequest(String reqType, Uri uri, IDictionary headers, IDictionary data, String strAjaxContext, int tabIndex = -1)
        {
            boolean bAjaxCall = !(strAjaxContext == null || strAjaxContext.length() == 0);

            if (!uri.OriginalString.StartsWith(RHODESAPP().getHomeUrl()) &&
                (uri.IsAbsoluteUri || uri.OriginalString.StartsWith("res:")))
            {
                return(false);
            }

            String query = "";
            String url   = uri.OriginalString;

            url = url.StartsWith(RHODESAPP().getHomeUrl()) ? url.substring(RHODESAPP().getHomeUrl().length()) : url;

            int nFrag = url.LastIndexOf('#');

            if (nFrag >= 0)
            {
                url = url.Substring(0, nFrag);
            }

            int nQuery = url.IndexOf('?');

            if (nQuery >= 0)
            {
                query = url.Substring(nQuery + 1);
                url   = url.Substring(0, nQuery);
            }

            if (url.EndsWith(".gen.html") || (isknowntype(url) && url.StartsWith(m_root)))
            {
                return(false);
            }

            CRoute route = new CRoute();

            if (dispatch(url, route))
            {
                addQueueCommand(new CServerCommand(this, route, reqType,
                                                   url + (0 < query.Length ? ("?" + query) : ""),
                                                   headers, data, CServerCommand.scDispatch, strAjaxContext, tabIndex));
                //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scDispatch, strAjaxContext));

                return(true);
            }

            String fullPath = url.StartsWith(m_root) ? url : CFilePath.join(m_root, url);

            String strIndexFile = getIndex(fullPath);

            if (strIndexFile.Length > 0)
            {
                addQueueCommand(new CServerCommand(this, route, reqType, url, headers, data, CServerCommand.scIndex, strAjaxContext, tabIndex));
                //addQueueCommand(new CServerCommand(this, route, bAjaxCall ? "GET" : "GET", url, query, "", CServerCommand.scIndex, strAjaxContext));

                return(true);
            }

            return(false);
        }