cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r563581 - in /incubator/cxf/trunk/rt/core/src: main/java/org/apache/cxf/bus/spring/ main/resources/META-INF/cxf/ test/java/org/apache/cxf/bus/spring/
Date Tue, 07 Aug 2007 17:35:44 GMT
Author: andreasmyth
Date: Tue Aug  7 10:35:43 2007
New Revision: 563581

URL: http://svn.apache.org/viewvc?view=rev&rev=563581
Log:
Fixed problem with BusExtensionPostProcessor whereby its early resolving a reference to the
bus had the effect that some beans' @PostConstruct annotated methods were not called.

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java?view=diff&rev=563581&r1=563580&r2=563581
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusExtensionPostProcessor.java
Tue Aug  7 10:35:43 2007
@@ -31,22 +31,12 @@
 public class BusExtensionPostProcessor implements BeanPostProcessor, ApplicationContextAware,
Ordered {
 
     private Bus bus;
+    private ApplicationContext context;
 
     public void setApplicationContext(ApplicationContext ctx) {
-        //nothing to do
-        if (bus == null) {
-            bus = (Bus)ctx.getBean(Bus.DEFAULT_BUS_ID);
-        }
-    }
-
-    public void setBus(Bus b) {
-        bus = b;
+        context = ctx;
     } 
     
-    public Bus getBus() {
-        return bus;
-    }
-    
     public int getOrder() {
         return 1001;
     }
@@ -58,11 +48,18 @@
 
     @SuppressWarnings("unchecked")
     public Object postProcessBeforeInitialization(Object bean, String beanId) throws BeansException
{
-        if (null != bus && bean instanceof BusExtension) {
+        if (null != getBus() && bean instanceof BusExtension) {
             Class cls = ((BusExtension)bean).getRegistrationType();
-            bus.setExtension(bean, cls);
+            getBus().setExtension(bean, cls);
         }
         return bean;
+    }
+    
+    private Bus getBus() {
+        if (bus == null) {
+            bus = (Bus)context.getBean(Bus.DEFAULT_BUS_ID);
+        }
+        return bus;
     }
 
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java?view=diff&rev=563581&r1=563580&r2=563581
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/SpringBusFactory.java
Tue Aug  7 10:35:43 2007
@@ -69,10 +69,11 @@
         final Bus bus = (Bus)bac.getBean(Bus.DEFAULT_BUS_ID);
 
         bus.setExtension(new ConfigurerImpl(bac), Configurer.class);
+        bus.setExtension(bac, BusApplicationContext.class);
 
         possiblySetDefaultBus(bus);
         
-        initializeBus(bus);
+        initializeBus(bus);        
         
         registerApplicationContextLifeCycleListener(bus, bac);
         return bus;

Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml?view=diff&rev=563581&r1=563580&r2=563581
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml (original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/cxf/cxf.xml Tue Aug  7 10:35:43
2007
@@ -24,10 +24,8 @@
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
 
     <bean id="cxf" class="org.apache.cxf.bus.CXFBusImpl"/>
-    <bean class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>
-    <bean class="org.apache.cxf.bus.spring.BusExtensionPostProcessor">
-       <property name="bus" ref="cxf"/>
-    </bean>
+    <bean class="org.apache.cxf.bus.spring.Jsr250BeanPostProcessor"/>    
+    <bean class="org.apache.cxf.bus.spring.BusExtensionPostProcessor"/>
     
     <bean id="org.apache.cxf.resource.ResourceManager" class="org.apache.cxf.bus.resource.ResourceManagerImpl">
        <constructor-arg>

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java?view=diff&rev=563581&r1=563580&r2=563581
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/BusDefinitionParserTest.java
Tue Aug  7 10:35:43 2007
@@ -19,9 +19,14 @@
 
 package org.apache.cxf.bus.spring;
 
+import java.util.Collection;
 import java.util.List;
 
+import javax.annotation.PostConstruct;
+
 import org.apache.cxf.Bus;
+import org.apache.cxf.bus.CXFBusImpl;
+import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.junit.Assert;
@@ -42,6 +47,45 @@
             }
         }
         assertTrue("could not find logging interceptor.", found);
+   
+        Collection<AbstractFeature> features = ((CXFBusImpl)bus).getFeatures();
+        TestFeature tf = null;
+        for (AbstractFeature f : features) {
+            if (f instanceof TestFeature) {
+                tf = (TestFeature)f;
+                break;
+            }
+        }
+        
+        assertNotNull(tf);
+        assertTrue("test feature  has not been initialised", tf.initialised);
+        assertNotNull("test feature has not been injected", tf.testBean);
+        assertTrue("bean injected into test feature has not been initialised", tf.testBean.initialised);
+    }
+    
+    static class TestBean {
+
+        boolean initialised;
+        
+        @PostConstruct
+        public void initialise() {
+            initialised = true;
+        }
+    }
+    
+    static class TestFeature extends AbstractFeature {
+        
+        boolean initialised;
+        TestBean testBean;
+        
+        @PostConstruct
+        public void initialise() {
+            initialised = true;
+        }
+
+        public void setTestBean(TestBean tb) {
+            testBean = tb;
+        }
     }
     
 }

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java?view=diff&rev=563581&r1=563580&r2=563581
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
(original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
Tue Aug  7 10:35:43 2007
@@ -169,7 +169,8 @@
     @Test
     public void testInitialisation() {
         Bus bus = new SpringBusFactory().createBus("org/apache/cxf/bus/spring/init.xml");
-        assertNotNull(bus.getExtension(TestListener.class));        
+        assertNotNull(bus.getExtension(TestListener.class));           
+        assertSame(bus, bus.getExtension(BusApplicationContext.class).getBean("cxf"));
     }
 
     

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml?view=diff&rev=563581&r1=563580&r2=563581
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml (original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/spring/bus.xml Tue Aug  7
10:35:43 2007
@@ -24,10 +24,15 @@
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
 
+
   <c:bus>
     <c:features>
       <c:logging />
+      <bean class="org.apache.cxf.bus.spring.BusDefinitionParserTest$TestFeature">
+         <property name="testBean" ref="tb"/>
+      </bean>
     </c:features>
-  </c:bus>
+  </c:bus>  
+  <bean id="tb" class="org.apache.cxf.bus.spring.BusDefinitionParserTest$TestBean"/>
 
-</beans>
\ No newline at end of file
+</beans>



Mime
View raw message