use of com.koushikdutta.async.AsyncServer 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.AsyncServer in project ion by koush.
the class RequestBodyUploadObserver method write.
@Override
public void write(AsyncHttpRequest request, final DataSink sink, final CompletedCallback completed) {
final int length = body.length();
body.write(request, new DataSink() {
int totalWritten;
@Override
public void write(ByteBufferList bb) {
int start = bb.remaining();
sink.write(bb);
int wrote = start - bb.remaining();
totalWritten += wrote;
callback.onProgress(totalWritten, length);
}
@Override
public void setWriteableCallback(WritableCallback handler) {
sink.setWriteableCallback(handler);
}
@Override
public WritableCallback getWriteableCallback() {
return sink.getWriteableCallback();
}
@Override
public boolean isOpen() {
return sink.isOpen();
}
@Override
public void end() {
sink.end();
}
@Override
public void setClosedCallback(CompletedCallback handler) {
sink.setClosedCallback(handler);
}
@Override
public CompletedCallback getClosedCallback() {
return sink.getClosedCallback();
}
@Override
public AsyncServer getServer() {
return sink.getServer();
}
}, completed);
}
use of com.koushikdutta.async.AsyncServer in project ion by koush.
the class Issues method testIssue329.
public void testIssue329() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.post("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
UrlEncodedFormBody body = (UrlEncodedFormBody) request.getBody();
response.send(body.get().getString("電"));
}
});
AsyncServer asyncServer = new AsyncServer();
try {
int localPort = httpServer.listen(asyncServer, 0).getLocalPort();
String s1 = Ion.with(getContext()).load("http://localhost:" + localPort).setBodyParameter("電", "電").asString().get();
assertEquals(s1, "電");
} finally {
asyncServer.stop();
}
}
use of com.koushikdutta.async.AsyncServer in project ion by koush.
the class Issues method testIssue146.
public void testIssue146() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.getHeaders().set("Cache-Control", "max-age=300");
response.send(request.getQuery().size() + "");
}
});
AsyncServer asyncServer = new AsyncServer();
try {
int localPort = httpServer.listen(asyncServer, 0).getLocalPort();
String s1 = Ion.with(getContext()).load("http://localhost:" + localPort).addQuery("query1", "q").asString().get();
String s2 = Ion.with(getContext()).load("http://localhost:" + localPort).addQuery("query1", "q").addQuery("query2", "qq").asString().get();
String s3 = Ion.with(getContext()).load("http://localhost:" + localPort).addQuery("query1", "q").asString().get();
assertEquals(s1, "1");
assertEquals(s2, "2");
assertEquals(s3, "1");
} finally {
asyncServer.stop();
}
}
use of com.koushikdutta.async.AsyncServer in project ion by koush.
the class HttpTests 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 s = httpServer.listen(proxyServer, 0);
Future<String> ret = Ion.with(getContext()).load("http://www.clockworkmod.com").proxy("localhost", s.getLocalPort()).asString();
String data;
assertNotNull(data = ret.get(10000, TimeUnit.MILLISECONDS));
assertTrue(data.contains("ClockworkMod"));
assertTrue(wasProxied);
} finally {
proxyServer.stop();
}
}
Aggregations