Search in sources :

Example 6 with AsyncServer

use of com.koushikdutta.async.AsyncServer in project AndroidAsync by koush.

the class DnsTests method testNoDomain.

public void testNoDomain() throws Exception {
    AsyncServer server = new AsyncServer();
    try {
        final Semaphore semaphore = new Semaphore(0);
        server.connectSocket("www.clockworkmod-notfound.com", 8080, new ConnectCallback() {

            @Override
            public void onConnectCompleted(Exception ex, AsyncSocket socket) {
                assertTrue(ex instanceof UnknownHostException);
                semaphore.release();
            }
        });
        assertTrue(semaphore.tryAcquire(5000, TimeUnit.MILLISECONDS));
    } finally {
        server.stop();
    }
}
Also used : AsyncSocket(com.koushikdutta.async.AsyncSocket) UnknownHostException(java.net.UnknownHostException) AsyncServer(com.koushikdutta.async.AsyncServer) Semaphore(java.util.concurrent.Semaphore) ConnectCallback(com.koushikdutta.async.callback.ConnectCallback) UnknownHostException(java.net.UnknownHostException)

Example 7 with AsyncServer

use of com.koushikdutta.async.AsyncServer in project AndroidAsync by koush.

the class HttpClientTests method testProxy.

public void testProxy() throws Exception {
    wasProxied = false;
    final AsyncServer proxyServer = new AsyncServer();
    try {
        AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {

            @Override
            protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                wasProxied = true;
                return super.onRequest(request, response);
            }
        };
        AsyncServerSocket socket = httpServer.listen(proxyServer, 0);
        //            client.getSocketMiddleware().enableProxy("localhost", 5555);
        AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
        get.enableProxy("localhost", socket.getLocalPort());
        Future<String> ret = client.executeString(get, null);
        String data;
        assertNotNull(data = ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
        assertTrue(data.contains("ClockworkMod"));
        assertTrue(wasProxied);
    } finally {
        proxyServer.stop();
    }
}
Also used : AsyncServerSocket(com.koushikdutta.async.AsyncServerSocket) AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet) AsyncHttpServerRequest(com.koushikdutta.async.http.server.AsyncHttpServerRequest) AsyncServer(com.koushikdutta.async.AsyncServer) AsyncHttpServerResponse(com.koushikdutta.async.http.server.AsyncHttpServerResponse) AsyncProxyServer(com.koushikdutta.async.http.server.AsyncProxyServer)

Aggregations

AsyncServer (com.koushikdutta.async.AsyncServer)7 AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)4 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)4 AsyncServerSocket (com.koushikdutta.async.AsyncServerSocket)2 AsyncHttpGet (com.koushikdutta.async.http.AsyncHttpGet)2 AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)2 AsyncProxyServer (com.koushikdutta.async.http.server.AsyncProxyServer)2 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)2 AsyncSocket (com.koushikdutta.async.AsyncSocket)1 ByteBufferList (com.koushikdutta.async.ByteBufferList)1 DataSink (com.koushikdutta.async.DataSink)1 CompletedCallback (com.koushikdutta.async.callback.CompletedCallback)1 ConnectCallback (com.koushikdutta.async.callback.ConnectCallback)1 WritableCallback (com.koushikdutta.async.callback.WritableCallback)1 AsyncHttpClient (com.koushikdutta.async.http.AsyncHttpClient)1 UrlEncodedFormBody (com.koushikdutta.async.http.body.UrlEncodedFormBody)1 UnknownHostException (java.net.UnknownHostException)1 Semaphore (java.util.concurrent.Semaphore)1 JSONObject (org.json.JSONObject)1