// Things we need from the response
final Buffer responseBody = new Buffer();
final AtomicInteger responseCode = new AtomicInteger();
synchronized (responseBody) {
S3ClientRequest request = client.createGetRequest(testBucket,
"testObject",
new Handler<HttpClientResponse>() {
@Override public void
handle(HttpClientResponse event) {
responseCode.set(event.statusCode);
if (event.statusCode != 200) {
synchronized (responseBody) {
// This
// is
// a
// failed
// request
logger.error("Bad response: "
+ event.statusCode);
responseBody.notify();
}
return;
}
// Try to
// download
// the
// body
event.bodyHandler(new Handler<Buffer>() {
@Override public void
handle(Buffer event) {
// Append
// the
// body
// on
synchronized (responseBody) {
logger.info("Got body: "
+ event.length()
+ "bytes");
responseBody.appendBuffer(event);
responseBody.notify();
}
}
});
}
});
request.end();
try {
responseBody.wait(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}