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 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();
}
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);
}
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));
}
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);
}
Aggregations