cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Updating the jaxrs scan server to optionally look for non-component classes and updated the client enablers to scan for component providers
Date Thu, 07 Jul 2016 13:12:25 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 87091eefd -> 5bbd03f80


Updating the jaxrs scan server to optionally look for non-component classes and updated the
client enablers to scan for component providers


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5bbd03f8
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5bbd03f8
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5bbd03f8

Branch: refs/heads/3.1.x-fixes
Commit: 5bbd03f8052adb653dc8fa1a2c4ce50737a95405
Parents: 87091ee
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Thu Jul 7 13:59:38 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Thu Jul 7 14:05:09 2016 +0100

----------------------------------------------------------------------
 .../rs/service/SampleRestApplication.java       |  2 +-
 .../src/main/resources/application.properties   |  1 +
 .../rs/service/SampleScanRestApplication.java   |  4 ---
 .../src/main/resources/application.yml          |  1 +
 .../AbstractSpringComponentScanServer.java      | 37 ++++++++++++++++++--
 .../AbstractJaxRsClientConfiguration.java       | 20 ++++++++++-
 .../client/spring/WebClientConfiguration.java   | 17 ++++++++-
 7 files changed, 73 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java
b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java
index 8839c1b..2bc20df 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/java/sample/rs/service/SampleRestApplication.java
@@ -63,7 +63,7 @@ public class SampleRestApplication {
 
         @Override
         public void run(String... runArgs) throws Exception {
-            System.out.println(webClient.accept("text/plain").path("sayHello/ApacheCxfWebClientUser").get(String.class));
+            System.out.println(webClient.path("sayHello/ApacheCxfWebClientUser").get(String.class));
         }
       };
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/resources/application.properties
b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/resources/application.properties
index 955d403..90e32e8 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/resources/application.properties
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot/src/main/resources/application.properties
@@ -1,3 +1,4 @@
 cxf.path=/services/helloservice
 cxf.jaxrs.client.address=http://localhost:8080/services/helloservice
+cxf.jaxrs.client.headers.accept=text/plain
 cxf.jaxrs.client.classes-scan-packages=sample.rs.service

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
index 68db191..9940733 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/java/sample/rs/service/SampleScanRestApplication.java
@@ -36,10 +36,6 @@ public class SampleScanRestApplication {
     }
  
     @Bean
-    public Swagger2Feature swaggerFeature(ApplicationContext context) {
-        return new Swagger2Feature();
-    }
-    @Bean
     @ExportMetricWriter
     public MetricWriter metricWriter() {
             return new MetricWriter() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
index 3643f09..b9582e6 100644
--- a/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
+++ b/distribution/src/main/release/samples/jax_rs/spring_boot_scan/application/src/main/resources/application.yml
@@ -8,6 +8,7 @@ cxf:
     service-list-path: /info
   jaxrs:
     component-scan: true
+    classes-scan-packages: org.apache.cxf.jaxrs.swagger
 
 eureka:
   client:

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
index 927c5e2..e1e6e21 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringComponentScanServer.java
@@ -19,18 +19,24 @@
 package org.apache.cxf.jaxrs.spring;
 
 import java.lang.annotation.Annotation;
+import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.Path;
 import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.annotations.Provider.Scope;
+import org.apache.cxf.common.util.ClasspathScanner;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.feature.Feature;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.service.factory.ServiceConstructionException;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.FilterType;
 
@@ -42,12 +48,16 @@ import org.springframework.context.annotation.FilterType;
 )
 public abstract class AbstractSpringComponentScanServer extends AbstractSpringConfigurationFactory
{
 
+    @Value("${cxf.jaxrs.classes-scan-packages:''}")
+    private String classesScanPackages;
+    
     private List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
     private List<Object> jaxrsProviders = new LinkedList<Object>();
     private List<Feature> cxfFeatures = new LinkedList<Feature>();
     private List<Interceptor<? extends Message>> cxfInInterceptors = new LinkedList<Interceptor<?>>();
     private List<Interceptor<? extends Message>> cxfOutInterceptors = new LinkedList<Interceptor<?>>();
     private Class<? extends Annotation> serviceAnnotation;
+    
     protected AbstractSpringComponentScanServer() {
         
     }
@@ -67,13 +77,33 @@ public abstract class AbstractSpringComponentScanServer extends AbstractSpringCo
                 resourceProviders.add(resourceFactory);
             } else if (checkJaxrsProviders && isAnnotationAvailable(beanName, Provider.class)
                 && matchesServiceAnnotation(beanName)) {
-                jaxrsProviders.add(applicationContext.getBean(beanName));
+                jaxrsProviders.add(getProviderBean(beanName));
             } else if (checkCxfProviders && isAnnotationAvailable(beanName, 
                 org.apache.cxf.annotations.Provider.class) && matchesServiceAnnotation(beanName))
{
-                addCxfProvider(applicationContext.getBean(beanName));
+                addCxfProvider(getProviderBean(beanName));
             }
         }
 
