Search in sources :

Example 1 with MessageHandler

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;
}
Also used : Entry(java.util.Map.Entry) MessageHandler(com.sforce.ws.MessageHandler) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageHandlerWithHeaders(com.sforce.ws.MessageHandlerWithHeaders) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Aggregations

MessageHandler (com.sforce.ws.MessageHandler)1 MessageHandlerWithHeaders (com.sforce.ws.MessageHandlerWithHeaders)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1