You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2011/12/07 17:59:42 UTC

svn commit: r1211538 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/ rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/ rt/frontend/jax...

Author: dkulp
Date: Wed Dec  7 16:59:42 2011
New Revision: 1211538

URL: http://svn.apache.org/viewvc?rev=1211538&view=rev
Log:
Merged revisions 1211519 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1211519 | dkulp | 2011-12-07 11:35:33 -0500 (Wed, 07 Dec 2011) | 2 lines
  
  [CXF-3959] Test cases for issues with PostConstruct being called
  too many times and injections not working.
........

Added:
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
      - copied unchanged from r1211519, cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml
      - copied unchanged from r1211519, cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml
      - copied unchanged from r1211519, cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml
      - copied unchanged from r1211519, cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?rev=1211538&r1=1211537&r2=1211538&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Wed Dec  7 16:59:42 2011
@@ -269,7 +269,7 @@ public class EndpointImpl extends javax.
         return endpointName.toString() + ".jaxws-endpoint";
     }
 
-    protected JaxWsServerFactoryBean getServerFactory() {
+    public JaxWsServerFactoryBean getServerFactory() {
         return serverFactory;
     }
     

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java?rev=1211538&r1=1211537&r2=1211538&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java Wed Dec  7 16:59:42 2011
@@ -29,6 +29,7 @@ import org.w3c.dom.NamedNodeMap;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor;
+import org.apache.cxf.bus.spring.Jsr250BeanPostProcessor;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.common.util.StringUtils;
@@ -38,7 +39,6 @@ import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxws.EndpointImpl;
 import org.apache.cxf.jaxws.spi.ProviderImpl;
 import org.springframework.beans.BeansException;
-import org.springframework.beans.FatalBeanException;
 import org.springframework.beans.factory.BeanDefinitionStoreException;
 import org.springframework.beans.factory.support.AbstractBeanDefinition;
 import org.springframework.beans.factory.support.BeanDefinitionBuilder;
@@ -147,19 +147,14 @@ public class EndpointDefinitionParser ex
         bean.setLazyInit(false);
     }
 
-    @SuppressWarnings("deprecation")
     private void loadImplementor(BeanDefinitionBuilder bean, String val) {
         if (!StringUtils.isEmpty(val)) {
+            bean.addPropertyValue("checkBlockConstruct", Boolean.TRUE);
             if (val.startsWith("#")) {
                 bean.addConstructorArgReference(val.substring(1));
-                bean.addPropertyValue("checkBlockConstruct", Boolean.TRUE);
             } else {
-                try {
-                    Object obj = ClassLoaderUtils.loadClass(val, getClass()).newInstance();
-                    bean.addConstructorArg(obj);
-                } catch (Exception e) {
-                    throw new FatalBeanException("Could not load class: " + val, e);
-                }
+                bean.addConstructorArgValue(BeanDefinitionBuilder
+                                            .genericBeanDefinition(val).getBeanDefinition());
             }
         }
     }
@@ -176,6 +171,23 @@ public class EndpointDefinitionParser ex
         return id;
     }
     
