johnament commented on a change in pull request #359: Adding an implementation of the MicroProfile Rest Client v1.0 URL: https://github.com/apache/cxf/pull/359#discussion_r157662654
########## File path: rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientFactoryBean.java ########## @@ -0,0 +1,118 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.microprofile.client; + +import java.net.URI; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import javax.ws.rs.client.ClientRequestFilter; +import javax.ws.rs.client.ClientResponseFilter; +import javax.ws.rs.core.Configuration; + +import org.apache.cxf.common.util.ClassHelper; +import org.apache.cxf.endpoint.Endpoint; +import org.apache.cxf.jaxrs.client.AbstractClient; +import org.apache.cxf.jaxrs.client.ClientProxyImpl; +import org.apache.cxf.jaxrs.client.ClientState; +import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; +import org.apache.cxf.jaxrs.model.ClassResourceInfo; +import org.apache.cxf.jaxrs.model.FilterProviderInfo; +import org.apache.cxf.jaxrs.model.ProviderInfo; +import org.apache.cxf.microprofile.client.proxy.MicroProfileClientProxyImpl; +import org.eclipse.microprofile.rest.client.RestClientBuilder; + +public class MicroProfileClientFactoryBean extends JAXRSClientFactoryBean { + private final Comparator<ProviderInfo<?>> comparator; + private final List<Object> registeredProviders; + private Configuration configuration; + private ClassLoader proxyLoader; + private boolean inheritHeaders; + + public MicroProfileClientFactoryBean(MicroProfileClientConfigurableImpl<RestClientBuilder> configuration, + String baseUri, Class<?> aClass) { + super(); + this.configuration = configuration.getConfiguration(); + this.comparator = MicroProfileClientProviderFactory.createComparator(this); + super.setAddress(baseUri); + super.setServiceClass(aClass); + super.setProviderComparator(comparator); + registeredProviders = new ArrayList<>(); + registeredProviders.addAll(processProviders()); + if (!configuration.isDefaultExceptionMapperDisabled()) { + registeredProviders.add(new DefaultResponseExceptionMapper()); + } + registeredProviders.add(new JsonPProvider()); + super.setProviders(registeredProviders); + } + + @Override + public void setClassLoader(ClassLoader loader) { + super.setClassLoader(loader); + this.proxyLoader = loader; + } + + @Override + public void setInheritHeaders(boolean inheritHeaders) { + super.setInheritHeaders(inheritHeaders); + this.inheritHeaders = inheritHeaders; + } + + @Override + protected void initClient(AbstractClient client, Endpoint ep, boolean addHeaders) { + super.initClient(client, ep, addHeaders); + MicroProfileClientProviderFactory factory = MicroProfileClientProviderFactory.createInstance(getBus(), + comparator); + factory.setUserProviders(registeredProviders); + ep.put(MicroProfileClientProviderFactory.CLIENT_FACTORY_NAME, factory); + } + + @Override + protected ClientProxyImpl createClientProxy(ClassResourceInfo cri, boolean isRoot, + ClientState actualState, Object[] varValues) { + if (actualState == null) { + return new MicroProfileClientProxyImpl(URI.create(getAddress()), proxyLoader, cri, isRoot, + inheritHeaders, varValues); + } else { + return new MicroProfileClientProxyImpl(actualState, proxyLoader, cri, isRoot, + inheritHeaders, varValues); + } + } + + Configuration getConfiguration() { + return configuration; + } + + private Set<Object> processProviders() { Review comment: I suspect this will be useful to move into the main client, since it handles converting filters into `FilterProviderInfo` objects, rather than regular `ProviderInfo`s ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
