org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory Java Examples

The following examples show how to use org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MicroProfileClientProxyImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void mergeHeaders(Class<ClientHeadersFactory> factoryCls, MultivaluedMap<String, String> existingHeaders) {

        try {
            ClientHeadersFactory factory;

            Message m = JAXRS_UTILS_GET_CURRENT_MESSAGE_METHOD == null ? null
                : (Message) JAXRS_UTILS_GET_CURRENT_MESSAGE_METHOD.invoke(null);

            if (m != null) {
                factory = CDIFacade.getInstanceFromCDI(factoryCls, m.getExchange().getBus())
                                   .map(this::mapInstance)
                                   .orElse(factoryCls.newInstance());
                ProviderInfo<ClientHeadersFactory> pi = clientHeaderFactories.computeIfAbsent(factoryCls, k -> {
                    return new ProviderInfo<ClientHeadersFactory>(factory, m.getExchange().getBus(), true);
                });
                InjectionUtils.injectContexts(factory, pi, m);
            } else {
                factory = CDIFacade.getInstanceFromCDI(factoryCls)
                                   .map(this::mapInstance)
                                   .orElse(factoryCls.newInstance());
            }

            MultivaluedMap<String, String> updatedHeaders = factory.update(getJaxrsHeaders(m), existingHeaders);
            existingHeaders.putAll(updatedHeaders);
        } catch (Throwable t) {
            // expected if not running in a JAX-RS server environment.
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.log(Level.FINEST, "Caught exception getting JAX-RS incoming headers", t);
            }
        }
    }