Search in sources :

Example 1 with Response

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();
    }
}
Also used : HeadersResponse(com.koushikdutta.ion.HeadersResponse) AsyncHttpServerResponse(com.koushikdutta.async.http.server.AsyncHttpServerResponse) Response(com.koushikdutta.ion.Response) HttpServerRequestCallback(com.koushikdutta.async.http.server.HttpServerRequestCallback) AsyncHttpServerRequest(com.koushikdutta.async.http.server.AsyncHttpServerRequest) AsyncHttpServer(com.koushikdutta.async.http.server.AsyncHttpServer) AsyncHttpServerResponse(com.koushikdutta.async.http.server.AsyncHttpServerResponse) Semaphore(java.util.concurrent.Semaphore)

Aggregations

AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)1 AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)1 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)1 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)1 HeadersResponse (com.koushikdutta.ion.HeadersResponse)1 Response (com.koushikdutta.ion.Response)1 Semaphore (java.util.concurrent.Semaphore)1