use of com.koushikdutta.ion.Response in project ion by koush.
the class HeadersTests method testHeadersCallback.
public void testHeadersCallback() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
httpServer.listen(Ion.getDefault(getContext()).getServer(), 5555);
final Semaphore semaphore = new Semaphore(0);
Ion.with(getContext()).load("http://localhost:5555/").asString().withResponse().setCallback(new FutureCallback<Response<String>>() {
@Override
public void onCompleted(Exception e, Response<String> result) {
assertEquals(result.getHeaders().code(), 200);
semaphore.release();
}
});
assertTrue(semaphore.tryAcquire(10000, TimeUnit.MILLISECONDS));
} finally {
httpServer.stop();
Ion.getDefault(getContext()).getServer().stop();
}
}
Aggregations