+        if (!StringUtils.isEmpty(classesScanPackages)) {
+            try {
+                final Map< Class< ? extends Annotation >, Collection< Class<
? > > > classes =
+                    ClasspathScanner.findClasses(classesScanPackages, Provider.class, 
+                                                 org.apache.cxf.annotations.Provider.class);
+                                          
+                jaxrsProviders.addAll(JAXRSServerFactoryBeanDefinitionParser
+                    .createBeansFromDiscoveredClasses(super.applicationContext, classes.get(Provider.class),
null));
+                List<Object> cxfProviders = JAXRSServerFactoryBeanDefinitionParser
+                    .createBeansFromDiscoveredClasses(super.applicationContext, 
+                                                      classes.get(org.apache.cxf.annotations.Provider.class),

+                                                      null);
+                for (Object cxfProvider : cxfProviders) {
+                    addCxfProvider(cxfProvider);
+                }
+            } catch (Exception ex) {
+                throw new ServiceConstructionException(ex);
+            }
+        }
+        
         factory.setResourceProviders(getResourceProviders());
         factory.setProviders(getJaxrsProviders());
         factory.setFeatures(getFeatures());
@@ -82,6 +112,9 @@ public abstract class AbstractSpringComponentScanServer extends AbstractSpringCo
         
     }
     
+    private Object getProviderBean(String beanName) {
+        return applicationContext.getBean(beanName);
+    }
     protected void addCxfProvider(Object bean) {
         org.apache.cxf.annotations.Provider ann = 
             bean.getClass().getAnnotation(org.apache.cxf.annotations.Provider.class);

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/AbstractJaxRsClientConfiguration.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/AbstractJaxRsClientConfiguration.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/AbstractJaxRsClientConfiguration.java
index 87931f8..560d45e 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/AbstractJaxRsClientConfiguration.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/AbstractJaxRsClientConfiguration.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.jaxrs.client.spring;
 
+import javax.ws.rs.ext.Provider;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.jaxrs.client.Client;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
@@ -27,9 +29,15 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.FilterType;
 import org.springframework.context.annotation.Import;
 
 @Import(JaxRsConfig.class)
+@ComponentScan(
+               includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, 
+                                                      value = {Provider.class})
+           )
 public abstract class AbstractJaxRsClientConfiguration implements ApplicationContextAware
{
 
     protected ApplicationContext context;
@@ -37,17 +45,27 @@ public abstract class AbstractJaxRsClientConfiguration implements ApplicationCon
     private Bus bus;
     @Value("${cxf.jaxrs.client.address}")
     private String address;
+    @Value("${cxf.jaxrs.client.thread-safe:false}")
+    private Boolean threadSafe;
+    
     
     protected Client createClient() {
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         bean.setBus(bus);        
         bean.setAddress(address);
+        bean.setThreadSafe(threadSafe);
         setJaxrsResources(bean);
+        
+        for (String beanName : context.getBeanDefinitionNames()) {
+            if (context.findAnnotationOnBean(beanName, Provider.class) != null) {
+                bean.setProvider(context.getBean(beanName));
+            } 
+        }
+        
         return bean.create();
     }
     
     protected abstract void setJaxrsResources(JAXRSClientFactoryBean factory);
-
     
     @Override
     public void setApplicationContext(ApplicationContext ac) throws BeansException {

http://git-wip-us.apache.org/repos/asf/cxf/blob/5bbd03f8/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/WebClientConfiguration.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/WebClientConfiguration.java
b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/WebClientConfiguration.java
index 72a5164..ccac861 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/WebClientConfiguration.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spring/WebClientConfiguration.java
@@ -20,6 +20,7 @@ package org.apache.cxf.jaxrs.client.spring;
 
 import java.lang.annotation.Annotation;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 
 import javax.ws.rs.ext.Provider;
@@ -35,8 +36,12 @@ import org.springframework.context.annotation.Bean;
 
 public class WebClientConfiguration extends AbstractJaxRsClientConfiguration {
 
-    @Value("${cxf.jaxrs.client.classes-scan-packages:''")
+    @Value("${cxf.jaxrs.client.classes-scan-packages:''}")
     private String scanPackages;
+    @Value("${cxf.jaxrs.client.headers.accept:''}")
+    private String accept;
+    @Value("${cxf.jaxrs.client.headers.content-type:''}")
+    private String contentType;
     
     @Bean
     protected Client jaxRsWebClient() {
@@ -58,6 +63,16 @@ public class WebClientConfiguration extends AbstractJaxRsClientConfiguration
{
                 throw new ServiceConstructionException(ex);
             }
         }
+        Map<String, String> extraHeaders = new HashMap<String, String>();
+        if (!StringUtils.isEmpty(accept)) {
+            extraHeaders.put("Accept", accept);
+        }
+        if (!StringUtils.isEmpty(contentType)) {
+            extraHeaders.put("Content-Type", contentType);
+        }
+        if (!extraHeaders.isEmpty()) {
+            factory.setHeaders(extraHeaders);
+        }
     }
 
     


Mime
View raw message