com.taobao.weex.common.WXResponse Java Examples
The following examples show how to use
com.taobao.weex.common.WXResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WXSDKInstance.java From weex with Apache License 2.0 | 6 votes |
@Override public void onHttpFinish(WXResponse response) { mWXPerformance.networkTime = System.currentTimeMillis() - startRequestTime; WXLogUtils.renderPerformanceLog("networkTime", mWXPerformance.networkTime); if (response!=null && response.originalData!=null && TextUtils.equals("200", response.statusCode)) { String template = new String(response.originalData); render(pageName, template, options, jsonInitData, width, height, flag); } else if (TextUtils.equals(WXRenderErrorCode.WX_USER_INTERCEPT_ERROR, response.statusCode)) { WXLogUtils.d("user intercept"); onRenderError(WXRenderErrorCode.WX_USER_INTERCEPT_ERROR,response.errorMsg); } else { onRenderError(WXRenderErrorCode.WX_NETWORK_ERROR, response.errorMsg); } }
Example #2
Source File: WXStreamModule.java From ucar-weex-core with Apache License 2.0 | 5 votes |
@Override public void onHttpFinish(final WXResponse response) { //compatible with old sendhttp if(mCallback!=null){ mCallback.onResponse(response, mRespHeaders); } if(WXEnvironment.isApkDebugable()){ WXLogUtils.d("WXStreamModule",response!=null && response.originalData!=null?new String(response.originalData):"response data is NUll!"); } }
Example #3
Source File: WXStreamModuleTest.java From weex with Apache License 2.0 | 5 votes |
@Test public void testFetchStatus() throws Exception{ WXStreamModule streamModule = new WXStreamModule(new IWXHttpAdapter() { @Override public void sendRequest(WXRequest request, OnHttpListener listener) { WXResponse response = new WXResponse(); response.statusCode = "-1"; listener.onHttpFinish(response); } }); Callback finish = new Callback(); streamModule.fetch("",finish,null); assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT),Status.ERR_INVALID_REQUEST); streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}",finish,null); assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT),Status.ERR_CONNECT_FAILED); streamModule = new WXStreamModule(new IWXHttpAdapter() { @Override public void sendRequest(WXRequest request, OnHttpListener listener) { WXResponse response = new WXResponse(); response.statusCode = "302"; listener.onHttpFinish(response); } }); streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}",finish,null); assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT),Status.getStatusText("302")); }
Example #4
Source File: DefaultWXHttpAdapter.java From weex with Apache License 2.0 | 5 votes |
@Override public void sendRequest(final WXRequest request, final OnHttpListener listener) { if (listener != null) { listener.onHttpStart(); } execute(new Runnable() { @Override public void run() { WXResponse response = new WXResponse(); try { HttpURLConnection connection = openConnection(request, listener); Map<String,List<String>> headers = connection.getHeaderFields(); int responseCode = connection.getResponseCode(); if(listener != null){ listener.onHeadersReceived(responseCode,headers); } response.statusCode = String.valueOf(responseCode); if (responseCode >= 200 && responseCode<=299) { response.originalData = readInputStreamAsBytes(connection.getInputStream(), listener); } else { response.errorMsg = readInputStream(connection.getErrorStream(), listener); } if (listener != null) { listener.onHttpFinish(response); } } catch (IOException e) { e.printStackTrace(); response.statusCode = "-1"; response.errorCode="-1"; response.errorMsg=e.getMessage(); if(listener!=null){ listener.onHttpFinish(response); } } } }); }
Example #5
Source File: WXStreamModule.java From weex-uikit with MIT License | 5 votes |
@Override public void onHttpFinish(final WXResponse response) { //compatible with old sendhttp if(mCallback!=null){ mCallback.onResponse(response, mRespHeaders); } if(WXEnvironment.isApkDebugable()){ WXLogUtils.d("WXStreamModule",response!=null && response.originalData!=null?new String(response.originalData):"response data is NUll!"); } }
Example #6
Source File: WXStreamModuleTest.java From ucar-weex-core with Apache License 2.0 | 4 votes |
private WXResponse successResponse(){ WXResponse resp = new WXResponse(); resp.data = "data"; resp.statusCode = "200"; return resp; }
Example #7
Source File: WXSDKInstance.java From ucar-weex-core with Apache License 2.0 | 4 votes |
@Override public void onHttpFinish(WXResponse response) { if (this.instance != null && this.instance.getWXStatisticsListener() != null) { this.instance.getWXStatisticsListener().onHttpFinish(); } mWXPerformance.networkTime = System.currentTimeMillis() - startRequestTime; if(response.extendParams!=null){ Object actualNetworkTime=response.extendParams.get("actualNetworkTime"); mWXPerformance.actualNetworkTime=actualNetworkTime instanceof Long?(long)actualNetworkTime:0; WXLogUtils.renderPerformanceLog("actualNetworkTime", mWXPerformance.actualNetworkTime); Object pureNetworkTime=response.extendParams.get("pureNetworkTime"); mWXPerformance.pureNetworkTime=pureNetworkTime instanceof Long?(long)pureNetworkTime:0; WXLogUtils.renderPerformanceLog("pureNetworkTime", mWXPerformance.pureNetworkTime); Object connectionType=response.extendParams.get("connectionType"); mWXPerformance.connectionType=connectionType instanceof String?(String)connectionType:""; Object packageSpendTime=response.extendParams.get("packageSpendTime"); mWXPerformance.packageSpendTime=packageSpendTime instanceof Long ?(long)packageSpendTime:0; Object syncTaskTime=response.extendParams.get("syncTaskTime"); mWXPerformance.syncTaskTime=syncTaskTime instanceof Long ?(long)syncTaskTime:0; Object requestType=response.extendParams.get("requestType"); mWXPerformance.requestType=requestType instanceof String?(String)requestType:""; if("network".equals(requestType) && mUserTrackAdapter!=null){ WXPerformance performance=new WXPerformance(); if(!TextUtils.isEmpty(mBundleUrl)){ try { performance.args= Uri.parse(mBundleUrl).buildUpon().clearQuery().toString(); } catch (Exception e) { performance.args=pageName; } } if(!"200".equals(response.statusCode)){ performance.errCode=WXErrorCode.WX_ERR_JSBUNDLE_DOWNLOAD.getErrorCode(); performance.appendErrMsg(response.errorCode); performance.appendErrMsg("|"); performance.appendErrMsg(response.errorMsg); }else if("200".equals(response.statusCode) && (response.originalData==null || response.originalData.length<=0)){ performance.errCode=WXErrorCode.WX_ERR_JSBUNDLE_DOWNLOAD.getErrorCode(); performance.appendErrMsg(response.statusCode); performance.appendErrMsg("|template is null!"); }else { performance.errCode=WXErrorCode.WX_SUCCESS.getErrorCode(); } if (mUserTrackAdapter != null) { mUserTrackAdapter.commit(getContext(), null, IWXUserTrackAdapter.JS_DOWNLOAD, performance, null); } } } WXLogUtils.renderPerformanceLog("networkTime", mWXPerformance.networkTime); if (response!=null && response.originalData!=null && TextUtils.equals("200", response.statusCode)) { String template = new String(response.originalData); render(pageName, template, options, jsonInitData, flag); } else if (TextUtils.equals(WXRenderErrorCode.WX_USER_INTERCEPT_ERROR, response.statusCode)) { WXLogUtils.d("user intercept"); onRenderError(WXRenderErrorCode.WX_USER_INTERCEPT_ERROR,response.errorMsg); } else { onRenderError(WXRenderErrorCode.WX_NETWORK_ERROR, response.errorMsg); } }
Example #8
Source File: DefaultWXHttpAdapter.java From weex-uikit with MIT License | 4 votes |
@Override public void sendRequest(final WXRequest request, final OnHttpListener listener) { if (listener != null) { listener.onHttpStart(); } execute(new Runnable() { @Override public void run() { WXResponse response = new WXResponse(); IEventReporterDelegate reporter = getEventReporterDelegate(); try { HttpURLConnection connection = openConnection(request, listener); reporter.preConnect(connection, request.body); Map<String,List<String>> headers = connection.getHeaderFields(); int responseCode = connection.getResponseCode(); if(listener != null){ listener.onHeadersReceived(responseCode,headers); } reporter.postConnect(); response.statusCode = String.valueOf(responseCode); if (responseCode >= 200 && responseCode<=299) { InputStream rawStream = connection.getInputStream(); rawStream = reporter.interpretResponseStream(rawStream); response.originalData = readInputStreamAsBytes(rawStream, listener); } else { response.errorMsg = readInputStream(connection.getErrorStream(), listener); } if (listener != null) { listener.onHttpFinish(response); } } catch (IOException|IllegalArgumentException e) { e.printStackTrace(); response.statusCode = "-1"; response.errorCode="-1"; response.errorMsg=e.getMessage(); if(listener!=null){ listener.onHttpFinish(response); } if (e instanceof IOException) { reporter.httpExchangeFailed((IOException) e); } } } }); }
Example #9
Source File: WXSDKInstance.java From weex-uikit with MIT License | 4 votes |
@Override public void onHttpFinish(WXResponse response) { mWXPerformance.networkTime = System.currentTimeMillis() - startRequestTime; if(response.extendParams!=null){ Object actualNetworkTime=response.extendParams.get("actualNetworkTime"); mWXPerformance.actualNetworkTime=actualNetworkTime instanceof Long?(long)actualNetworkTime:0; WXLogUtils.renderPerformanceLog("actualNetworkTime", mWXPerformance.actualNetworkTime); Object pureNetworkTime=response.extendParams.get("pureNetworkTime"); mWXPerformance.pureNetworkTime=pureNetworkTime instanceof Long?(long)pureNetworkTime:0; WXLogUtils.renderPerformanceLog("pureNetworkTime", mWXPerformance.pureNetworkTime); Object connectionType=response.extendParams.get("connectionType"); mWXPerformance.connectionType=connectionType instanceof String?(String)connectionType:""; Object packageSpendTime=response.extendParams.get("packageSpendTime"); mWXPerformance.packageSpendTime=packageSpendTime instanceof Long ?(long)packageSpendTime:0; Object syncTaskTime=response.extendParams.get("syncTaskTime"); mWXPerformance.syncTaskTime=syncTaskTime instanceof Long ?(long)syncTaskTime:0; Object requestType=response.extendParams.get("requestType"); mWXPerformance.requestType=requestType instanceof String?(String)requestType:""; if("network".equals(requestType) && mUserTrackAdapter!=null){ WXPerformance performance=new WXPerformance(); if(!TextUtils.isEmpty(mBundleUrl)){ try { performance.args= Uri.parse(mBundleUrl).buildUpon().clearQuery().toString(); } catch (Exception e) { performance.args=pageName; } } if(!"200".equals(response.statusCode)){ performance.errCode=WXErrorCode.WX_ERR_JSBUNDLE_DOWNLOAD.getErrorCode(); performance.appendErrMsg(response.errorCode); performance.appendErrMsg("|"); performance.appendErrMsg(response.errorMsg); }else if("200".equals(response.statusCode) && (response.originalData==null || response.originalData.length<=0)){ performance.errCode=WXErrorCode.WX_ERR_JSBUNDLE_DOWNLOAD.getErrorCode(); performance.appendErrMsg(response.statusCode); performance.appendErrMsg("|template is null!"); }else { performance.errCode=WXErrorCode.WX_SUCCESS.getErrorCode(); } mUserTrackAdapter.commit(getContext(),null,IWXUserTrackAdapter.JS_DOWNLOAD,performance,null); } } WXLogUtils.renderPerformanceLog("networkTime", mWXPerformance.networkTime); if (response!=null && response.originalData!=null && TextUtils.equals("200", response.statusCode)) { String template = new String(response.originalData); render(pageName, template, options, jsonInitData, flag); } else if (TextUtils.equals(WXRenderErrorCode.WX_USER_INTERCEPT_ERROR, response.statusCode)) { WXLogUtils.d("user intercept"); onRenderError(WXRenderErrorCode.WX_USER_INTERCEPT_ERROR,response.errorMsg); } else { onRenderError(WXRenderErrorCode.WX_NETWORK_ERROR, response.errorMsg); } }
Example #10
Source File: WXStreamModuleTest.java From weex-uikit with MIT License | 4 votes |
private WXResponse successResponse(){ WXResponse resp = new WXResponse(); resp.data = "data"; resp.statusCode = "200"; return resp; }
Example #11
Source File: DefaultWXHttpAdapter.java From ucar-weex-core with Apache License 2.0 | 4 votes |
@Override public void sendRequest(final WXRequest request, final OnHttpListener listener) { if (listener != null) { listener.onHttpStart(); } execute(new Runnable() { @Override public void run() { WXResponse response = new WXResponse(); IEventReporterDelegate reporter = getEventReporterDelegate(); try { HttpURLConnection connection = openConnection(request, listener); reporter.preConnect(connection, request.body); Map<String,List<String>> headers = connection.getHeaderFields(); int responseCode = connection.getResponseCode(); if(listener != null){ listener.onHeadersReceived(responseCode,headers); } reporter.postConnect(); response.statusCode = String.valueOf(responseCode); if (responseCode >= 200 && responseCode<=299) { InputStream rawStream = connection.getInputStream(); rawStream = reporter.interpretResponseStream(rawStream); response.originalData = readInputStreamAsBytes(rawStream, listener); } else { response.errorMsg = readInputStream(connection.getErrorStream(), listener); } if (listener != null) { listener.onHttpFinish(response); } } catch (IOException|IllegalArgumentException e) { e.printStackTrace(); response.statusCode = "-1"; response.errorCode="-1"; response.errorMsg=e.getMessage(); if(listener!=null){ listener.onHttpFinish(response); } if (e instanceof IOException) { reporter.httpExchangeFailed((IOException) e); } } } }); }
Example #12
Source File: WXStreamModuleTest.java From weex with Apache License 2.0 | 4 votes |
private WXResponse successResponse(){ WXResponse resp = new WXResponse(); resp.data = "data"; resp.statusCode = "200"; return resp; }
Example #13
Source File: IWXHttpAdapter.java From weex-uikit with MIT License | 2 votes |
/** * http response finish * @param response */ void onHttpFinish(WXResponse response);
Example #14
Source File: IWXHttpAdapter.java From weex with Apache License 2.0 | 2 votes |
/** * http response finish * @param response */ void onHttpFinish(WXResponse response);
Example #15
Source File: IWXHttpAdapter.java From ucar-weex-core with Apache License 2.0 | 2 votes |
/** * http response finish * @param response */ void onHttpFinish(WXResponse response);
Example #16
Source File: WXStreamModule.java From weex-uikit with MIT License | votes |
void onResponse(WXResponse response, Map<String, String> headers);
Example #17
Source File: WXStreamModule.java From ucar-weex-core with Apache License 2.0 | votes |
void onResponse(WXResponse response, Map<String, String> headers);