本文整理汇总了Java中com.koushikdutta.async.http.AsyncHttpResponse类的典型用法代码示例。如果您正苦于以下问题:Java AsyncHttpResponse类的具体用法?Java AsyncHttpResponse怎么用?Java AsyncHttpResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AsyncHttpResponse类属于com.koushikdutta.async.http包,在下文中一共展示了AsyncHttpResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: uploadFile
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public static Future<?> uploadFile(Request request, final ResponseCallback responseCallback) {
StringBuilder stringBuffer = new StringBuilder(request.getURL());
if (request.getURLParams() != null) {
String params = HttpUtils.getRequestParams(request.getURLParams());
if (!TextUtils.isEmpty(params)) {
stringBuffer.append("?").append(params);
}
}
if (BuildConfig.DEBUG) {
LogUtils.d(stringBuffer.toString());
}
AsyncHttpPost asyncHttpPost = new AsyncHttpPost(stringBuffer.toString());
HashMap<String, File> file = request.getFileBody();
if (file != null && !file.isEmpty()) {
asyncHttpPost.setBody(new FileBody(file.entrySet().iterator().next().getValue()));
}
addHead(request.getHeader(), asyncHttpPost);
return asyncHttpClient.executeString(asyncHttpPost, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String s) {
if (responseCallback != null) {
responseCallback.onCompleted(e, asyncHttpResponse, s);
}
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:27,代码来源:HttpApi.java
示例2: convert
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
private Response convert(Request request, AsyncHttpResponse response, String s) {
Response res = new Response();
res.setCode(response.code());
res.setMessage(response.message());
res.setProtocol(response.protocol());
res.setBody(s);
res.setSourceBody(s.getBytes());
Type type = request.getBusinessType();
if (type != null) {
res.setBussinessResponse(JsonUtil.fromJson(s, type));
}
Headers headers = response.headers();
Multimap multimap = headers.getMultiMap();
Set<String> keySet = multimap.keySet();
for (String key : keySet) {
res.addHeader(key, multimap.get(key));
}
res.setRequest(request);
return res;
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:21,代码来源:NetworkDelegate.java
示例3: send
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
@Override
public void send(String message) {
if (message.startsWith("5")) {
postMessage(message);
return;
}
AsyncHttpRequest request = new AsyncHttpPost(computedRequestUrl());
request.setBody(new StringBody(message));
client.executeString(request, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse source, String result) {
if (e != null) {
close(e);
return;
}
sendResult(result);
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:23,代码来源:XHRPollingTransport.java
示例4: proxy
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
@Override
public void proxy(final AsyncHttpResponse remoteResponse) {
code(remoteResponse.code());
remoteResponse.headers().removeAll("Transfer-Encoding");
remoteResponse.headers().removeAll("Content-Encoding");
remoteResponse.headers().removeAll("Connection");
getHeaders().addAll(remoteResponse.headers());
// TODO: remove?
remoteResponse.headers().set("Connection", "close");
Util.pump(remoteResponse, this, new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
remoteResponse.setEndCallback(new NullCompletedCallback());
remoteResponse.setDataCallback(new DataCallback.NullDataCallback());
end();
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:19,代码来源:AsyncHttpServerResponseImpl.java
示例5: fetchContacts
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public void fetchContacts(final ContactProviderListener callback) {
createClient().executeString(createGetRequest(), new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String result) {
if (result != null) {
try {
callback.onContacts(gson.fromJson(result, Contacts.class));
} catch (JsonSyntaxException jse) {
callback.onError(jse);
}
} else {
callback.onError(e);
}
}
});
}
开发者ID:lavong,项目名称:SpockUnitTestsDemo,代码行数:17,代码来源:ContactsProvider.java
示例6: executePostJsonObject
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public static Future<?> executePostJsonObject(Request request, final ResponseCallback responseCallback) throws JSONException {
StringBuilder stringBuilder = new StringBuilder(64);
String params = HttpUtils.getRequestParams(request.getURLParams());
if (!TextUtils.isEmpty(params)) {
stringBuilder.append("?").append(params);
}
AsyncHttpPost asyncHttpPost = new AsyncHttpPost(stringBuilder.toString());
JSONObject jsonObject;
if (request.getBodyParams() != null) {
jsonObject = new JSONObject(request.getBodyParams());
} else {
jsonObject = new JSONObject("{}");
}
AsyncHttpRequestBody<JSONObject> asyncHttpRequestBody = new JSONObjectBody(jsonObject);
asyncHttpPost.setBody(asyncHttpRequestBody);
addHead(request.getHeader(), asyncHttpPost);
return asyncHttpClient.executeString(asyncHttpPost, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String s) {
if (responseCallback != null) {
responseCallback.onCompleted(e, asyncHttpResponse, s);
}
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:26,代码来源:HttpApi.java
示例7: executePostJsonArray
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public static Future<?> executePostJsonArray(Request request, final ResponseCallback responseCallback) throws JSONException {
StringBuilder builder = new StringBuilder(request.getURL());
String params = HttpUtils.getRequestParams(request.getURLParams());
if (!TextUtils.isEmpty(params)) {
builder.append("?").append(params);
}
if (BuildConfig.DEBUG) {
LogUtils.d(builder.toString());
}
AsyncHttpPost asyncHttpPost = new AsyncHttpPost(builder.toString());
JSONArray jsonArray;
if (request.getArray() != null) {
jsonArray = new JSONArray(request.getArray());
} else {
jsonArray = new JSONArray("[]");
}
AsyncHttpRequestBody<JSONArray> asyncHttpRequestBody = new JSONArrayBody(jsonArray);
asyncHttpPost.setBody(asyncHttpRequestBody);
addHead(request.getHeader(), asyncHttpPost);
return asyncHttpClient.executeString(asyncHttpPost, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String s) {
if (responseCallback != null) {
responseCallback.onCompleted(e, asyncHttpResponse, s);
}
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:30,代码来源:HttpApi.java
示例8: executePost
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public static Future<?> executePost(Request request, final ResponseCallback responseCallback) {
AsyncHttpPost asyncHttpPost = new AsyncHttpPost(request.getURL());
String body;
if (request.getBodyParams() != null) {
if (BuildConfig.DEBUG) {
LogUtils.d(request.getBodyParams().toString());
}
body = HttpUtils.getRequestParams(request.getBodyParams());
} else {
body = "";
}
AsyncHttpRequestBody<String> asyncHttpRequestBody = new StringBody(body);
asyncHttpPost.setBody(asyncHttpRequestBody);
addHead(request.getHeader(), asyncHttpPost);
return asyncHttpClient.executeString(asyncHttpPost, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String s) {
if (responseCallback != null) {
responseCallback.onCompleted(e, asyncHttpResponse, s);
}
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:24,代码来源:HttpApi.java
示例9: executeGet
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public static Future<?> executeGet(Request request, final ResponseCallback responseCallback) {
StringBuilder stringBuffer = new StringBuilder(request.getURL());
if (request.getURLParams() != null) {
String params = HttpUtils.getRequestParams(request.getURLParams());
if (!TextUtils.isEmpty(params)) {
stringBuffer.append("?").append(params);
}
}
if (BuildConfig.DEBUG) {
LogUtils.d(stringBuffer.toString());
}
AsyncHttpGet asyncHttpGet = new AsyncHttpGet(stringBuffer.toString());
CacheControl cacheControl = request.getCacheControl();
if (cacheControl != null) {
asyncHttpGet.setHeader("Cache-Control", cacheControl.getCacheHeaderProperty());
}
addHead(request.getHeader(), asyncHttpGet);
return asyncHttpClient.executeString(asyncHttpGet, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String s) {
if (responseCallback != null) {
responseCallback.onCompleted(e, asyncHttpResponse, s);
}
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:27,代码来源:HttpApi.java
示例10: handleResponse
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
private void handleResponse(Exception e, AsyncHttpResponse response, String s, Request request, NetworkListener networkListener) {
Future future = mTask.remove(request.getRealTag());
if (future.isCancelled()) {
return;
}
if (e != null) {
networkListener.onError(request, e);
} else {
networkListener.onComplete(convert(request, response, s));
}
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:12,代码来源:NetworkDelegate.java
示例11: doLongPolling
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
private void doLongPolling() {
this.client.executeString(new AsyncHttpGet(computedRequestUrl()), new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse source, String result) {
if (e != null) {
close(e);
return;
}
sendResult(result);
doLongPolling();
}
});
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:15,代码来源:XHRPollingTransport.java
示例12: testUpload
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public void testUpload() throws Exception {
File dummy = getContext().getFileStreamPath("dummy.txt");
final String FIELD_VAL = "bar";
dummy.getParentFile().mkdirs();
FileOutputStream fout = new FileOutputStream(dummy);
byte[] zeroes = new byte[100000];
for (int i = 0; i < 10; i++) {
fout.write(zeroes);
}
fout.close();
// StreamUtility.writeFile(dummy, DUMMY_VAL);
AsyncHttpPost post = new AsyncHttpPost("http://localhost:5000");
MultipartFormDataBody body = new MultipartFormDataBody();
body.addStringPart("foo", FIELD_VAL);
body.addFilePart("my-file", dummy);
body.addStringPart("baz", FIELD_VAL);
post.setBody(body);
Future<String> ret = AsyncHttpClient.getDefaultInstance().executeString(post, new StringCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse source, String result) {
}
});
String data = ret.get(10000, TimeUnit.MILLISECONDS);
assertEquals(data, FIELD_VAL + (zeroes.length * 10) + FIELD_VAL);
}
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:29,代码来源:MultipartTests.java
示例13: listAllPeers
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
/**
* Retrieves the list of peer that can be connected.
* @param callback Callback to return the list of peer
*/
public void listAllPeers(final OnAllPeersCallback callback) {
Uri uri = Uri.parse(createDiscoveryUrl());
AsyncHttpRequest req = new AsyncHttpRequest(uri, "GET");
addConfig(req);
AsyncHttpClient client = AsyncHttpClient.getDefaultInstance();
client.executeJSONArray(req, new AsyncHttpClient.JSONArrayCallback() {
@Override
public void onCompleted(final Exception e, final AsyncHttpResponse source, final JSONArray result) {
if (e != null) {
if (callback != null) {
callback.onErrorCallback();
}
} else {
int statusCode = source.code();
if (statusCode == 200) {
if (callback != null) {
callback.onCallback(result);
}
} else {
if (callback != null) {
callback.onErrorCallback();
}
}
}
}
});
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:33,代码来源:SignalingClient.java
示例14: retrieveId
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
/**
* Retrieves my id from peer server.
* @param id old id
*/
private void retrieveId(final String id) {
Uri uri = Uri.parse(createRetrievedUrl(id));
AsyncHttpRequest req = new AsyncHttpRequest(uri, "GET");
req.setHeader("Content-Length", String.valueOf(0));
req.setTimeout(TIMEOUT_HTTP_CONNECTION);
addConfig(req);
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ retrieveId");
Log.d(TAG, "@@@ uri=" + req.toString());
}
AsyncHttpClient client = AsyncHttpClient.getDefaultInstance();
client.executeString(req, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(final Exception e, final AsyncHttpResponse source, final String result) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ retrieveId response " + source);
Log.d(TAG, "@@@ result: " + result);
}
if (e != null) {
if (mSignalingCallback != null) {
mSignalingCallback.onError("Failed to connect a server.");
}
return;
}
if (result != null && result.length() > 0 && source != null) {
int resultCode = source.code();
source.close();
if (resultCode == 200) {
try {
JSONObject jsonResult = new JSONObject(result);
mId = jsonResult.getString("id");
mCredential = jsonResult.getString("credential");
} catch (Exception ex) {
mId = result;
}
if (mId != null) {
startXhrStream();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
startWebSocket();
}
}, 1000L);
if (mHandler != null && mSendingRun != null) {
mHandler.post(mSendingRun);
}
}
} else {
if (mSignalingCallback != null) {
mSignalingCallback.onError("Failed to connect a server.");
}
}
} else {
if (source != null) {
source.close();
}
if (mSignalingCallback != null) {
mSignalingCallback.onError("Retrieved PeerId is failed.");
}
}
}
});
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:76,代码来源:SignalingClient.java
示例15: startXhrStream
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
/**
* Starts XHR stream.
*/
private void startXhrStream() {
Uri uri = Uri.parse(createSkyWayServer());
AsyncHttpRequest req = new AsyncHttpRequest(uri, "POST");
req.setHeader("Accept-Encoding", "gzip, deflate");
req.setHeader("Connection", "keep-alive");
req.setHeader("Accept", "*/*");
req.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
req.addHeader("_index", "1");
req.addHeader("_streamIndex", String.valueOf(0));
req.setTimeout(TIMEOUT_HTTP_CONNECTION);
addConfig(req);
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ startXhrStream");
Log.d(TAG, "@@@ request=" + req);
}
AsyncHttpClient client = AsyncHttpClient.getDefaultInstance();
client.executeString(req, new AsyncHttpClient.StringCallback() {
@Override
public void onCompleted(final Exception e, final AsyncHttpResponse source, final String result) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ startXhrStream response.");
Log.d(TAG, "@@@ result=" + result);
Log.d(TAG, "@@@ message=" + source.message());
Log.d(TAG, "@@@ source=" + source);
if (e != null) {
Log.e(TAG, "@@@ ", e);
}
}
String type = null;
if (result != null) {
int msgIndex = result.indexOf("{");
if (msgIndex != -1) {
try {
String error = result.substring(msgIndex);
JSONObject ex = new JSONObject(error);
type = ex.getString("type");
} catch (Exception e2) {
// do nothing
}
}
if ("OPEN".equalsIgnoreCase(type)) {
mDisconnectFlag = false;
if (mSignalingCallback != null) {
mSignalingCallback.onOpen(mId);
}
}
}
}
});
}
开发者ID:DeviceConnect,项目名称:DeviceConnect-Android,代码行数:58,代码来源:SignalingClient.java
示例16: onCompleted
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
void onCompleted(Exception e, AsyncHttpResponse response, T s);
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:ResponseCallback.java
示例17: onProgress
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
void onProgress(AsyncHttpResponse response, long downloaded, long total);
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:ResponseCallback.java
示例18: onConnect
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
void onConnect(AsyncHttpResponse response);
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:ResponseCallback.java
示例19: proxy
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public void proxy(AsyncHttpResponse response);
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:AsyncHttpServerResponse.java
示例20: onConnectCompleted
import com.koushikdutta.async.http.AsyncHttpResponse; //导入依赖的package包/类
public void onConnectCompleted(Exception ex, AsyncHttpResponse response);
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:2,代码来源:HttpConnectCallback.java
注:本文中的com.koushikdutta.async.http.AsyncHttpResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论