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 JAX-RS Spring parser to do a last try and check the matching resources if none of them have been set previously
Date Wed, 03 Dec 2014 14:37:49 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 50f5cd8c3 -> 83205e07b


Updating JAX-RS Spring parser to do a last try and check the matching resources if none of
them have been set previously


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

Branch: refs/heads/master
Commit: 83205e07bc890c794032a85735adde1fedd0f565
Parents: 50f5cd8
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Dec 3 14:37:31 2014 +0000
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Dec 3 14:37:31 2014 +0000

----------------------------------------------------------------------
 .../AbstractSpringComponentScanServer.java      | 18 ++++++++++----
 .../AbstractSpringConfigurationFactory.java     |  6 ++---
 .../JAXRSServerFactoryBeanDefinitionParser.java | 25 ++++++++++++++++++--
 .../org/apache/cxf/jaxrs/spring/servers.xml     |  4 ++++
 4 files changed, 43 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/83205e07/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 cb05d1c..31284aa 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
@@ -37,23 +37,31 @@ public abstract class AbstractSpringComponentScanServer extends AbstractSpringCo
 
     private List<ResourceProvider> resourceProviders = new LinkedList<ResourceProvider>();
     private List<Object> jaxrsProviders = new LinkedList<Object>();
-
-    
-    protected void setRootResources(JAXRSServerFactoryBean factory) {
+    private Class<? extends Annotation> serviceAnnotation;
+    protected AbstractSpringComponentScanServer() {
+        
+    }
+    protected AbstractSpringComponentScanServer(Class<? extends Annotation> serviceAnnotation)
{
+        this.serviceAnnotation = serviceAnnotation;
+    }
+    protected void setJaxrsResources(JAXRSServerFactoryBean factory) {
         boolean checkJaxrsRoots = checkJaxrsRoots();
         boolean checkJaxrsProviders = checkJaxrsProviders(); 
         
         for (String beanName : applicationContext.getBeanDefinitionNames()) {
-            if (checkJaxrsRoots && isAnnotationAvailable(beanName, Path.class)) {
+            if (checkJaxrsRoots && isAnnotationAvailable(beanName, Path.class)
+                && (serviceAnnotation == null || isAnnotationAvailable(beanName,
serviceAnnotation))) {
                 SpringResourceFactory resourceFactory = new SpringResourceFactory(beanName);
                 resourceFactory.setApplicationContext(applicationContext);
                 resourceProviders.add(resourceFactory);
-            } else if (checkJaxrsProviders && isAnnotationAvailable(beanName, Provider.class))
{
+            } else if (checkJaxrsProviders && isAnnotationAvailable(beanName, Provider.class)
+                && (serviceAnnotation == null || isAnnotationAvailable(beanName,
serviceAnnotation))) {
                 jaxrsProviders.add(applicationContext.getBean(beanName));
             }
         }
 
         factory.setResourceProviders(getResourceProviders());
+        factory.setProviders(getJaxrsProviders());
     }
     
     protected <A extends Annotation> boolean isAnnotationAvailable(String beanName,
Class<A> annClass) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/83205e07/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
index f8f827e..1ee09fa 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/AbstractSpringConfigurationFactory.java
@@ -44,8 +44,8 @@ public abstract class AbstractSpringConfigurationFactory
         factory.setTransportId(getTransportId());
         factory.setBus(applicationContext.getBean(SpringBus.class));
         
-        setRootResources(factory);
-        factory.setProviders(getJaxrsProviders());
+        setJaxrsResources(factory);
+        
         factory.setInInterceptors(getInInterceptors());
         factory.setOutInterceptors(getOutInterceptors());
         factory.setOutFaultInterceptors(getOutFaultInterceptors());
@@ -59,7 +59,7 @@ public abstract class AbstractSpringConfigurationFactory
         applicationContext = ac;
     }
     
-    protected abstract void setRootResources(JAXRSServerFactoryBean factory);
+    protected abstract void setJaxrsResources(JAXRSServerFactoryBean factory);
     
     protected List<Object> getJaxrsProviders() {
         return Collections.emptyList();

http://git-wip-us.apache.org/repos/asf/cxf/blob/83205e07/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
index e6f33ce..672d709 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanDefinitionParser.java
@@ -157,6 +157,10 @@ public class JAXRSServerFactoryBeanDefinitionParser extends AbstractBeanDefiniti
         private List<String> basePackages;
         private String serviceAnnotation;
         private ApplicationContext context;
+        private boolean serviceBeansAvailable;
+        private boolean providerBeansAvailable;
+        private boolean resourceProvidersAvailable;
+        
         public SpringJAXRSServerFactoryBean() {
             super();
         }
@@ -171,7 +175,20 @@ public class JAXRSServerFactoryBeanDefinitionParser extends AbstractBeanDefiniti
                 server.destroy();
             }
         }
-        
+        @Override
+        public void setServiceBeans(List<Object> beans) {
+            super.setServiceBeans(beans);
+            this.serviceBeansAvailable = true;
+        }
+        @Override
+        public void setProviders(List<? extends Object> beans) {
+            super.setProviders(beans);
+            this.providerBeansAvailable = true;
+        }
+        public void setResourceProviders(List<ResourceProvider> rps) {
+            super.setResourceProviders(rps);
+            this.resourceProvidersAvailable = true;
+        }
         public void setBasePackages(List<String> basePackages) {
             this.basePackages = basePackages;
         }
@@ -196,7 +213,7 @@ public class JAXRSServerFactoryBeanDefinitionParser extends AbstractBeanDefiniti
                     factories.add(factory);
                 }
                 tempFactories.clear();
-                super.setResourceProviders(factories);
+                setResourceProviders(factories);
             }
             Class<? extends Annotation> serviceAnnotationClass = loadServiceAnnotationClass();
             if (basePackages != null) {
@@ -226,6 +243,10 @@ public class JAXRSServerFactoryBeanDefinitionParser extends AbstractBeanDefiniti
                 }
                 this.setServiceBeans(services);
                 this.setProviders(providers);
+            } else if (!serviceBeansAvailable && !providerBeansAvailable &&
!resourceProvidersAvailable) {
+                AbstractSpringComponentScanServer scanServer = new AbstractSpringComponentScanServer()
{ };
+                scanServer.setApplicationContext(context);
+                scanServer.setJaxrsResources(this);
             }
             if (bus == null) {
                 setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));

http://git-wip-us.apache.org/repos/asf/cxf/blob/83205e07/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
index 5061d56..cc75402 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
@@ -48,6 +48,10 @@
         <jaxrs:extensionMappings>
             <entry key="json" value="application/json"/>
         </jaxrs:extensionMappings>
+        <jaxrs:serviceBeans>
+            <bean class="org.apache.cxf.jaxrs.resources.BookStore"/>
+            <bean class="org.apache.cxf.jaxrs.resources.BookStoreSubresourcesOnly"/>
+        </jaxrs:serviceBeans>
     </jaxrs:server>
     <bean id="dataBinding" class="org.apache.cxf.jaxrs.provider.DataBindingProvider"/>
     <bean id="jaxb" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">


Mime
View raw message