public static int getErrorFromResponse(NetResponse resp) { if ( resp.isUnathorized() ) return ERR_UNATHORIZED; if ( !resp.isOK() ) return ERR_REMOTESERVER; return ERR_NONE; }
private NetResponse makeResponse(String strRespBody, int nErrorCode) { NetResponse pResp = new NetResponse(strRespBody != null ? strRespBody : "", nErrorCode); if (pResp.isSuccess()) { if (m_strCookies == "" && m_strRespBody.Contains("rhoconnect_session")) { m_strRespBody = m_strRespBody.Replace('{', ' '); m_strRespBody = m_strRespBody.Replace('}', ' '); m_strRespBody = m_strRespBody.Replace('"', ' '); string[] cookies = m_strRespBody.Split(':'); m_strCookies = cookies[1].Trim(); m_strCookies = Uri.UnescapeDataString(m_strCookies); } pResp.setCookies(m_strCookies); } return(pResp); }
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); }
private NetResponse makeResponse(String strRespBody, int nErrorCode) { NetResponse pResp = new NetResponse(strRespBody != null ? strRespBody : "", nErrorCode ); if (pResp.isSuccess()) pResp.setCookies(m_strCookies); return pResp; }
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); } } }
public void execute() { NetResponse resp = null; try { switch (m_eCmd) { case hcGet: ///m_pNetRequest.setIgnoreSuffixOnSim(false); resp = m_pNetRequest.doRequest(m_params.getString("http_command", "GET"), m_params.getString("url"), m_params.getString("body"), null, m_mapHeaders); break; case hcPost: ///m_pNetRequest.setIgnoreSuffixOnSim(false); resp = m_pNetRequest.doRequest(m_params.getString("http_command", "POST"), m_params.getString("url"), m_params.getString("body"), null, m_mapHeaders); break; case hcDownload: resp = m_pNetRequest.pullFile(m_params.getString("url"), m_params.getString("filename"), null, m_mapHeaders); break; case hcUpload: { Vector <NetRequest.MultipartItem> /*Ptr<net::CMultipartItem*>*/ arMultipartItems = new Vector <NetRequest.MultipartItem>(); RhoParamArray arParams = new RhoParamArray(m_params, "multipart"); if (arParams.size() > 0) { for (int i = 0; i < arParams.size(); i++) { RhoParams oItem = arParams.getItem(i); NetRequest.MultipartItem pItem = new NetRequest.MultipartItem(); String strBody = oItem.getString("body"); if (strBody.length() > 0) { pItem.m_strBody = strBody; pItem.m_strContentType = oItem.getString("content_type", "application/x-www-form-urlencoded"); } else { pItem.m_strFilePath = oItem.getString("filename"); pItem.m_strContentType = oItem.getString("content_type", "application/octet-stream"); } pItem.m_strName = oItem.getString("name"); pItem.m_strFileName = oItem.getString("filename_base"); arMultipartItems.addElement(pItem); } } else { NetRequest.MultipartItem pItem = new NetRequest.MultipartItem(); pItem.m_strFilePath = m_params.getString("filename"); pItem.m_strContentType = m_params.getString("file_content_type", "application/octet-stream"); pItem.m_strName = m_params.getString("name"); pItem.m_strFileName = m_params.getString("filename_base"); arMultipartItems.addElement(pItem); String strBody = m_params.getString("body"); if (strBody.length() > 0) { NetRequest.MultipartItem pItem2 = new NetRequest.MultipartItem(); pItem2.m_strBody = strBody; pItem2.m_strContentType = (String)m_mapHeaders.get("content-type"); arMultipartItems.addElement(pItem2); } } resp = m_pNetRequest.pushMultipartData(m_params.getString("url"), arMultipartItems, null, m_mapHeaders); break; } } if (!m_pNetRequest.isCancelled()) { processResponse(resp); callNotify(resp, 0); } }catch (IOException exc) { LOG.ERROR("command failed: " + m_eCmd + "url: " + m_params.getString("url"), exc); callNotify(null, RhoAppAdapter.ERR_NETWORK); }catch (Exception exc) { LOG.ERROR("command crashed: " + m_eCmd + "url: " + m_params.getString("url"), exc); callNotify(null, RhoAppAdapter.ERR_RUNTIME); } }
private NetResponse makeResponse(String strRespBody, int nErrorCode) { NetResponse pResp = new NetResponse(strRespBody != null ? strRespBody : "", nErrorCode ); if (pResp.isSuccess()) { if (m_strCookies == "" && m_strRespBody != null && m_strRespBody.Contains("rhoconnect_session")) { m_strRespBody = m_strRespBody.Replace('{', ' '); m_strRespBody = m_strRespBody.Replace('}', ' '); m_strRespBody = m_strRespBody.Replace('"', ' '); string[] cookies = m_strRespBody.Split(':'); m_strCookies = cookies[1].Trim(); m_strCookies = Uri.UnescapeDataString(m_strCookies); } pResp.setCookies(m_strCookies); } return pResp; }