use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class HttpClientTests method testGithubHelloWithFuture.
public void testGithubHelloWithFuture() throws Exception {
Future<String> string = client.executeString(new AsyncHttpGet("https://" + githubPath + "hello.txt"), null);
assertEquals(string.get(TIMEOUT, TimeUnit.MILLISECONDS), "hello world");
}
use of com.koushikdutta.async.http.AsyncHttpGet 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();
}
}
use of com.koushikdutta.async.http.AsyncHttpGet in project AndroidAsync by koush.
the class Issue59 method testIssue.
public void testIssue() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
// setting this to empty is a hacky way of telling the framework not to use
// transfer-encoding. It will get removed.
response.getHeaders().set("Transfer-Encoding", "");
response.code(200);
Util.writeAll(response, "foobarbeepboop".getBytes(), new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
response.end();
}
});
}
});
httpServer.listen(5959);
AsyncHttpGet get = new AsyncHttpGet("http://localhost:5959/");
get.setLogging("issue59", Log.VERBOSE);
get.getHeaders().removeAll("Connection");
get.getHeaders().removeAll("Accept-Encoding");
assertEquals("foobarbeepboop", AsyncHttpClient.getDefaultInstance().executeString(get, null).get(1000, TimeUnit.MILLISECONDS));
} finally {
httpServer.stop();
AsyncServer.getDefault().stop();
}
}
use of com.koushikdutta.async.http.AsyncHttpGet in project simperium-android by Simperium.
the class AsyncWebSocketProvider method connect.
@Override
public void connect(final WebSocketManager.ConnectionListener listener) {
Uri uri = Uri.parse(String.format(AndroidClient.WEBSOCKET_URL, mAppId));
AsyncHttpRequest request = new AsyncHttpGet(uri);
request.setHeader(AndroidClient.USER_AGENT_HEADER, mSessionId);
// Protocol is null
mAsyncClient.websocket(request, null, new WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, final WebSocket webSocket) {
if (ex != null) {
listener.onError(ex);
return;
}
if (webSocket == null) {
listener.onError(new IOException("WebSocket could not be opened"));
return;
}
final WebSocketManager.Connection connection = new WebSocketManager.Connection() {
@Override
public void close() {
mHandler.post(new Runnable() {
@Override
public void run() {
webSocket.close();
}
});
}
@Override
public void send(final String message) {
mHandler.post(new Runnable() {
@Override
public void run() {
webSocket.send(message);
}
});
}
};
webSocket.setStringCallback(new WebSocket.StringCallback() {
@Override
public void onStringAvailable(String s) {
listener.onMessage(s);
}
});
webSocket.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
listener.onDisconnect(ex);
}
});
webSocket.setClosedCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
listener.onDisconnect(ex);
}
});
listener.onConnect(connection);
}
});
}
Aggregations