use of com.taobao.weex.common.WXRequest in project weex-example by KalicyZhou.
the class WXDebugActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!WXEnvironment.isApkDebugable()) {
finish();
return;
}
setContentView(R.layout.activity_dynamic);
mTipView = (TextView) findViewById(R.id.dynamic_tip);
mResultView = (TextView) findViewById(R.id.dynamic_result);
Uri uri = getIntent().getData();
if (uri != null && uri.isHierarchical()) {
String frameworkUrl = uri.getQueryParameter("framework");
String bundleUrl = uri.getQueryParameter("bundle");
if (!TextUtils.isEmpty(frameworkUrl)) {
mTipView.setText("Dynamically replaces the framework!");
IWXHttpAdapter adapter = WXSDKManager.getInstance().getIWXHttpAdapter();
final WXRequest wxRequest = new WXRequest();
wxRequest.url = frameworkUrl;
adapter.sendRequest(wxRequest, this);
} else if (!TextUtils.isEmpty(bundleUrl)) {
mTipView.setText("Dynamically replaces the bundle!");
WXEnvironment.sDynamicMode = uri.getBooleanQueryParameter("debug", false);
WXEnvironment.sDynamicUrl = uri.getQueryParameter("bundle");
String tip = WXEnvironment.sDynamicMode ? "Has switched to Dynamic Mode" : "Has switched to Normal Mode";
Toast.makeText(this, tip, Toast.LENGTH_SHORT).show();
finish();
}
}
}
use of com.taobao.weex.common.WXRequest in project weex-example by KalicyZhou.
the class WXStreamModuleTest method testFetchStatus.
@Test
public void testFetchStatus() throws Exception {
WXStreamModule streamModule = createModule(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 = createModule(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), 302);
assertEquals(finish.mData.get(WXStreamModule.STATUS).getClass(), Integer.class);
assertEquals(finish.mData.get(WXStreamModule.STATUS_TEXT), Status.getStatusText("302"));
}
use of com.taobao.weex.common.WXRequest in project weex-example by KalicyZhou.
the class WXStreamModuleTest method testFetchInvaildOptions.
@Test
public void testFetchInvaildOptions() throws Exception {
IWXHttpAdapter adapter = new IWXHttpAdapter() {
@Override
public void sendRequest(WXRequest request, OnHttpListener listener) {
listener.onHttpFinish(successResponse());
}
};
WXStreamModule streamModule = new WXStreamModule(adapter);
Callback cb = new Callback();
streamModule.fetch("", cb, null);
assert !(boolean) cb.mData.get("ok");
}
use of com.taobao.weex.common.WXRequest in project weex-example by KalicyZhou.
the class WXStreamModule method sendRequest.
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.");
}
}
use of com.taobao.weex.common.WXRequest in project weex-example by KalicyZhou.
the class WXSDKInstance method renderByUrlInternal.
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()));
}
Aggregations