com.taobao.weex.adapter.IWXHttpAdapter Java Examples
The following examples show how to use
com.taobao.weex.adapter.IWXHttpAdapter.
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: WXStreamModule.java From ucar-weex-core with Apache License 2.0 | 6 votes |
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){ WXRequest wxRequest = new WXRequest(); wxRequest.method = options.getMethod(); wxRequest.url = mWXSDKInstance.rewriteUri(Uri.parse(options.getUrl()), URIAdapter.REQUEST).toString(); wxRequest.body = options.getBody(); wxRequest.timeoutMs = options.getTimeout(); if(options.getHeaders()!=null) if (wxRequest.paramMap == null) { wxRequest.paramMap = options.getHeaders(); }else{ wxRequest.paramMap.putAll(options.getHeaders()); } IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter; if (adapter != null) { adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback)); }else{ WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed."); } }
Example #2
Source File: WXStreamModuleTest.java From weex with Apache License 2.0 | 6 votes |
@Test public void testFetchHeaderReceived() throws Exception{ IWXHttpAdapter adapter = new IWXHttpAdapter() { @Override public void sendRequest(WXRequest request, OnHttpListener listener) { Map<String,List<String>> headers = new HashMap<>(); headers.put("key", Arrays.asList("someval")); listener.onHeadersReceived(200,headers); } }; WXStreamModule streamModule = new WXStreamModule(adapter); Callback cb = new Callback(); streamModule.fetch("{'url':'http://www.taobao.com'}",null,cb); assert ((Map<String,String>)cb.mData.get("headers")).get("key").equals("someval"); }
Example #3
Source File: WXStreamModule.java From weex with Apache License 2.0 | 6 votes |
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){ WXRequest wxRequest = new WXRequest(); wxRequest.method = options.getMethod(); wxRequest.url = options.getUrl(); wxRequest.body = options.getBody(); if(options.getHeaders()!=null) if (wxRequest.paramMap == null) { wxRequest.paramMap = options.getHeaders(); }else{ wxRequest.paramMap.putAll(options.getHeaders()); } IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter; if (adapter != null) { adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback)); }else{ WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed."); } }
Example #4
Source File: WXStreamModuleTest.java From weex-uikit with MIT License | 6 votes |
@Test public void testFetchHeaderReceived() throws Exception{ IWXHttpAdapter adapter = new IWXHttpAdapter() { @Override public void sendRequest(WXRequest request, OnHttpListener listener) { Map<String,List<String>> headers = new HashMap<>(); headers.put("key", Arrays.asList("someval")); listener.onHeadersReceived(200,headers); } }; WXStreamModule streamModule = createModule(adapter); Callback cb = new Callback(); streamModule.fetch("{'url':'http://www.taobao.com'}",null,cb); assert ((Map<String,String>)cb.mData.get("headers")).get("key").equals("someval"); }
Example #5
Source File: WXStreamModule.java From weex-uikit with MIT License | 6 votes |
private void sendRequest(Options options,ResponseCallback callback,JSCallback progressCallback){ WXRequest wxRequest = new WXRequest(); wxRequest.method = options.getMethod(); wxRequest.url = mWXSDKInstance.rewriteUri(Uri.parse(options.getUrl()), URIAdapter.REQUEST).toString(); wxRequest.body = options.getBody(); wxRequest.timeoutMs = options.getTimeout(); if(options.getHeaders()!=null) if (wxRequest.paramMap == null) { wxRequest.paramMap = options.getHeaders(); }else{ wxRequest.paramMap.putAll(options.getHeaders()); } IWXHttpAdapter adapter = ( mAdapter==null && mWXSDKInstance != null) ? mWXSDKInstance.getWXHttpAdapter() : mAdapter; if (adapter != null) { adapter.sendRequest(wxRequest, new StreamHttpListener(callback,progressCallback)); }else{ WXLogUtils.e("WXStreamModule","No HttpAdapter found,request failed."); } }
Example #6
Source File: WXStreamModuleTest.java From ucar-weex-core with Apache License 2.0 | 6 votes |
@Test public void testFetchHeaderReceived() throws Exception{ IWXHttpAdapter adapter = new IWXHttpAdapter() { @Override public void sendRequest(WXRequest request, OnHttpListener listener) { Map<String,List<String>> headers = new HashMap<>(); headers.put("key", Arrays.asList("someval")); listener.onHeadersReceived(200,headers); } }; WXStreamModule streamModule = createModule(adapter); Callback cb = new Callback(); streamModule.fetch("{'url':'http://www.taobao.com'}",null,cb); assert ((Map<String,String>)cb.mData.get("headers")).get("key").equals("someval"); }
Example #7
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 #8
Source File: WXSDKEngine.java From weex with Apache License 2.0 | 5 votes |
@Deprecated public static void init(Application application, String framework, IWXUserTrackAdapter utAdapter, IWXImgLoaderAdapter imgLoaderAdapter, IWXHttpAdapter httpAdapter) { initialize(application, new InitConfig.Builder() .setUtAdapter(utAdapter) .setHttpAdapter(httpAdapter) .setImgAdapter(imgLoaderAdapter) .build() ); }
Example #9
Source File: WXSDKEngine.java From weex-uikit with MIT License | 5 votes |
@Deprecated public static void init(Application application, String framework, IWXUserTrackAdapter utAdapter, IWXImgLoaderAdapter imgLoaderAdapter, IWXHttpAdapter httpAdapter) { initialize(application, new InitConfig.Builder() .setUtAdapter(utAdapter) .setHttpAdapter(httpAdapter) .setImgAdapter(imgLoaderAdapter) .build() ); }
Example #10
Source File: WXSDKInstance.java From weex-uikit with MIT License | 5 votes |
private void renderByUrlInternal(String pageName, final String url, Map<String, Object> options, final String jsonInitData, final WXRenderStrategy flag) { ensureRenderArchor(); pageName = wrapPageName(pageName, url); mBundleUrl = url; Map<String, Object> renderOptions = options; if (renderOptions == null) { renderOptions = new HashMap<>(); } if (!renderOptions.containsKey(BUNDLE_URL)) { renderOptions.put(BUNDLE_URL, url); } Uri uri = Uri.parse(url); if (uri != null && TextUtils.equals(uri.getScheme(), "file")) { render(pageName, WXFileUtils.loadAsset(assembleFilePath(uri), mContext), renderOptions, jsonInitData, flag); return; } IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter(); WXRequest wxRequest = new WXRequest(); wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString(); if (wxRequest.paramMap == null) { wxRequest.paramMap = new HashMap<String, String>(); } wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig())); adapter.sendRequest(wxRequest, new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis())); }
Example #11
Source File: WXSDKEngine.java From ucar-weex-core with Apache License 2.0 | 5 votes |
@Deprecated public static void init(Application application, String framework, IWXUserTrackAdapter utAdapter, IWXImgLoaderAdapter imgLoaderAdapter, IWXHttpAdapter httpAdapter) { initialize(application, new InitConfig.Builder() .setUtAdapter(utAdapter) .setHttpAdapter(httpAdapter) .setImgAdapter(imgLoaderAdapter) .build() ); }
Example #12
Source File: WXSDKInstance.java From ucar-weex-core with Apache License 2.0 | 5 votes |
private void renderByUrlInternal(String pageName, final String url, Map<String, Object> options, final String jsonInitData, final WXRenderStrategy flag) { ensureRenderArchor(); pageName = wrapPageName(pageName, url); mBundleUrl = url; if(WXSDKManager.getInstance().getValidateProcessor()!=null) { mNeedValidate = WXSDKManager.getInstance().getValidateProcessor().needValidate(mBundleUrl); } Map<String, Object> renderOptions = options; if (renderOptions == null) { renderOptions = new HashMap<>(); } if (!renderOptions.containsKey(BUNDLE_URL)) { renderOptions.put(BUNDLE_URL, url); } Uri uri = Uri.parse(url); if (uri != null && TextUtils.equals(uri.getScheme(), "file")) { render(pageName, WXFileUtils.loadFileOrAsset(assembleFilePath(uri), mContext), renderOptions, jsonInitData, flag); return; } IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter(); WXRequest wxRequest = new WXRequest(); wxRequest.url = rewriteUri(Uri.parse(url),URIAdapter.BUNDLE).toString(); if (wxRequest.paramMap == null) { wxRequest.paramMap = new HashMap<String, String>(); } wxRequest.paramMap.put(KEY_USER_AGENT, WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig())); WXHttpListener httpListener = new WXHttpListener(pageName, renderOptions, jsonInitData, flag, System.currentTimeMillis()); httpListener.setSDKInstance(this); adapter.sendRequest(wxRequest, (IWXHttpAdapter.OnHttpListener) httpListener); }
Example #13
Source File: WXStreamModule.java From weex with Apache License 2.0 | 4 votes |
public WXStreamModule(IWXHttpAdapter adapter){ mAdapter = adapter; }
Example #14
Source File: WXStreamModule.java From ucar-weex-core with Apache License 2.0 | 4 votes |
public WXStreamModule(IWXHttpAdapter adapter){ mAdapter = adapter; }
Example #15
Source File: InitConfig.java From ucar-weex-core with Apache License 2.0 | 4 votes |
public IWXHttpAdapter getHttpAdapter() { return httpAdapter; }
Example #16
Source File: WXSDKEngine.java From weex with Apache License 2.0 | 4 votes |
public static void setIWXHttpAdapter(IWXHttpAdapter IWXHttpAdapter) { WXSDKManager.getInstance().setIWXHttpAdapter(IWXHttpAdapter); }
Example #17
Source File: WXSDKEngine.java From weex with Apache License 2.0 | 4 votes |
public static IWXHttpAdapter getIWXHttpAdapter() { return WXSDKManager.getInstance().getIWXHttpAdapter(); }
Example #18
Source File: InitConfig.java From ucar-weex-core with Apache License 2.0 | 4 votes |
public Builder setHttpAdapter(IWXHttpAdapter httpAdapter) { this.httpAdapter = httpAdapter; return this; }
Example #19
Source File: WXSDKInstance.java From weex with Apache License 2.0 | 4 votes |
public IWXHttpAdapter getWXHttpAdapter() { return WXSDKManager.getInstance().getIWXHttpAdapter(); }
Example #20
Source File: InitConfig.java From weex with Apache License 2.0 | 4 votes |
public Builder setHttpAdapter(IWXHttpAdapter httpAdapter) { this.httpAdapter = httpAdapter; return this; }
Example #21
Source File: InitConfig.java From weex with Apache License 2.0 | 4 votes |
public IWXHttpAdapter getHttpAdapter() { return httpAdapter; }
Example #22
Source File: WXSDKManager.java From weex with Apache License 2.0 | 4 votes |
void setIWXHttpAdapter(IWXHttpAdapter IWXHttpAdapter) { mIWXHttpAdapter = IWXHttpAdapter; }
Example #23
Source File: WXStreamModule.java From weex-uikit with MIT License | 4 votes |
public WXStreamModule(IWXHttpAdapter adapter){ mAdapter = adapter; }
Example #24
Source File: WXSDKInstance.java From ucar-weex-core with Apache License 2.0 | 4 votes |
public IWXHttpAdapter getWXHttpAdapter() { return WXSDKManager.getInstance().getIWXHttpAdapter(); }
Example #25
Source File: WXStreamModuleTest.java From weex-uikit with MIT License | 4 votes |
private WXStreamModule createModule(IWXHttpAdapter adapter){ WXStreamModule m = new WXStreamModule(adapter); m.mWXSDKInstance = WXSDKInstanceTest.createInstance(); return m; }
Example #26
Source File: WXSDKEngine.java From weex-uikit with MIT License | 4 votes |
public static IWXHttpAdapter getIWXHttpAdapter() { return WXSDKManager.getInstance().getIWXHttpAdapter(); }
Example #27
Source File: WXSDKInstance.java From weex-uikit with MIT License | 4 votes |
public IWXHttpAdapter getWXHttpAdapter() { return WXSDKManager.getInstance().getIWXHttpAdapter(); }
Example #28
Source File: WXSDKEngine.java From ucar-weex-core with Apache License 2.0 | 4 votes |
public static IWXHttpAdapter getIWXHttpAdapter() { return WXSDKManager.getInstance().getIWXHttpAdapter(); }
Example #29
Source File: InitConfig.java From weex-uikit with MIT License | 4 votes |
public Builder setHttpAdapter(IWXHttpAdapter httpAdapter) { this.httpAdapter = httpAdapter; return this; }
Example #30
Source File: InitConfig.java From weex-uikit with MIT License | 4 votes |
public IWXHttpAdapter getHttpAdapter() { return httpAdapter; }