This is an automated email from the ASF dual-hosted git repository.

johndament pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 19cfc93617e0f9012987e6047c44865d0cb24584
Author: John D. Ament <[email protected]>
AuthorDate: Thu Dec 7 06:35:47 2017 -0500

    [CXF-7579] More config impl.
---
 .../client/CxfTypeSafeClientBuilder.java           | 27 ++++------
 .../client/MicroProfileClientConfigurableImpl.java | 50 +++++++++++++++++
 .../client/MicroProfileClientFactoryBean.java      | 62 ++++++++++++++++++++++
 .../client/CxfTypeSafeClientBuilderTest.java       |  2 +-
 4 files changed, 123 insertions(+), 18 deletions(-)

diff --git 
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilder.java
 
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilder.java
index 8fc7b54..904731c 100644
--- 
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilder.java
+++ 
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilder.java
@@ -19,22 +19,17 @@
 package org.apache.cxf.microprofile.client;
 
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import javax.ws.rs.core.Configurable;
 import javax.ws.rs.core.Configuration;
-import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
-import org.apache.cxf.jaxrs.client.spec.ClientConfigurableImpl;
 import org.eclipse.microprofile.rest.client.RestClientBuilder;
 import org.eclipse.microprofile.rest.client.annotation.RegisterProviders;
 
-public class CxfTypeSafeClientBuilder implements RestClientBuilder {
+public class CxfTypeSafeClientBuilder implements RestClientBuilder, 
Configurable<RestClientBuilder> {
     private String baseUri;
-    private final Configurable<CxfTypeSafeClientBuilder> configImpl =
-        new ClientConfigurableImpl(this);
+    private final MicroProfileClientConfigurableImpl<RestClientBuilder> 
configImpl =
+            new MicroProfileClientConfigurableImpl<>(this);
 
     @Override
     public RestClientBuilder baseUrl(URL url) {
@@ -48,18 +43,16 @@ public class CxfTypeSafeClientBuilder implements 
RestClientBuilder {
             throw new IllegalStateException("baseUrl not set");
         }
         RegisterProviders providers = 
aClass.getAnnotation(RegisterProviders.class);
-        List<Object> providerClasses = new ArrayList<>();
         Configuration config = configImpl.getConfiguration();
-        providerClasses.addAll(config.getClasses());
-        providerClasses.addAll(config.getInstances());
         if (providers != null) {
-            providerClasses.addAll(Arrays.asList(providers.value()));
+            for (Class<?> c : providers.value()) {
+                if (!config.isRegistered(c)) {
+                    register(c);
+                }
+            }
         }
-        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
-        bean.setAddress(baseUri);
-        bean.setServiceClass(aClass);
-        bean.setProviders(providerClasses);
-        bean.setProperties(config.getProperties());
+        MicroProfileClientFactoryBean bean = new 
MicroProfileClientFactoryBean(getConfiguration(),
+                baseUri, aClass);
         return bean.create(aClass);
     }
 
diff --git 
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientConfigurableImpl.java
 
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientConfigurableImpl.java
new file mode 100644
index 0000000..9a6ccbc
--- /dev/null
+++ 
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientConfigurableImpl.java
@@ -0,0 +1,50 @@
+/**
+ * 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 javax.ws.rs.RuntimeType;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.Configurable;
+import javax.ws.rs.core.Configuration;
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.WriterInterceptor;
+import org.apache.cxf.jaxrs.impl.ConfigurableImpl;
+import org.apache.cxf.jaxrs.impl.ConfigurationImpl;
+import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
+
+public class MicroProfileClientConfigurableImpl<C extends Configurable<C>>
+        extends ConfigurableImpl<C>
+    implements Configurable<C> {
+    static final Class<?>[] CONTRACTS = new Class<?>[] 
{ClientRequestFilter.class,
+        ClientResponseFilter.class, ReaderInterceptor.class, 
WriterInterceptor.class,
+        MessageBodyWriter.class, MessageBodyReader.class, 
ResponseExceptionMapper.class};
+
+    public MicroProfileClientConfigurableImpl(C configurable) {
+        this(configurable, null);
+    }
+
+    public MicroProfileClientConfigurableImpl(C configurable, Configuration 
config) {
+        super(configurable,
+                CONTRACTS, config == null ? new 
ConfigurationImpl(RuntimeType.CLIENT)
+                        : new ConfigurationImpl(config, CONTRACTS));
+    }
+}
diff --git 
a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientFactoryBean.java
 
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientFactoryBean.java
new file mode 100644
index 0000000..4499807
--- /dev/null
+++ 
b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientFactoryBean.java
@@ -0,0 +1,62 @@
+/**
+ * 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.util.Comparator;
+import java.util.Map;
+import javax.ws.rs.core.Configuration;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
+import static 
org.apache.cxf.microprofile.client.MicroProfileClientConfigurableImpl.CONTRACTS;
+
+public class MicroProfileClientFactoryBean extends JAXRSClientFactoryBean {
+    private Configuration configuration;
+
+    public MicroProfileClientFactoryBean(Configuration configuration, String 
baseUri, Class<?> aClass) {
+        super();
+        this.configuration = configuration;
+        super.setAddress(baseUri);
+        super.setServiceClass(aClass);
+        super.setProviderComparator(new ContractComparator());
+    }
+
+    private class ContractComparator implements Comparator<Object> {
+        @Override
+        public int compare(Object o1, Object o2) {
+            int left = getPriority(o1.getClass());
+            int right = getPriority(o2.getClass());
+            return right - left;
+        }
+
+        private int getPriority(Class<?> clazz) {
+            for (Class<?> providerClass : CONTRACTS) {
+                Map<Class<?>, Integer> contracts = 
MicroProfileClientFactoryBean.this.
+                        configuration.getContracts(providerClass);
+                if (contracts != null) {
+                    Integer priority = contracts.get(clazz);
+                    if (priority != null) {
+                        return priority;
+                    }
+                }
+            }
+            return AnnotationUtils.getBindingPriority(clazz);
+        }
+    }
+
+}
diff --git 
a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilderTest.java
 
b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilderTest.java
index 8d6d1a0..e903f09 100644
--- 
a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilderTest.java
+++ 
b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/CxfTypeSafeClientBuilderTest.java
@@ -44,8 +44,8 @@ public class CxfTypeSafeClientBuilderTest extends Assert {
 
     }
 
-    @Ignore
     @Test
+    @Ignore
     public void testConfigPriorityOverrides() throws Exception {
         RestClientBuilder builder = RestClientBuilder.newBuilder();
         builder.register(HighPriorityClientReqFilter.class); // annotation 
priority of 10

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

Reply via email to