本文整理汇总了Java中com.taobao.weex.common.WXRequest类的典型用法代码示例。如果您正苦于以下问题:Java WXRequest类的具体用法?Java WXRequest怎么用?Java WXRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WXRequest类属于com.taobao.weex.common包,在下文中一共展示了WXRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testFetchHeaderReceived
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@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");
}
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:18,代码来源:WXStreamModuleTest.java
示例2: sendRequest
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
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.");
}
}
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:23,代码来源:WXStreamModule.java
示例3: testFetchHeaderReceived
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@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");
}
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:18,代码来源:WXStreamModuleTest.java
示例4: setup
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@Before
public void setup() {
WXEnvironment.sApplication = RuntimeEnvironment.application;
WXSDKManager wxsdkManager = WXSDKManager.getInstance();
if (!new MockUtil().isSpy(wxsdkManager)) {
WXSDKManager spy = Mockito.spy(wxsdkManager);
WXSDKManagerTest.setInstance(spy);
Mockito.when(spy.getIWXHttpAdapter()).thenReturn(new IWXHttpAdapter() {
@Override
public void sendRequest(WXRequest request, OnHttpListener listener) {
//do nothing.
}
});
}
adapter = new DefaultUriAdapter();
instance = WXSDKInstanceTest.createInstance();
}
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:19,代码来源:DefaultUriAdapterTest.java
示例5: sendRequest
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@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|IllegalArgumentException e) {
e.printStackTrace();
response.statusCode = "-1";
response.errorCode="-1";
response.errorMsg=e.getMessage();
if(listener!=null){
listener.onHttpFinish(response);
}
}
}
});
}
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:39,代码来源:DefaultWXHttpAdapter.java
示例6: openConnection
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
/**
* Opens an {@link HttpURLConnection} with parameters.
*
* @param request
* @param listener
* @return an open connection
* @throws IOException
*/
private HttpURLConnection openConnection(WXRequest request, OnHttpListener listener) throws IOException {
URL url = new URL(request.url);
HttpURLConnection connection = createConnection(url);
connection.setConnectTimeout(request.timeoutMs);
connection.setReadTimeout(request.timeoutMs);
connection.setUseCaches(false);
connection.setDoInput(true);
if (request.paramMap != null) {
Set<String> keySets = request.paramMap.keySet();
for (String key : keySets) {
connection.addRequestProperty(key, request.paramMap.get(key));
}
}
if ("POST".equals(request.method) || "PUT".equals(request.method) || "PATCH".equals(request.method)) {
connection.setRequestMethod(request.method);
if (request.body != null) {
if (listener != null) {
listener.onHttpUploadProgress(0);
}
connection.setDoOutput(true);
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
//TODO big stream will cause OOM; Progress callback is meaningless
out.write(request.body.getBytes());
out.close();
if (listener != null) {
listener.onHttpUploadProgress(100);
}
}
} else if (!TextUtils.isEmpty(request.method)) {
connection.setRequestMethod(request.method);
} else {
connection.setRequestMethod("GET");
}
return connection;
}
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:47,代码来源:DefaultWXHttpAdapter.java
示例7: renderByUrl
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
public void renderByUrl(String pageName, final String url, Map<String, Object> options, final String jsonInitData, final int width, final int height, final WXRenderStrategy flag) {
pageName = wrapPageName(pageName, url);
mBundleUrl = url;
if (options == null) {
options = new HashMap<String, Object>();
}
if (!options.containsKey(BUNDLE_URL)) {
options.put(BUNDLE_URL, url);
}
Uri uri=Uri.parse(url);
if(uri!=null && TextUtils.equals(uri.getScheme(),"file")){
render(pageName, WXFileUtils.loadAsset(assembleFilePath(uri), mContext),options,jsonInitData,width,height,flag);
return;
}
IWXHttpAdapter adapter=WXSDKManager.getInstance().getIWXHttpAdapter();
WXRequest wxRequest = new WXRequest();
wxRequest.url = url;
if (wxRequest.paramMap == null) {
wxRequest.paramMap = new HashMap<String, String>();
}
wxRequest.paramMap.put("user-agent", WXHttpUtil.assembleUserAgent(mContext,WXEnvironment.getConfig()));
adapter.sendRequest(wxRequest, new WXHttpListener(pageName, options, jsonInitData, width, height, flag, System.currentTimeMillis()));
mWXHttpAdapter = adapter;
}
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:30,代码来源:WXSDKInstance.java
示例8: testFetchStatus
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@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"));
}
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:30,代码来源:WXStreamModuleTest.java
示例9: renderByUrlInternal
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
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);
}
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:41,代码来源:WXSDKInstance.java
示例10: renderByUrlInternal
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
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()));
}
开发者ID:erguotou520,项目名称:weex-uikit,代码行数:35,代码来源:WXSDKInstance.java
示例11: sendRequest
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@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);
}
}
}
});
}
开发者ID:Laisly,项目名称:weex,代码行数:39,代码来源:DefaultWXHttpAdapter.java
示例12: openConnection
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
/**
* Opens an {@link HttpURLConnection} with parameters.
*
* @param request
* @param listener
* @return an open connection
* @throws IOException
*/
private HttpURLConnection openConnection(WXRequest request, OnHttpListener listener) throws IOException {
URL url = new URL(request.url);
HttpURLConnection connection = createConnection(url);
connection.setConnectTimeout(request.timeoutMs);
connection.setReadTimeout(request.timeoutMs);
connection.setUseCaches(false);
connection.setDoInput(true);
if (request.paramMap != null) {
Set<String> keySets = request.paramMap.keySet();
for (String key : keySets) {
connection.addRequestProperty(key, request.paramMap.get(key));
}
}
if ("POST".equals(request.method)) {
connection.setRequestMethod("POST");
if (request.body != null) {
if (listener != null) {
listener.onHttpUploadProgress(0);
}
connection.setDoOutput(true);
DataOutputStream out = new DataOutputStream(connection.getOutputStream());
//TODO big stream will cause OOM; Progress callback is meaningless
out.write(request.body.getBytes());
out.close();
if (listener != null) {
listener.onHttpUploadProgress(100);
}
}
} else if (!TextUtils.isEmpty(request.method)) {
connection.setRequestMethod(request.method);
} else {
connection.setRequestMethod("GET");
}
return connection;
}
开发者ID:Laisly,项目名称:weex,代码行数:47,代码来源:DefaultWXHttpAdapter.java
示例13: AddHeaders
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
private Headers AddHeaders(WXRequest request) {
Headers.Builder builder = new Headers.Builder();
if (request.paramMap != null) {
Set<String> keySets = request.paramMap.keySet();
for (String key : keySets) {
builder.add(key, request.paramMap.get(key));
}
}
return builder.build();
}
开发者ID:zjutkz,项目名称:Weex-OkHttp-Adapter,代码行数:11,代码来源:OkHttpAdapter.java
示例14: sendRequest
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
@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);
}
}
}
});
}
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:47,代码来源:DefaultWXHttpAdapter.java
示例15: sendRequest
import com.taobao.weex.common.WXRequest; //导入依赖的package包/类
/**
* http request method
*
* @param request weex assemble request
* @param listener http response notify
*/
void sendRequest(WXRequest request, OnHttpListener listener);
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:8,代码来源:IWXHttpAdapter.java
注:本文中的com.taobao.weex.common.WXRequest类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论