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); }
void doDispatch(Properties reqHash, String strIndex) throws IOException { reqHash.setProperty("request-method", this.method); reqHash.setProperty("request-uri", uri.getPath()); reqHash.setProperty("request-query", uri.getQueryString()); if (postData != null && postData.size() > 0) { if (!RHOCONF().getBool("log_skip_post")) LOG.TRACE(postData.toString()); reqHash.setProperty("request-body", postData.toString()); } RubyValue res = RhoRuby.processRequest(reqHash, reqHeaders, resHeaders, strIndex); processResponse(res); RhodesApp.getInstance().keepLastVisitedUrl(url_external); LOG.INFO("dispatch end"); }
public InputConnection handleResourceRequest(BrowserFieldRequest request) throws Exception { String url = request.getURL(); if (RhodesApp.getInstance().isRhodesAppUrl(url) || URI.isLocalData(url)) { HttpConnection connection = Utilities.makeConnection(url, request.getHeaders(), null, null); return connection; } else return super.handleResourceRequest(request); }
protected boolean httpServeFile(String strContType) throws IOException { String strPath = uri.getPath(); // if ( !strPath.startsWith("/apps") ) // strPath = "/apps" + strPath; LOG.TRACE("httpServeFile: " + strPath); if (!isDbFilesPath(strPath)) { if (strContType.equals("application/javascript")) { responseData = RhoRuby.loadFile(strPath); if (responseData == null) { String str = ""; responseData = new ByteArrayInputStream(str.getBytes()); } } else responseData = RhoRuby.loadFile(strPath); } else { if (strPath.startsWith("/apps/app/db/db-files")) strPath = strPath.substring(9); // remove /apps/app else strPath = strPath.substring(5); // remove /apps } if (responseData == null) { SimpleFile file = null; try { file = RhoClassFactory.createFile(); String strFileName = strPath; // if ( strFileName.startsWith("/apps") ) // strFileName = strPath.substring(5); file.open(strFileName, true, true); responseData = file.getInputStream(); if (responseData != null) { contentLength = (int) file.length(); } m_file = file; } catch (Exception exc) { if (file != null) file.close(); } } else { if (responseData != null) { contentLength = responseData.available(); } } if (responseData == null) return false; if (strContType.length() > 0) resHeaders.addProperty("Content-Type", strContType); resHeaders.addProperty("Content-Length", Integer.toString(contentLength)); // resHeaders.addProperty("Date",getLocalHttpTimeString()); // resHeaders.addProperty("Cache-control", "public, max-age=3600" ); // resHeaders.addProperty("Expires", "Thu, 01 Dec 2010 16:00:00 GMT" ); return true; }
public String next() { if (isEnd()) return null; int nEnd = strPath.indexOf('/', nStart); if (nEnd < 0) nEnd = strPath.length(); String res = strPath.substring(nStart, nEnd); nStart = nEnd + 1; return URI.urlDecode(res).trim(); }
public void resetUrl(String url) { url_external = url; uri = new URI(url_external); if (!uri.getPath().startsWith("/apps")) uri.setPath("/apps" + uri.getPath()); else uri.setPath(uri.getPath()); method = ""; responseCode = 200; responseMsg = "OK"; contentLength = -1; reqHeaders.clear(); resHeaders.clear(); requestProcessed = false; try { clean(); } catch (IOException exc) { LOG.ERROR("clean failed.", exc); } }
protected boolean httpGetIndexFile() { String strIndex = null; String slash = ""; if (uri.getPath() != null && uri.getPath().length() > 0) slash = uri.getPath().charAt(uri.getPath().length() - 1) == '/' ? "" : "/"; for (int i = 0; i < m_arIndexes.length; i++) { String name = uri.getPath() + slash + m_arIndexes[i]; String nameClass = name; if (nameClass.endsWith(".iseq")) nameClass = nameClass.substring(0, nameClass.length() - 5); if (RhoSupport.findClass(nameClass) != null || RhoRuby.resourceFileExists(name)) { strIndex = name; break; } } if (strIndex == null) return false; respondMoved(strIndex); return true; }
void respondNotFound(String strError) { responseCode = HTTP_NOT_FOUND; responseMsg = "Not found"; if (strError != null && strError.length() != 0) responseMsg += ".Error: " + strError; String strBody = "Page not found: " + uri.getPath(); contentLength = strBody.length(); responseData = new ByteArrayInputStream(strBody.getBytes()); resHeaders.addProperty("Content-Type", "text/html"); resHeaders.addProperty("Content-Length", Integer.toString(contentLength)); }
/** Construct connection using URI * */ public RhoConnection(URI _uri) { url_external = _uri.toString(); uri_orig = _uri; uri = new URI(url_external); if (!uri.getPath().startsWith("/apps")) uri.setPath("/apps" + uri.getPath()); else uri.setPath(uri.getPath()); }
public void processRequest() throws IOException { if (!requestProcessed) { String strErr = ""; LOG.TRACE("processRequest: " + getURL()); String strReferer = reqHeaders != null ? reqHeaders.getPropertyIgnoreCase("Referer") : ""; if (getRef() != null && getRef().length() > 0 && strReferer != null && strReferer.equalsIgnoreCase(uri_orig.getPathNoFragment())) { respondNotModified(); } else { String strContType = getContentType(); if (uri.getPath().startsWith("/apps/public")) { httpServeFile(strContType); } else { if (this.method.equals("POST") || strContType.length() == 0 || strContType.indexOf("application/x-www-form-urlencoded") >= 0) { if (dispatch()) { requestProcessed = true; return; } } if ( /*this.method == "GET" &&*/ httpGetFile(strContType)) { // }else if ( dispatch() ){ } else { respondNotFound(strErr); } } } requestProcessed = true; } }
public String getFile() { LOG.TRACE("getFile"); if (uri != null) { String path = uri.getPath(); if (path != null) { int s0 = path.lastIndexOf('/'); int s1 = path.lastIndexOf('\\'); if (s1 > s0) s0 = s1; if (s0 < 0) s0 = 0; return path.substring(s0); } } return null; }
void callLoginCallback(SyncNotification oNotify, int nErrCode, String strMessage) { try { if (getSync().isStoppedByUser()) return; String strBody = "error_code=" + nErrCode; strBody += "&error_message=" + URI.urlEncode(strMessage != null ? strMessage : ""); strBody += "&rho_callback=1"; LOG.INFO("Login callback: " + oNotify.toString() + ". Body: " + strBody); callNotify(oNotify, strBody); } catch (Exception exc) { LOG.ERROR("Call Login callback failed.", exc); } }
void respondMoved(String location) { responseCode = HTTP_MOVED_PERM; responseMsg = "Moved Permanently"; String strLoc = location; if (strLoc.startsWith("/apps")) strLoc = strLoc.substring(5); String strQuery = uri.getQueryString(); if (strQuery != null && strQuery.length() > 0) strLoc += "?" + strQuery; resHeaders.addProperty("Location", strLoc); contentLength = 0; responseData = new ByteArrayInputStream("".getBytes()); }
String getContentType() { String contType = reqHeaders.getProperty("Content-Type"); if (contType == null || contType.length() == 0) contType = reqHeaders.getProperty("content-type"); if (contType != null && contType.length() > 0) return contType; String path = uri.getPath(); int nPoint = path.lastIndexOf('.'); String strExt = ""; if (nPoint > 0) strExt = path.substring(nPoint + 1); if (strExt.equals("png")) return "image/png"; else if (strExt.equals("jpeg")) return "image/jpeg"; else if (strExt.equals("jpg")) return "image/jpg"; else if (strExt.equals("js")) return "application/javascript"; else if (strExt.equals("css")) return "text/css"; else if (strExt.equals("gif")) return "image/gif"; else if (strExt.equals("html") || strExt.equals("htm")) return "text/html"; else if (strExt.equals("txt")) return "text/plain"; return ""; }
public HttpConnection getResource(RequestedResource resource, BrowserContent referrer) { if (resource == null) return null; String url = resource.getUrl(); if (url == null || url.endsWith("/favicon.ico")) return null; try { if (referrer == null || URI.isLocalData(url) || !m_bLoadImageAsync) { boolean bLocalHost = RhodesApp.getInstance().isRhodesAppUrl(url); if (bLocalHost && m_connResource != null) { com.rho.net.RhoConnection rhoConn = (com.rho.net.RhoConnection) ((com.rho.net.bb.NativeBBHttpConnection) m_connResource).getNativeConnection(); rhoConn.resetUrl(url); Utilities.makeConnection(url, resource.getRequestHeaders(), null, m_connResource); return m_connResource; } else { HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null, null); // if (bLocalHost) // m_connResource = connection; return connection; } } else { SecondaryResourceFetchThread.enqueue(resource, referrer); } } catch (Exception exc) { LOG.ERROR("getResource failed.", exc); } return null; /* // check if this is cache-only request if (resource.isCacheOnly()) { // no cache support return null; } String url = resource.getUrl(); if (url == null) { return null; } try{ // if referrer is null we must return the connection if (referrer == null) { HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null); return connection; } else { if ( URI.isLocalHost(url) || URI.isLocalData(url)) { HttpConnection connection = Utilities.makeConnection(url, resource.getRequestHeaders(), null); return connection; }else { // if referrer is provided we can set up the connection on a separate thread SecondaryResourceFetchThread.enqueue(resource, referrer); } } }catch(Exception exc) { LOG.ERROR("getResource failed.", exc); } return null;*/ }
void doFireSyncNotification( SyncSource src, boolean bFinish, int nErrCode, String strError, String strParams, String strServerError) { if (getSync().isStoppedByUser()) return; try { SyncNotification pSN = null; String strBody = ""; boolean bRemoveAfterFire = bFinish; { synchronized (m_mxSyncNotifications) { pSN = getSyncNotifyBySrc(src); if (pSN == null) return; strBody = ""; if (src != null) { strBody += "total_count=" + src.getTotalCount(); strBody += "&processed_count=" + src.getCurPageCount(); strBody += "&processed_objects_count=" + getLastSyncObjectCount(src.getID()); strBody += "&cumulative_count=" + src.getServerObjectsCount(); strBody += "&source_id=" + src.getID(); strBody += "&source_name=" + src.getName(); } if (strParams.length() > 0) strBody += (strBody.length() > 0 ? "&" : "") + strParams; else strBody += (strBody.length() > 0 ? "&" : "") + "sync_type=incremental"; strBody += "&status="; if (bFinish) { if (nErrCode == RhoAppAdapter.ERR_NONE) { if (getSync().isSchemaChanged()) strBody += "schema_changed"; else strBody += (src == null && strParams.length() == 0) ? "complete" : "ok"; } else { if (getSync().isStoppedByUser()) nErrCode = RhoAppAdapter.ERR_CANCELBYUSER; strBody += "error"; strBody += "&error_code=" + nErrCode; if (strError != null && strError.length() > 0) strBody += "&error_message=" + URI.urlEncode(strError); else if (src != null) strBody += "&error_message=" + URI.urlEncode(src.m_strError); if (strServerError != null && strServerError.length() > 0) strBody += "&" + strServerError; else if (src != null && src.m_strServerError != null && src.m_strServerError.length() > 0) strBody += "&" + src.m_strServerError; } if (src != null) strBody += makeCreateObjectErrorBody(src.getID()); } else strBody += "in_progress"; strBody += "&rho_callback=1"; if (pSN.m_strParams != null && pSN.m_strParams.length() > 0) { if (!pSN.m_strParams.startsWith("&")) strBody += "&"; strBody += pSN.m_strParams; } bRemoveAfterFire = bRemoveAfterFire && pSN.m_bRemoveAfterFire; } } if (bRemoveAfterFire) clearNotification(src); LOG.INFO( "Fire notification. Source : " + (src != null ? (src).getName() : "") + "; " + pSN.toString()); if (callNotify(pSN, strBody)) clearNotification(src); } catch (Exception exc) { LOG.ERROR("Fire notification failed.", exc); } }
protected boolean dispatch() throws IOException { // LOG.INFO("dispatch start : " + uri.getPath()); UrlParser up = new UrlParser(uri.getPath()); String apps = up.next(); String application; if (apps.equalsIgnoreCase("apps")) application = up.next(); else application = apps; String model = up.next(); if (model == null || model.length() == 0) return false; if (checkRhoExtensions(application, model)) return true; // Convert CamelCase to underscore_case StringBuffer cName = new StringBuffer(); byte[] modelname = model.getBytes(); char ch; for (int i = 0; i != model.length(); ++i) { if (modelname[i] >= (byte) 'A' && modelname[i] <= (byte) 'Z') { ch = (char) (modelname[i] + 0x20); if (i != 0) cName.append('_'); } else ch = (char) modelname[i]; cName.append(ch); } String controllerName = cName.toString(); String strCtrl = "apps/" + application + '/' + model + '/' + controllerName + "_controller"; if (RhoSupport.findClass(strCtrl) == null) { strCtrl = "apps/" + application + '/' + model + '/' + "controller"; if (RhoSupport.findClass(strCtrl) == null) return false; } Properties reqHash = new Properties(); String actionid = up.next(); String actionnext = up.next(); if (actionid != null && actionid.length() > 0) { if (actionid.length() > 6 && actionid.startsWith("%7B") && actionid.endsWith("%7D")) actionid = "{" + actionid.substring(3, actionid.length() - 3) + "}"; if (actionid.length() > 2 && actionid.charAt(0) == '{' && actionid.charAt(actionid.length() - 1) == '}') { reqHash.setProperty("id", actionid); reqHash.setProperty("action", actionnext); } else { reqHash.setProperty("id", actionnext); reqHash.setProperty("action", actionid); } } reqHash.setProperty("application", application); reqHash.setProperty("model", model); doDispatch(reqHash, null); if (actionid != null && actionid.length() > 2 && actionid.charAt(0) == '{' && actionid.charAt(actionid.length() - 1) == '}') SyncThread.getInstance().addobjectnotify_bysrcname(model, actionid); return true; }
public String getHost() { LOG.TRACE("getHost: " + uri.getHost()); return uri.getHost(); }
public int getPort() { LOG.TRACE("getPort: " + uri.getPort()); return uri.getPort(); }
public String getProtocol() { LOG.TRACE("getProtocol: " + uri.getScheme()); return uri.getScheme(); }
public String getQuery() { LOG.TRACE("getQuery: " + uri.getQueryString()); return uri.getQueryString(); }
public String getRef() { LOG.TRACE("getRef: " + uri.getFragment()); return uri.getFragment() != null ? uri.getFragment() : ""; }