use of com.sforce.ws.MessageHandler in project teiid by teiid.
the class SalesforceCXFTransport method getContent.
@Override
public InputStream getContent() throws IOException {
javax.ws.rs.core.Response response = client.post(new ByteArrayInputStream(this.payload.toByteArray()));
successful = true;
InputStream in = (InputStream) response.getEntity();
if (response.getStatus() != 200) {
successful = false;
}
if (!successful) {
return in;
}
String encoding = response.getHeaderString("Content-Encoding");
if (config.getMaxResponseSize() > 0) {
in = new LimitingInputStream(config.getMaxResponseSize(), in);
}
if ("gzip".equals(encoding)) {
in = new GZIPInputStream(in);
}
if (config.hasMessageHandlers() || config.isTraceMessage()) {
byte[] bytes = FileUtil.toBytes(in);
in = new ByteArrayInputStream(bytes);
if (config.hasMessageHandlers()) {
Iterator<MessageHandler> it = config.getMessagerHandlers();
while (it.hasNext()) {
MessageHandler handler = it.next();
if (handler instanceof MessageHandlerWithHeaders) {
((MessageHandlerWithHeaders) handler).handleResponse(url, bytes, modify(response.getHeaders()));
} else {
handler.handleResponse(url, bytes);
}
}
}
if (config.isTraceMessage()) {
MultivaluedMap<String, Object> headers = response.getHeaders();
for (Map.Entry header : headers.entrySet()) {
config.getTraceStream().print(header.getKey());
config.getTraceStream().print("=");
config.getTraceStream().println(header.getValue());
}
new TeeInputStream(config, bytes);
}
}
return in;
}
Aggregations