use of com.taobao.weex.adapter.IWXHttpAdapter in project weex-example by KalicyZhou.
the class WXStreamModuleTest method testFetchSuccessFinish.
@Test
public void testFetchSuccessFinish() throws Exception {
IWXHttpAdapter adapter = new IWXHttpAdapter() {
@Override
public void sendRequest(WXRequest request, OnHttpListener listener) {
listener.onHttpFinish(successResponse());
}
};
WXStreamModule streamModule = createModule(adapter);
Callback cb = new Callback();
streamModule.fetch("{'url':'http://www.taobao.com'}", cb, null);
assert (boolean) cb.mData.get("ok");
}
use of com.taobao.weex.adapter.IWXHttpAdapter in project weex-example by KalicyZhou.
the class WXStreamModuleTest method testFetchHeaderReceived.
@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");
}
use of com.taobao.weex.adapter.IWXHttpAdapter in project weex-example by KalicyZhou.
the class TypefaceUtil method downloadFontByNetwork.
private static void downloadFontByNetwork(final String url, final String fullPath, final String fontFamily) {
IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter();
if (adapter == null) {
WXLogUtils.e(TAG, "downloadFontByNetwork() IWXHttpAdapter == null");
return;
}
WXRequest request = new WXRequest();
request.url = url;
request.method = "GET";
adapter.sendRequest(request, new IWXHttpAdapter.OnHttpListener() {
@Override
public void onHttpStart() {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d(TAG, "downloadFontByNetwork begin url:" + url);
}
}
@Override
public void onHeadersReceived(int statusCode, Map<String, List<String>> headers) {
}
@Override
public void onHttpUploadProgress(int uploadProgress) {
}
@Override
public void onHttpResponseProgress(int loadedLength) {
}
@Override
public void onHttpFinish(WXResponse response) {
int statusCode = 0;
if (!TextUtils.isEmpty(response.statusCode)) {
try {
statusCode = Integer.parseInt(response.statusCode);
} catch (NumberFormatException e) {
statusCode = 0;
WXLogUtils.e(TAG, "IWXHttpAdapter onHttpFinish statusCode:" + response.statusCode);
}
}
boolean result;
if (statusCode >= 200 && statusCode <= 299 && response.originalData != null) {
result = WXFileUtils.saveFile(fullPath, response.originalData, WXEnvironment.getApplication());
if (result) {
result = loadLocalFontFile(fullPath, fontFamily);
} else {
if (WXEnvironment.isApkDebugable()) {
WXLogUtils.d(TAG, "downloadFontByNetwork() onHttpFinish success, but save file failed.");
}
}
} else {
result = false;
}
if (!result) {
FontDO fontDO = sCacheMap.get(fontFamily);
if (fontDO != null) {
fontDO.setState(FontDO.STATE_FAILED);
}
}
}
});
}
Aggregations