use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class SSLTests method disabled__testClientCertificateIssue163.
public void disabled__testClientCertificateIssue163() throws Exception {
// https://security.springthroughtest.com/hello.json
AsyncServer server = new AsyncServer();
try {
AsyncHttpClient client = new AsyncHttpClient(server);
JSONObject json = client.executeJSONObject(new AsyncHttpGet("https://security.springthroughtest.com/hello.json"), null).get();
} finally {
server.stop();
}
}
use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class RedirectTests method testRelativeRedirect.
public void testRelativeRedirect() throws Exception {
String ret = AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("http://localhost:6003/foo/bar"), null).get();
assertEquals(ret, "SUCCESS!");
ret = AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("http://localhost:6003/foo"), null).get();
assertEquals(ret, "BORAT!");
ret = AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("http://localhost:6003/foo/poo"), null).get();
assertEquals(ret, "SWEET!");
}
use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class CacheTests method testMaxAgePrivate.
public void testMaxAgePrivate() throws Exception {
AsyncHttpClient client = new AsyncHttpClient(AsyncServer.getDefault());
ResponseCacheMiddleware cache = ResponseCacheMiddleware.addCache(client, new File(getContext().getFilesDir(), "AndroidAsyncTest"), 1024 * 1024 * 10);
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/uname/(.*)", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.getHeaders().set("Date", HttpDate.format(new Date()));
response.getHeaders().set("Cache-Control", "private, max-age=10000");
response.send(request.getMatcher().group(1));
}
});
AsyncServerSocket socket = httpServer.listen(AsyncServer.getDefault(), 0);
int port = socket.getLocalPort();
// clear the old cache
cache.clear();
client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();
client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();
assertEquals(cache.getCacheHitCount(), 1);
assertEquals(cache.getNetworkCount(), 1);
} finally {
AsyncServer.getDefault().stop();
client.getMiddleware().remove(cache);
}
}
use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class HttpClientTests method testGithubRandomData.
public void testGithubRandomData() throws Exception {
final Semaphore semaphore = new Semaphore(0);
final Md5 md5 = Md5.createInstance();
AsyncHttpGet get = new AsyncHttpGet(github);
get.setLogging("AsyncTest", Log.VERBOSE);
client.execute(get, new HttpConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, AsyncHttpResponse response) {
assertNull(ex);
// make sure gzip decoding works, as that is generally what github sends.
// this broke sometime in 03/2014
// Assert.assertEquals("gzip", response.getHeaders().getContentEncoding());
response.setDataCallback(new DataCallback() {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
md5.update(bb);
}
});
response.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
semaphore.release();
}
});
}
});
assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
assertEquals(md5.digest(), dataNameAndHash);
}
use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class HttpClientTests method testFileCancel.
public void testFileCancel() throws Exception {
final Semaphore semaphore = new Semaphore(0);
File f = getContext().getFileStreamPath("test.txt");
fileFuture = client.executeFile(new AsyncHttpGet(github), f.getAbsolutePath(), new AsyncHttpClient.FileCallback() {
@Override
public void onCompleted(Exception e, AsyncHttpResponse source, File result) {
fail();
}
@Override
public void onProgress(AsyncHttpResponse response, long downloaded, long total) {
semaphore.release();
}
}).setCallback(new FutureCallback<File>() {
@Override
public void onCompleted(Exception e, File result) {
assertTrue(e instanceof CancellationException);
}
});
try {
assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
assertTrue(fileFuture.cancel());
fileFuture.get();
fail();
} catch (ExecutionException ex) {
assertTrue(ex.getCause() instanceof CancellationException);
}
// Thread.sleep(1000);
// assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
assertFalse(f.exists());
}
Aggregations