use of org.apache.cxf.transport.http.ProxyOutputStream in project cxf by apache.
the class ClientRequestFilterInterceptor method handleMessage.
public void handleMessage(Message outMessage) throws Fault {
ClientProviderFactory pf = ClientProviderFactory.getInstance(outMessage);
if (pf == null) {
return;
}
// create an empty proxy output stream that the filter can interact with
// and save a reference for later
ProxyOutputStream pos = new ProxyOutputStream();
outMessage.setContent(OutputStream.class, pos);
outMessage.setContent(ProxyOutputStream.class, pos);
List<ProviderInfo<ClientRequestFilter>> filters = pf.getClientRequestFilters();
if (!filters.isEmpty()) {
final Exchange exchange = outMessage.getExchange();
final ClientRequestContext context = new ClientRequestContextImpl(outMessage, false);
for (ProviderInfo<ClientRequestFilter> filter : filters) {
InjectionUtils.injectContexts(filter.getProvider(), filter, outMessage);
try {
filter.getProvider().filter(context);
@SuppressWarnings("unchecked") Map<String, List<Object>> headers = CastUtils.cast((Map<String, List<Object>>) outMessage.get(Message.PROTOCOL_HEADERS));
HttpUtils.convertHeaderValuesToString(headers, false);
Response response = outMessage.getExchange().get(Response.class);
if (response != null) {
outMessage.getInterceptorChain().abort();
Message inMessage = new MessageImpl();
inMessage.setExchange(exchange);
inMessage.put(Message.RESPONSE_CODE, response.getStatus());
inMessage.put(Message.PROTOCOL_HEADERS, response.getMetadata());
exchange.setInMessage(inMessage);
MessageObserver observer = exchange.get(MessageObserver.class);
observer.onMessage(inMessage);
return;
}
} catch (IOException ex) {
throw new ProcessingException(ex);
}
}
}
}
Aggregations