cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1211229 - in /cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws: JaxWsServerFactoryBean.java spring/EndpointDefinitionParser.java
Date Tue, 06 Dec 2011 23:42:20 GMT
Author: dkulp
Date: Tue Dec  6 23:42:20 2011
New Revision: 1211229

URL: http://svn.apache.org/viewvc?rev=1211229&view=rev
Log:
[CXF-3959] Fix issues of double injection with Spring Part 1

Modified:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java?rev=1211229&r1=1211228&r2=1211229&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JaxWsServerFactoryBean.java
Tue Dec  6 23:42:20 2011
@@ -65,6 +65,7 @@ public class JaxWsServerFactoryBean exte
     protected List<Handler> handlers = new ArrayList<Handler>();
 
     private boolean blockPostConstruct;
+    private boolean blockInjection;
     
     public JaxWsServerFactoryBean() {
         this(new JaxWsServiceFactoryBean());
@@ -255,7 +256,7 @@ public class JaxWsServerFactoryBean exte
      * @param instance
      */
     protected void injectResources(Object instance) {
-        if (instance != null) {
+        if (instance != null && !blockInjection) {
             ResourceManager resourceManager = getBus().getExtension(ResourceManager.class);
             List<ResourceResolver> resolvers = resourceManager.getResourceResolvers();
             resourceManager = new DefaultResourceManager(resolvers); 
@@ -276,7 +277,6 @@ public class JaxWsServerFactoryBean exte
     }
 
     /**
-     * 
      * @param blockPostConstruct @PostConstruct method will not be called 
      *  if this property is set to true - this may be necessary in cases
      *  when the @PostConstruct method needs to be called at a later stage,
@@ -285,5 +285,14 @@ public class JaxWsServerFactoryBean exte
     public void setBlockPostConstruct(boolean blockPostConstruct) {
         this.blockPostConstruct = blockPostConstruct;
     }
+    /**
+     * No injection or PostContstuct will be called if this is set to true.
+     * If the container has already handled the injection, this should 
+     * be set to true.
+     * @param b
+     */
+    public void setBlockInjection(boolean b) {
+        this.blockInjection = b;
+    }
       
 }

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java?rev=1211229&r1=1211228&r2=1211229&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
Tue Dec  6 23:42:20 2011
@@ -152,6 +152,7 @@ public class EndpointDefinitionParser ex
         if (!StringUtils.isEmpty(val)) {
             if (val.startsWith("#")) {
                 bean.addConstructorArgReference(val.substring(1));
+                bean.addPropertyValue("checkBlockConstuct", Boolean.TRUE);
             } else {
                 try {
                     Object obj = ClassLoaderUtils.loadClass(val, getClass()).newInstance();
@@ -179,6 +180,8 @@ public class EndpointDefinitionParser ex
     public static class SpringEndpointImpl extends EndpointImpl
         implements ApplicationContextAware {
     
+        boolean checkBlockConstruct;
+        
         public SpringEndpointImpl(Object o) {
             super(o instanceof Bus ? (Bus)o : null,
                 o instanceof Bus ? null : o);
@@ -188,8 +191,26 @@ public class EndpointDefinitionParser ex
             super(bus, implementor);
         }
         
+        public void setCheckBlockConstuct(Boolean b) {
+            checkBlockConstruct = b;
+        }
         
         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
+                }
+            }
             if (getBus() == null) {
                 setBus(BusWiringBeanFactoryPostProcessor.addDefaultBus(ctx));
             }



Mime
View raw message