return builder.toString();
}
});
String r = f.get(5, TimeUnit.SECONDS);
FluentCaseInsensitiveStringsMap h = responseHeaders.get();
assertNotNull(h, "Should receive non null headers");
assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET.toLowerCase(Locale.ENGLISH), "Unexpected content-type");
assertNotNull(r, "No response body");
assertEquals(r.trim(), RESPONSE, "Unexpected response body");
responseHeaders.set(null);
// Let do the same again
f = rb.execute(new AsyncHandlerAdapter() {
private StringBuilder builder = new StringBuilder();
@Override
public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
responseHeaders.set(content.getHeaders());
return STATE.CONTINUE;
}
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
builder.append(new String(content.getBodyPartBytes()));
return STATE.CONTINUE;
}
@Override
public String onCompleted() throws Exception {
return builder.toString();
}
});
f.get(5, TimeUnit.SECONDS);
h = responseHeaders.get();
assertNotNull(h, "Should receive non null headers");
assertEquals(h.getJoinedValue("content-type", ", ").toLowerCase(Locale.ENGLISH), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET.toLowerCase(Locale.ENGLISH), "Unexpected content-type");
assertNotNull(r, "No response body");
assertEquals(r.trim(), RESPONSE, "Unexpected response body");
} finally {
c.close();
}