public static int getErrorFromResponse(NetResponse resp) { if ( resp.isUnathorized() ) return ERR_UNATHORIZED; if ( !resp.isOK() ) return ERR_REMOTESERVER; return ERR_NONE; }
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))); }
void processResponse(NetResponse resp) { if (resp.isOK() && m_mapHeaders != null) { String strContType = null; m_mapHeaders.TryGetValue("content-type", out strContType); if (strContType != null && strContType.indexOf("application/json") >= 0) { try{ m_valBody = fastJSON.RJSONTokener.JsonDecode(resp.getCharData()); return; }catch (Exception exc) { LOG.ERROR("Incorrect json body.", exc); } } } m_valBody = CRhoRuby.create_string(resp.getCharData()); }
public NetResponse pullCookies(String strUrl, String strBody, IRhoSession oSession) { Hashtable <String, String> headers = new Hashtable <String, String>(); m_bCancel = false; NetResponse resp = doRequest/*Try*/ ("POST", strUrl, strBody, oSession, headers); if (resp.isOK()) { String strCookie = resp.getCookies(); if (strCookie == null || strCookie.length() == 0) { strCookie = "rho_empty"; } resp.setCharData(strCookie); LOG.INFO("pullCookies: " + resp.getCharData()); } return(resp); }
void callNotify(NetResponse resp, int nError ) { if (m_bInternal) return; m_strResBody = "rho_callback=1"; m_strResBody += "&status="; if ( nError > 0 ) { m_strResBody += "error&error_code=" + nError; }else { if ( resp.isOK() ) m_strResBody += "ok"; else { m_strResBody += "error&error_code="; m_strResBody += RhoAppAdapter.getErrorFromResponse(resp); //if ( resp.isResponseRecieved()) m_strResBody += "&http_error=" + resp.getRespCode(); } String cookies = resp.getCookies(); if (cookies.length()>0) m_strResBody += "&cookies=" + URI.urlEncode(cookies); String strHeaders = makeHeadersString(); if (strHeaders.length() > 0 ) m_strResBody += "&" + strHeaders; m_strResBody += "&" + RHODESAPP().addCallbackObject(m_valBody, "body"); } if ( m_strCallbackParams.length() > 0 ) m_strResBody += "&" + m_strCallbackParams; if ( m_strCallback.length() > 0 ) { try{ String strFullUrl = m_pNetRequest.resolveUrl(m_strCallback); NetResponse resp1 = m_pNetRequest.pushData( strFullUrl, m_strResBody, null ); if ( !resp1.isOK() ) LOG.ERROR("AsyncHttp notification failed. Code: " + resp1.getRespCode() + "; Error body: " + resp1.getCharData() ); }catch(Exception exc) { LOG.ERROR("Async http callback failed.", exc); } } }
void processResponse(NetResponse resp ) { if (resp.isOK() && m_mapHeaders != null) { String strContType = null; m_mapHeaders.TryGetValue("content-type", out strContType); if ( strContType != null && strContType.indexOf("application/json") >=0 ) { try{ m_valBody = fastJSON.RJSONTokener.JsonDecode(resp.getCharData()); return; }catch(Exception exc) { LOG.ERROR("Incorrect json body.", exc); } } } m_valBody = CRhoRuby.create_string(resp.getCharData()); }
void callNotify(NetResponse resp, int nError) { if (m_bInternal) { return; } m_strResBody = "rho_callback=1"; m_strResBody += "&status="; if (nError > 0) { m_strResBody += "error&error_code=" + nError; } else { if (resp.isOK()) { m_strResBody += "ok"; } else { m_strResBody += "error&error_code="; m_strResBody += RhoAppAdapter.getErrorFromResponse(resp); //if ( resp.isResponseRecieved()) m_strResBody += "&http_error=" + resp.getRespCode(); } String cookies = resp.getCookies(); if (cookies.length() > 0) { m_strResBody += "&cookies=" + URI.urlEncode(cookies); } String strHeaders = makeHeadersString(); if (strHeaders.length() > 0) { m_strResBody += "&" + strHeaders; } m_strResBody += "&" + RHODESAPP().addCallbackObject(m_valBody, "body"); } if (m_strCallbackParams.length() > 0) { m_strResBody += "&" + m_strCallbackParams; } if (m_strCallback.length() > 0) { try{ String strFullUrl = m_pNetRequest.resolveUrl(m_strCallback); NetResponse resp1 = m_pNetRequest.pushData(strFullUrl, m_strResBody, null); if (!resp1.isOK()) { LOG.ERROR("AsyncHttp notification failed. Code: " + resp1.getRespCode() + "; Error body: " + resp1.getCharData()); } }catch (Exception exc) { LOG.ERROR("Async http callback failed.", exc); } } }