// Request the options from the server so we can find out if the broker we are
// talking to supports GZip compressed content. If so and useCompression is on
// then we can compress our POST data, otherwise we must send it uncompressed to
// ensure backwards compatibility.
HttpOptions optionsMethod = new HttpOptions(remoteUrl.toString());
ResponseHandler<String> handler = new BasicResponseHandler() {
@Override
public String handleResponse(HttpResponse response) throws HttpResponseException, IOException {
for(Header header : response.getAllHeaders()) {
if (header.getName().equals("Accepts-Encoding") && header.getValue().contains("gzip")) {
LOG.info("Broker Servlet supports GZip compression.");
canSendCompressed = true;
break;
}
}
return super.handleResponse(response);
}
};
try {
httpClient.execute(httpMethod, new BasicResponseHandler());
httpClient.execute(optionsMethod, handler);
} catch(Exception e) {
throw new IOException("Failed to perform GET on: " + remoteUrl + " as response was: " + e.getMessage());
}