cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1211519 - in /cxf/trunk/rt/frontend/jaxws/src: main/java/org/apache/cxf/jaxws/ main/java/org/apache/cxf/jaxws/spring/ main/jaxws22/org/apache/cxf/jaxws22/spring/ test/java/org/apache/cxf/jaxws/spring/
Date Wed, 07 Dec 2011 16:35:34 GMT
Author: dkulp
Date: Wed Dec  7 16:35:33 2011
New Revision: 1211519

URL: http://svn.apache.org/viewvc?rev=1211519&view=rev
Log:
[CXF-3959] Test cases for issues with PostConstruct being called
too many times and injections not working.

Added:
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
  (with props)
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml   (with
props)
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml   (with
props)
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml   (with
props)
Modified:
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spring/EndpointDefinitionParser.java
    cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java

Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?rev=1211519&r1=1211518&r2=1211519&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java Wed Dec
 7 16:35:33 2011
@@ -271,7 +271,7 @@ public class EndpointImpl extends javax.
         return endpointName.toString() + ".jaxws-endpoint";
     }
 
-    protected JaxWsServerFactoryBean getServerFactory() {
+    public JaxWsServerFactoryBean getServerFactory() {
         return serverFactory;
     }
     

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=1211519&r1=1211518&r2=1211519&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
Wed Dec  7 16:35:33 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/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java?rev=1211519&r1=1211518&r2=1211519&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/jaxws22/org/apache/cxf/jaxws22/spring/JAXWS22SpringEndpointImpl.java
Wed Dec  7 16:35:33 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));

Added: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java?rev=1211519&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
(added)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
Wed Dec  7 16:35:33 2011
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxws.spring;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceContext;
+
+@WebService()
+public class PostConstructCalledCount {
+    private static int count;
+    private static int injectedCount;
+
+    @Resource
+    WebServiceContext context;
+    
+    public static int getCount() {
+        return count;
+    }
+    public static int getInjectedCount() {
+        return injectedCount;
+    }
+    public static void reset() {
+        count = 0;
+        injectedCount = 0;
+    }
+    
+    
+    @PostConstruct
+    public void postConstruct() {
+        count++;
+        if (context != null) {
+            injectedCount++;
+        }
+    }
+    @WebMethod(exclude = true)
+    public WebServiceContext getContext() {
+        return context;
+    }
+    
+    public int doubleIt(int i) {
+        return i * 2;
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/PostConstructCalledCount.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java?rev=1211519&r1=1211518&r2=1211519&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java
Wed Dec  7 16:35:33 2011
@@ -443,5 +443,36 @@ public class SpringBeansTest extends Ass
             assertTrue(ex.getMessage().contains("cxf1"));
         }
     }
+    
+    @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());
+    }
 }
 

Added: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml?rev=1211519&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml (added)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml Wed
Dec  7 16:35:33 2011
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements. See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership. The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License. You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied. See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
+
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+
+	<jaxws:endpoint implementor="org.apache.cxf.jaxws.spring.PostConstructCalledCount" address="/HelloWorld1"
/>
+    
+    <bean id="theBean" class="org.apache.cxf.jaxws.spring.PostConstructCalledCount"/>
+    <jaxws:endpoint implementor="#theBean" address="/HelloWorld2" />
+	  
+</beans>

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959a.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml?rev=1211519&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml (added)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml Wed
Dec  7 16:35:33 2011
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements. See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership. The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License. You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied. See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
+
+	<jaxws:endpoint implementor="org.apache.cxf.jaxws.spring.PostConstructCalledCount" address="/HelloWorld1"
/>
+    
+    <bean id="theBean" class="org.apache.cxf.jaxws.spring.PostConstructCalledCount"/>
+    <jaxws:endpoint implementor="#theBean" address="/HelloWorld2" />
+	  
+</beans>

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959b.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml?rev=1211519&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml (added)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml Wed
Dec  7 16:35:33 2011
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+	Licensed to the Apache Software Foundation (ASF) under one
+	or more contributor license agreements. See the NOTICE file
+	distributed with this work for additional information
+	regarding copyright ownership. The ASF licenses this file
+	to you under the Apache License, Version 2.0 (the
+	"License"); you may not use this file except in compliance
+	with the License. You may obtain a copy of the License at
+	
+	http://www.apache.org/licenses/LICENSE-2.0
+	
+	Unless required by applicable law or agreed to in writing,
+	software distributed under the License is distributed on an
+	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+	KIND, either express or implied. See the License for the
+	specific language governing permissions and limitations
+	under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xmlns:context="http://www.springframework.org/schema/context"
+	xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+
+    <context:annotation-config/>
+
+	<import resource="classpath:META-INF/cxf/cxf.xml" />
+	
+	<jaxws:endpoint implementor="org.apache.cxf.jaxws.spring.PostConstructCalledCount" address="/HelloWorld1"
/>
+    
+    <bean id="theBean" class="org.apache.cxf.jaxws.spring.PostConstructCalledCount"/>
+    <jaxws:endpoint implementor="#theBean" address="/HelloWorld2" />
+	  
+</beans>

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/cxf3959c.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message