+    public static final void setBlocking(ApplicationContext ctx, EndpointImpl impl) {
+        try {
+            Class<?> cls = Class
+                .forName("org.springframework.context.annotation.CommonAnnotationBeanPostProcessor");
+            if (ctx.getBeanNamesForType(cls, true, false).length != 0) {
+                //Spring will handle the postconstruct, but won't inject the 
+                // WebServiceContext so we do need to do that.
+                impl.getServerFactory().setBlockPostConstruct(true);
+            } else if (ctx.containsBean(Jsr250BeanPostProcessor.class.getName())) {
+                impl.getServerFactory().setBlockInjection(true);
+            }
+        } catch (ClassNotFoundException e) {
+            //ignore
+        }
+
+    }
+    
     @NoJSR250Annotations
     public static class SpringEndpointImpl extends EndpointImpl
         implements ApplicationContextAware {
@@ -197,19 +209,7 @@ public class EndpointDefinitionParser ex
         
         public void setApplicationContext(ApplicationContext ctx) throws BeansException {
             if (checkBlockConstruct) {
-                try {
-                    Class<?> cls = Class
-                        .forName("org.springframework.context.annotation.CommonAnnotationBeanPostProcessor");
-                    if (ctx.getBeanNamesForType(cls, true, false).length != 0) {
-                        //Spring will handle the postconstruct, but won't inject the 
-                        // WebServiceContext so we do need to do that.
-                        super.getServerFactory().setBlockPostConstruct(true);
-                    } else {
-                        super.getServerFactory().setBlockInjection(true);
-                    }
-                } catch (ClassNotFoundException e) {
-                    //ignore
-                }
+                setBlocking(ctx, this);
             }
             if (getBus() == null) {
                 setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java?rev=1211538&r1=1211537&r2=1211538&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java Wed Dec  7 16:59:42 2011
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxws22.spring;
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor;
 import org.apache.cxf.common.injection.NoJSR250Annotations;
+import org.apache.cxf.jaxws.spring.EndpointDefinitionParser;
 import org.springframework.beans.BeansException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContextAware;
@@ -46,19 +47,7 @@ public class JAXWS22SpringEndpointImpl e
     
     public void setApplicationContext(ApplicationContext ctx) throws BeansException {
         if (checkBlockConstruct) {
-            try {
-                Class<?> cls = Class
-                    .forName("org.springframework.context.annotation.CommonAnnotationBeanPostProcessor");
-                if (ctx.getBeanNamesForType(cls, true, false).length != 0) {
-                    //Spring will handle the postconstruct, but won't inject the 
-                    // WebServiceContext so we do need to do that.
-                    super.getServerFactory().setBlockPostConstruct(true);
-                } else {
-                    super.getServerFactory().setBlockInjection(true);
-                }
-            } catch (ClassNotFoundException e) {
-                //ignore
-            }
+            EndpointDefinitionParser.setBlocking(ctx, this);
         }
         if (getBus() == null) {
             setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java?rev=1211538&r1=1211537&r2=1211538&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java (original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java Wed Dec  7 16:59:42 2011
@@ -431,5 +431,36 @@ public class SpringBeansTest extends Ass
             }
         }
     }
+    
+    @Test
+    public void testCXF3959NormalImport() throws Exception {
+        PostConstructCalledCount.reset();
+        ClassPathXmlApplicationContext ctx 
+            = new ClassPathXmlApplicationContext("/org/apache/cxf/jaxws/spring/cxf3959a.xml");
+        assertNotNull(ctx);
+        assertEquals(2, PostConstructCalledCount.getCount());
+        assertEquals(2, PostConstructCalledCount.getInjectedCount());
+    }
+    @Test
+    public void testCXF3959NoImport() throws Exception {
+        PostConstructCalledCount.reset();
+        ClassPathXmlApplicationContext ctx 
+            = new ClassPathXmlApplicationContext("/org/apache/cxf/jaxws/spring/cxf3959b.xml");
+        assertNotNull(ctx);
+        assertEquals(2, PostConstructCalledCount.getCount());
+        assertEquals(2, PostConstructCalledCount.getInjectedCount());
+    }
+    @Test
+    public void testCXF3959SpringInject() throws Exception {
+        PostConstructCalledCount.reset();
+        ClassPathXmlApplicationContext ctx 
+            = new ClassPathXmlApplicationContext("/org/apache/cxf/jaxws/spring/cxf3959c.xml");
+        assertNotNull(ctx);
+        assertEquals(2, PostConstructCalledCount.getCount());
+        //only one will have the WebServiceContext injected in properly before PostConstruct
+        assertEquals(0, PostConstructCalledCount.getInjectedCount());
+        PostConstructCalledCount pc = ctx.getBean("theBean", PostConstructCalledCount.class);
+        assertNotNull(pc.getContext());
+    }
 }