void setSearchNotification(String strUrl, String strParams) throws Exception { LOG.INFO("Set search notification. Url :" + strUrl + "; Params: " + strParams); String strFullUrl = getNet().resolveUrl(strUrl); if (strFullUrl.length() > 0) { synchronized (m_mxSyncNotifications) { m_pSearchNotification = new SyncNotification(strFullUrl, strParams, true); } LOG.INFO(" Done Set search notification. Url :" + strFullUrl + "; Params: " + strParams); } }
private void createBrowserField() { LOG.INFO("Use BrowserField5"); m_oBrowserField = new BrowserField(m_oConfig); m_oBrowserField .getRenderingOptions() .setProperty(RenderingOptions.CORE_OPTIONS_GUID, RenderingOptions.ALLOW_POPUPS, true); m_oController = new RhoProtocolController(m_oBrowserField); m_oConfig.setProperty(BrowserFieldConfig.CONTROLLER, m_oController); BrowserFieldListener _listener = new BrowserFieldListener() { public void documentLoaded(BrowserField browserField, org.w3c.dom.Document document) throws Exception { synchronized (Application.getEventLock()) { m_oMainScreen.deleteAll(); m_oMainScreen.add(m_oBrowserField); } } /* public void downloadProgress(BrowserField browserField, net.rim.device.api.browser.field.ContentReadEvent event)throws Exception { //Add your code here. }*/ }; m_oBrowserField.addListener(_listener); }
public static void stopSync() throws Exception { LOG.INFO("STOP sync"); if (getSyncEngine().isSyncing()) { getSyncEngine().stopSyncByUser(); getInstance().stopWait(); int nWait = 0; // while( nWait < 30000 && getSyncEngine().getState() != SyncEngine.esNone ) while (nWait < 30000 && DBAdapter.isAnyInsideTransaction()) try { Thread.sleep(100); nWait += 100; } catch (Exception e) { } // if (getSyncEngine().getState() != SyncEngine.esNone) if (DBAdapter.isAnyInsideTransaction()) { getSyncEngine().exitSync(); getInstance().stop(0); RhoClassFactory ptrFactory = getInstance().getFactory(); m_pInstance = null; Create(ptrFactory); } } }
void clearNotification(SyncSource src) { LOG.INFO("Clear notification. Source : " + (src != null ? src.getName() : "")); synchronized (m_mxSyncNotifications) { if (getSync().isSearch()) m_pSearchNotification = null; else m_mapSyncNotifications.remove(src.getID()); } }
void clearSyncNotification(int source_id) { LOG.INFO("Clear notification. Source ID: " + source_id); synchronized (m_mxSyncNotifications) { if (source_id == -1) // Clear all m_pAllNotification = null; else m_mapSyncNotifications.remove(new Integer(source_id)); } }
SyncThread(RhoClassFactory factory) throws Exception { super(factory); ThreadQueue.setLogCategory(LOG.getLogCategory()); if (RhoConf.getInstance().isExist("sync_poll_interval")) setPollInterval(RhoConf.getInstance().getInt("sync_poll_interval")); m_oSyncEngine = new SyncEngine(); m_oSyncEngine.setFactory(factory); m_oSyncEngine.setFactory(factory); LOG.INFO("sync_poll_interval: " + RhoConf.getInstance().getInt("sync_poll_interval")); LOG.INFO("syncserver: " + RhoConf.getInstance().getString("syncserver")); LOG.INFO("bulksync_state: " + RhoConf.getInstance().getInt("bulksync_state")); ClientRegister.Create(factory); if (RhoConf.getInstance().getString("syncserver").length() > 0) start(epLow); }
public NetResponse pullCookies(String strUrl, String strBody, IRhoSession oSession) throws Exception { Hashtable headers = new Hashtable(); m_bIgnoreSuffixOnSim = false; m_bCancel = false; NetResponse resp = doRequest /*Try*/("POST", strUrl, strBody, oSession, headers); if (resp.isOK()) { resp.setCharData(resp.getCookies()); LOG.INFO("pullCookies: " + resp.getCharData()); } return resp; }
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 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"); }
/* void setSyncNotification(int source_id, String strUrl, String strParams )throws Exception { LOG.INFO( "Set notification. Source ID: " + source_id + "; Url :" + strUrl + "; Params: " + strParams ); String strFullUrl = getNet().resolveUrl(strUrl); if ( source_id == -1 ) { synchronized(m_mxSyncNotifications) { m_pAllNotification = new SyncNotification( strFullUrl, strParams, false ); } LOG.INFO( " Done Set notification for all sources; Url :" + strFullUrl + "; Params: " + strParams ); }else { if ( strFullUrl.length() > 0 ) { synchronized(m_mxSyncNotifications){ m_mapSyncNotifications.put(new Integer(source_id),new SyncNotification( strFullUrl, strParams, true ) ); } LOG.INFO( " Done Set notification. Source ID: " + source_id + "; Url :" + strFullUrl + "; Params: " + strParams ); } } }*/ void setSyncNotification(int source_id, SyncNotification pNotify) { LOG.INFO( "Set notification. Source ID: " + source_id + ";" + (pNotify != null ? pNotify.toString() : "")); if (source_id == -1) { synchronized (m_mxSyncNotifications) { m_pAllNotification = pNotify; } } else { synchronized (m_mxSyncNotifications) { m_mapSyncNotifications.put(new Integer(source_id), pNotify); } } }
public void reportSyncStatus(String status, int error, String strDetails) { synchronized (m_mxSyncNotifications) { if (m_syncStatusListener != null && (isReportingEnabled() || error == RhoAppAdapter.ERR_SYNCVERSION)) { if (error == RhoAppAdapter.ERR_SYNCVERSION) status = RhoAppAdapter.getErrorText(error); else { if (strDetails.length() == 0) strDetails = RhoAppAdapter.getErrorText(error); status += (strDetails.length() > 0 ? RhoAppAdapter.getMessageText("details") + strDetails : ""); } LOG.INFO("Status: " + status); m_syncStatusListener.reportStatus(status, error); } } }
private static String makeClientCookie(Hashtable headers) throws IOException { if (headers == null) return ""; // ParsedCookie cookie = new ParsedCookie(); String strRes = ""; Enumeration valsHeaders = headers.elements(); Enumeration keysHeaders = headers.keys(); while (valsHeaders.hasMoreElements()) { String strName = (String) keysHeaders.nextElement(); String strValue = (String) valsHeaders.nextElement(); if (strName.equalsIgnoreCase("Set-Cookie")) { LOG.INFO("Set-Cookie: " + strValue); strRes += URI.parseCookie(strValue); } } return strRes; }
public NetResponse doRequest( String strMethod, String strUrl, String strBody, IRhoSession oSession, Hashtable headers) throws Exception { String strRespBody = null; InputStream is = null; OutputStream os = null; int code = -1; m_bCancel = false; try { closeConnection(); m_connection = RhoClassFactory.getNetworkAccess().connect(strUrl, m_bIgnoreSuffixOnSim); LOG.INFO("connection done"); if (oSession != null) { String strSession = oSession.getSession(); LOG.INFO("Cookie : " + (strSession != null ? strSession : "")); if (strSession != null && strSession.length() > 0) m_connection.setRequestProperty("Cookie", strSession); } // m_connection.setRequestProperty("Connection", "keep-alive"); // m_connection.setRequestProperty("Accept", // "application/x-www-form-urlencoded,application/json,text/html"); if (strBody != null && strBody.length() > 0) { if (oSession != null) m_connection.setRequestProperty("Content-Type", oSession.getContentType()); else m_connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); writeHeaders(headers); LOG.INFO("writeHeaders done"); m_connection.setRequestMethod(IHttpConnection.POST); os = m_connection.openOutputStream(); os.write(strBody.getBytes(), 0, strBody.length()); LOG.INFO("write body done"); } else { writeHeaders(headers); m_connection.setRequestMethod(strMethod); } code = m_connection.getResponseCode(); LOG.INFO("getResponseCode : " + code); is = m_connection.openInputStream(); LOG.INFO("openInputStream done"); readHeaders(headers); copyHashtable(m_OutHeaders, headers); if (code != IHttpConnection.HTTP_OK) { LOG.ERROR("Error retrieving data: " + code); if (code == IHttpConnection.HTTP_UNAUTHORIZED && oSession != null) oSession.logout(); // if ( code != IHttpConnection.HTTP_INTERNAL_ERROR ) { strRespBody = readFully(is, getResponseEncoding()); if (code == IHttpConnection.HTTP_MOVED_TEMPORARILY || code == IHttpConnection.HTTP_MOVED_PERMANENTLY) LOG.INFO("Response body: " + strRespBody); else LOG.TRACE("Response body: " + strRespBody); } } else { long len = m_connection.getLength(); LOG.INFO("fetchRemoteData data size:" + len); strRespBody = readFully(is, getResponseEncoding()); LOG.INFO("fetchRemoteData data readFully."); } } finally { if (is != null) try { is.close(); } catch (IOException exc) { } if (os != null) try { os.close(); } catch (IOException exc) { } closeConnection(); m_bIgnoreSuffixOnSim = true; } return makeResponse(strRespBody, code); }
public NetResponse pushMultipartData( String strUrl, Vector /*Ptr<CMultipartItem*>&*/ arItems, IRhoSession oSession, Hashtable /*<String,String>**/ headers) throws Exception { String strRespBody = null; InputStream is = null; OutputStream os = null; int code = -1; m_bCancel = false; try { closeConnection(); m_connection = RhoClassFactory.getNetworkAccess().connect(strUrl, false); if (oSession != null) { String strSession = oSession.getSession(); if (strSession != null && strSession.length() > 0) m_connection.setRequestProperty("Cookie", strSession); } m_connection.setRequestProperty("Connection", "keep-alive"); m_connection.setRequestProperty("content-type", szMultipartContType); writeHeaders(headers); m_connection.setRequestMethod(IHttpConnection.POST); // PUSH specific processMultipartItems(arItems); os = m_connection.openOutputStream(); // write all items for (int i = 0; i < (int) arItems.size(); i++) { MultipartItem oItem = (MultipartItem) arItems.elementAt(i); os.write(oItem.m_strDataPrefix.getBytes(), 0, oItem.m_strDataPrefix.length()); if (oItem.m_strFilePath.length() > 0) { SimpleFile file = null; InputStream fis = null; try { file = RhoClassFactory.createFile(); file.open(oItem.m_strFilePath, true, true); if (!file.isOpened()) { LOG.ERROR("File not found: " + oItem.m_strFilePath); throw new RuntimeException("File not found:" + oItem.m_strFilePath); } fis = file.getInputStream(); byte[] byteBuffer = new byte[1024 * 4]; int nRead = 0; do { nRead = fis.read(byteBuffer); if (nRead > 0) os.write(byteBuffer, 0, nRead); } while (nRead > 0); } finally { if (fis != null) try { fis.close(); } catch (IOException e) { } if (file != null) try { file.close(); } catch (IOException e) { } } } else { os.write(oItem.m_strBody.getBytes(), 0, oItem.m_strBody.length()); } } os.write(szMultipartPostfix.getBytes(), 0, szMultipartPostfix.length()); // os.flush(); // PUSH specific is = m_connection.openInputStream(); code = m_connection.getResponseCode(); LOG.INFO("getResponseCode : " + code); readHeaders(headers); copyHashtable(m_OutHeaders, headers); if (code != IHttpConnection.HTTP_OK) { LOG.ERROR("Error retrieving data: " + code); if (code == IHttpConnection.HTTP_UNAUTHORIZED) oSession.logout(); if (code != IHttpConnection.HTTP_INTERNAL_ERROR) strRespBody = readFully(is, getResponseEncoding()); } else { long len = m_connection.getLength(); LOG.INFO("fetchRemoteData data size:" + len); strRespBody = readFully(is, getResponseEncoding()); LOG.INFO("fetchRemoteData data readFully."); } } finally { try { if (is != null) is.close(); if (os != null) os.close(); closeConnection(); } catch (IOException exc2) { } } return makeResponse(strRespBody, code); }
NetResponse pullFile1( String strUrl, IRAFile file, long nStartPos, IRhoSession oSession, Hashtable headers) throws Exception { String strRespBody = null; InputStream is = null; int code = -1; try { closeConnection(); m_connection = RhoClassFactory.getNetworkAccess().connect(strUrl, true); if (oSession != null) { String strSession = oSession.getSession(); if (strSession != null && strSession.length() > 0) m_connection.setRequestProperty("Cookie", strSession); } m_connection.setRequestProperty("Connection", "keep-alive"); if (nStartPos > 0 || m_nMaxPacketSize > 0) { if (m_nMaxPacketSize > 0) m_connection.setRequestProperty( "Range", "bytes=" + nStartPos + "-" + (nStartPos + m_nMaxPacketSize - 1)); else m_connection.setRequestProperty("Range", "bytes=" + nStartPos + "-"); } writeHeaders(headers); m_connection.setRequestMethod(IHttpConnection.GET); code = m_connection.getResponseCode(); LOG.INFO("getResponseCode : " + code); m_nCurDownloadSize = 0; readHeaders(headers); if (code == IHttpConnection.HTTP_RANGENOTSATISFY) code = IHttpConnection.HTTP_PARTIAL_CONTENT; else { if (code != IHttpConnection.HTTP_OK && code != IHttpConnection.HTTP_PARTIAL_CONTENT) { LOG.ERROR("Error retrieving data: " + code); if (code == IHttpConnection.HTTP_UNAUTHORIZED) oSession.logout(); if (code != IHttpConnection.HTTP_INTERNAL_ERROR) { is = m_connection.openInputStream(); strRespBody = readFully(is, getResponseEncoding()); } } else { int nRead = 0; is = m_connection.openInputStream(); byte[] byteBuffer = new byte[1024 * 20]; do { nRead = /*bufferedReadByByte(m_byteBuffer, is);*/ is.read(byteBuffer); if (nRead > 0) { file.write(byteBuffer, 0, nRead); if (m_bFlushFileAfterWrite) file.sync(); m_nCurDownloadSize += nRead; } } while (!m_bCancel && nRead >= 0); if (code == IHttpConnection.HTTP_OK || (code == IHttpConnection.HTTP_PARTIAL_CONTENT && isFinishDownload())) m_nCurDownloadSize = 0; } } } finally { if (is != null) try { is.close(); } catch (IOException exc) { } closeConnection(); } return makeResponse(strRespBody != null ? strRespBody : "", code); }
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); } }
public static void rhoLogInfo(String msg) { LOG.INFO(msg); // LOG.ERROR(msg); }