use of org.apache.cxf.jaxrs.client.ClientProviderFactory in project meecrowave by apache.
the class MeecrowaveClientLifecycleListener method clientDestroyed.
@Override
public void clientDestroyed(final Client client) {
try {
final ClientProviderFactory cpf = ClientProviderFactory.class.cast(client.getEndpoint().get(ClientProviderFactory.class.getName()));
final Collection<Object> invoke = Collection.class.cast(getReadersWriters.invoke(cpf));
invoke.stream().map(p -> ProviderInfo.class.isInstance(p) ? ProviderInfo.class.cast(p).getProvider() : p).filter(p -> !ConfigurableBus.ConfiguredJsonbJaxrsProvider.class.isInstance(p) && JsonbJaxrsProvider.class.isInstance(p)).map(JsonbJaxrsProvider.class::cast).map(p -> {
try {
return ((AtomicReference<Jsonb>) delegate.get(p)).get();
} catch (final IllegalAccessException e) {
throw new IllegalStateException(e);
}
}).filter(Objects::nonNull).filter(JohnzonJsonb.class::isInstance).map(JohnzonJsonb.class::cast).distinct().forEach(jsonb -> CDI.current().select(JohnzonCdiExtension.class).get().untrack(jsonb));
} catch (final RuntimeException re) {
new LogFacade(MeecrowaveClientLifecycleListener.class.getName()).debug(re.getMessage(), re);
} catch (final Exception re) {
// reflection etc which shouldn't fail
new LogFacade(MeecrowaveClientLifecycleListener.class.getName()).error(re.getMessage(), re);
}
}
use of org.apache.cxf.jaxrs.client.ClientProviderFactory in project cxf by apache.
the class InboundSseEventProcessor method run.
void run(final Response response) {
if (closed) {
throw new IllegalStateException("The SSE Event Processor is already closed");
}
final InputStream is = response.readEntity(InputStream.class);
final ClientProviderFactory factory = ClientProviderFactory.getInstance(endpoint);
Message message = null;
if (response instanceof ResponseImpl) {
message = ((ResponseImpl) response).getOutMessage();
}
executor.submit(process(response, is, factory, message));
}
use of org.apache.cxf.jaxrs.client.ClientProviderFactory 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);
}
}
}
}
use of org.apache.cxf.jaxrs.client.ClientProviderFactory in project cxf by apache.
the class ClientResponseFilterInterceptor method handleMessage.
public void handleMessage(Message inMessage) throws Fault {
ClientProviderFactory pf = ClientProviderFactory.getInstance(inMessage);
if (pf == null) {
return;
}
List<ProviderInfo<ClientResponseFilter>> filters = pf.getClientResponseFilters();
if (!filters.isEmpty()) {
ClientRequestContext reqContext = new ClientRequestContextImpl(inMessage.getExchange().getOutMessage(), true);
ClientResponseContext respContext = new ClientResponseContextImpl((ResponseImpl) getResponse(inMessage), inMessage);
for (ProviderInfo<ClientResponseFilter> filter : filters) {
InjectionUtils.injectContexts(filter.getProvider(), filter, inMessage);
try {
filter.getProvider().filter(reqContext, respContext);
} catch (IOException ex) {
throw new ProcessingException(ex);
}
}
}
}
Aggregations