Search in sources :

Example 1 with ClientProviderFactory

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);
    }
}
Also used : LogFacade(org.apache.meecrowave.logging.tomcat.LogFacade) Collection(java.util.Collection) CDI(javax.enterprise.inject.spi.CDI) Client(org.apache.cxf.endpoint.Client) ProviderFactory(org.apache.cxf.jaxrs.provider.ProviderFactory) Field(java.lang.reflect.Field) AtomicReference(java.util.concurrent.atomic.AtomicReference) Objects(java.util.Objects) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ClientProviderFactory(org.apache.cxf.jaxrs.client.ClientProviderFactory) JohnzonCdiExtension(org.apache.johnzon.jsonb.cdi.JohnzonCdiExtension) ClientLifeCycleListener(org.apache.cxf.endpoint.ClientLifeCycleListener) JohnzonJsonb(org.apache.johnzon.jsonb.JohnzonJsonb) Jsonb(javax.json.bind.Jsonb) Method(java.lang.reflect.Method) JsonbJaxrsProvider(org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider) JsonbJaxrsProvider(org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider) ClientProviderFactory(org.apache.cxf.jaxrs.client.ClientProviderFactory) JohnzonJsonb(org.apache.johnzon.jsonb.JohnzonJsonb) JohnzonJsonb(org.apache.johnzon.jsonb.JohnzonJsonb) Jsonb(javax.json.bind.Jsonb) LogFacade(org.apache.meecrowave.logging.tomcat.LogFacade) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) Objects(java.util.Objects) JohnzonCdiExtension(org.apache.johnzon.jsonb.cdi.JohnzonCdiExtension)

Example 2 with ClientProviderFactory

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));
}
Also used : Message(org.apache.cxf.message.Message) InputStream(java.io.InputStream) ClientProviderFactory(org.apache.cxf.jaxrs.client.ClientProviderFactory) ResponseImpl(org.apache.cxf.jaxrs.impl.ResponseImpl)

Example 3 with ClientProviderFactory

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);
            }
        }
    }
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) ClientRequestFilter(javax.ws.rs.client.ClientRequestFilter) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) IOException(java.io.IOException) ClientProviderFactory(org.apache.cxf.jaxrs.client.ClientProviderFactory) Exchange(org.apache.cxf.message.Exchange) Response(javax.ws.rs.core.Response) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ProxyOutputStream(org.apache.cxf.transport.http.ProxyOutputStream) List(java.util.List) MessageImpl(org.apache.cxf.message.MessageImpl) ProcessingException(javax.ws.rs.ProcessingException)

Example 4 with ClientProviderFactory

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);
            }
        }
    }
}
Also used : ClientRequestContext(javax.ws.rs.client.ClientRequestContext) ProviderInfo(org.apache.cxf.jaxrs.model.ProviderInfo) ClientResponseFilter(javax.ws.rs.client.ClientResponseFilter) IOException(java.io.IOException) ClientProviderFactory(org.apache.cxf.jaxrs.client.ClientProviderFactory) ClientResponseContext(javax.ws.rs.client.ClientResponseContext) ProcessingException(javax.ws.rs.ProcessingException)

Aggregations

ClientProviderFactory (org.apache.cxf.jaxrs.client.ClientProviderFactory)4 ProviderInfo (org.apache.cxf.jaxrs.model.ProviderInfo)3 IOException (java.io.IOException)2 ProcessingException (javax.ws.rs.ProcessingException)2 ClientRequestContext (javax.ws.rs.client.ClientRequestContext)2 Message (org.apache.cxf.message.Message)2 InputStream (java.io.InputStream)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 List (java.util.List)1 Objects (java.util.Objects)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 CDI (javax.enterprise.inject.spi.CDI)1 Jsonb (javax.json.bind.Jsonb)1 ClientRequestFilter (javax.ws.rs.client.ClientRequestFilter)1 ClientResponseContext (javax.ws.rs.client.ClientResponseContext)1 ClientResponseFilter (javax.ws.rs.client.ClientResponseFilter)1 Response (javax.ws.rs.core.Response)1 Client (org.apache.cxf.endpoint.Client)1