Search in sources :

Example 1 with AsyncHttpGet

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();
    }
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet) JSONObject(org.json.JSONObject) AsyncServer(com.koushikdutta.async.AsyncServer) AsyncHttpClient(com.koushikdutta.async.http.AsyncHttpClient)

Example 2 with AsyncHttpGet

use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.

the class SSLTests method testKeys.

public void testKeys() throws Exception {
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
    kmf.init(ks, "storepass".toCharArray());
    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
    ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
    tmf.init(ts);
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
    AsyncHttpServer httpServer = new AsyncHttpServer();
    httpServer.listenSecure(8888, sslContext);
    httpServer.get("/", new HttpServerRequestCallback() {

        @Override
        public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
            response.send("hello");
        }
    });
    Thread.sleep(1000);
    AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(sslContext);
    AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
    AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("https://localhost:8888/"), null).get();
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet) HttpServerRequestCallback(com.koushikdutta.async.http.server.HttpServerRequestCallback) AsyncHttpServerRequest(com.koushikdutta.async.http.server.AsyncHttpServerRequest) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) AsyncHttpServer(com.koushikdutta.async.http.server.AsyncHttpServer) AsyncHttpServerResponse(com.koushikdutta.async.http.server.AsyncHttpServerResponse) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Example 3 with AsyncHttpGet

use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.

the class HttpClientTests method testGithubRandomDataWithFuture.

public void testGithubRandomDataWithFuture() throws Exception {
    final Md5 md5 = Md5.createInstance();
    Future<ByteBufferList> bb = client.executeByteBufferList(new AsyncHttpGet(github), null);
    md5.update(bb.get(TIMEOUT, TimeUnit.MILLISECONDS));
    assertEquals(md5.digest(), dataNameAndHash);
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet) ByteBufferList(com.koushikdutta.async.ByteBufferList)

Example 4 with AsyncHttpGet

use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.

the class HttpClientTests method testHomepage.

@Test
public void testHomepage() throws Exception {
    Future<String> ret = client.executeString(new AsyncHttpGet("http://google.com"), null);
    assertNotNull(ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet) Test(org.junit.Test)

Example 5 with AsyncHttpGet

use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.

the class HttpClientTests method testSni.

public void testSni() throws Exception {
    // ProviderInstaller.installIfNeeded(getContext());
    // AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(SSLContext.getInstance("TLS"));
    // this server requires SNI as it serves multiple SSL certificates
    // LOLLIPOP_MR1 and lower requires SSLEngineSNIConfigurator to set the appropriate fields via reflection.
    // Higher than LOLLIPOP_MR1 can use createSSLEngine(host, port) as it is based off recent-ish versions of Conscrypt
    // Conscrypt, if it is being used in GPS ProviderInstaller, can also use createSSLEngine(host, port)
    Future<String> string = client.executeString(new AsyncHttpGet("https://koush.com/"), null);
    string.get(TIMEOUT, TimeUnit.MILLISECONDS);
}
Also used : AsyncHttpGet(com.koushikdutta.async.http.AsyncHttpGet)

Aggregations

AsyncHttpGet (com.koushikdutta.async.http.AsyncHttpGet)17 AsyncHttpServer (com.koushikdutta.async.http.server.AsyncHttpServer)5 AsyncHttpServerRequest (com.koushikdutta.async.http.server.AsyncHttpServerRequest)5 AsyncHttpServerResponse (com.koushikdutta.async.http.server.AsyncHttpServerResponse)5 HttpServerRequestCallback (com.koushikdutta.async.http.server.HttpServerRequestCallback)4 AsyncServerSocket (com.koushikdutta.async.AsyncServerSocket)3 ByteBufferList (com.koushikdutta.async.ByteBufferList)3 CompletedCallback (com.koushikdutta.async.callback.CompletedCallback)3 AsyncHttpClient (com.koushikdutta.async.http.AsyncHttpClient)3 AsyncHttpResponse (com.koushikdutta.async.http.AsyncHttpResponse)3 CancellationException (java.util.concurrent.CancellationException)3 ExecutionException (java.util.concurrent.ExecutionException)3 Semaphore (java.util.concurrent.Semaphore)3 TimeoutException (java.util.concurrent.TimeoutException)3 Test (org.junit.Test)3 AsyncServer (com.koushikdutta.async.AsyncServer)2 File (java.io.File)2 AssetManager (android.content.res.AssetManager)1 Uri (android.net.Uri)1 DataEmitter (com.koushikdutta.async.DataEmitter)1