use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class XHRPollingTransport method send.
@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);
}
});
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class TimeoutTests method testSlowBody.
public void testSlowBody() throws Exception {
AsyncHttpRequest req = new AsyncHttpRequest(Uri.parse("http://localhost:5000/now"), "POST");
req.setTimeout(1000);
req.setLogging("slowbody", Log.VERBOSE);
req.setBody(new DelayedStringBody("foo"));
assertEquals("foo", AsyncHttpClient.getDefaultInstance().executeString(req, null).get());
req = new AsyncHttpRequest(Uri.parse("http://localhost:5000/3"), "GET");
req.setLogging("slowbody", Log.VERBOSE);
req.setTimeout(100);
req.setBody(new DelayedStringBody("foo"));
try {
AsyncHttpClient.getDefaultInstance().executeString(req, null).get();
fail();
} catch (Exception e) {
Log.d("timeout", "error", e);
assertTrue(e.getCause() instanceof TimeoutException);
}
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project ion by koush.
the class IonRequestBuilder method execute.
<T> ResponseFuture<T> execute(final AsyncParser<T> parser, Runnable cancel) {
assert parser != null;
final Uri uri = prepareURI();
AsyncHttpRequest request = null;
if (uri != null) {
request = prepareRequest(uri);
Type type = parser.getType();
for (Loader loader : ion.loaders) {
ResponseFuture<T> quickLoad = loader.load(ion, request, type);
if (quickLoad != null)
return quickLoad;
}
}
EmitterTransform<T> ret = new EmitterTransform<T>(cancel) {
EmitterTransform<T> self = this;
@Override
protected void transform(LoaderEmitter emitter) throws Exception {
super.transform(emitter);
parser.parse(this.emitter).setCallback(new FutureCallback<T>() {
@Override
public void onCompleted(Exception e, T result) {
postExecute(self, e, result);
}
});
}
};
if (uri == null) {
ret.setComplete(new Exception("Invalid URI"));
return ret;
}
ret.initialRequest = request;
getLoaderEmitter(ret);
return ret;
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class TimeoutTests method testTimeout.
public void testTimeout() throws Exception {
AsyncHttpRequest req = new AsyncHttpRequest(Uri.parse("http://localhost:5000/3"), "GET");
req.setTimeout(1000);
try {
AsyncHttpClient.getDefaultInstance().executeString(req, null).get();
fail();
} catch (Exception e) {
Log.d("timeout", "error", e);
assertTrue(e.getCause() instanceof TimeoutException);
}
req = new AsyncHttpRequest(Uri.parse("http://localhost:5000/3"), "GET");
assertEquals("3", AsyncHttpClient.getDefaultInstance().executeString(req, null).get());
}
use of com.koushikdutta.async.http.AsyncHttpRequest in project AndroidAsync by koush.
the class HttpClientTests method testUriPathWithSpaces.
public void testUriPathWithSpaces() throws Exception {
AsyncHttpRequest request = new AsyncHttpRequest(Uri.parse("http://jpkc.seiee.sjtu.edu.cn/ds/ds2/Course%20lecture/chapter%2010.pdf"), AsyncHttpGet.METHOD);
String requestLine = request.getRequestLine().toString();
assertEquals("GET /ds/ds2/Course%20lecture/chapter%2010.pdf HTTP/1.1", requestLine);
}
Aggregations