cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1209672 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/configuration/spring/ rt/core/src/main/java/org/apache/cxf/bus/spring/ rt/core/src/main/java/org/apache/cxf/configuration/blueprint/ rt/frontend/jaxws/src/test/java/org/ap...
Date Fri, 02 Dec 2011 19:59:45 GMT
Author: dkulp
Date: Fri Dec  2 19:59:44 2011
New Revision: 1209672

URL: http://svn.apache.org/viewvc?rev=1209672&view=rev
Log:
[CXF-3951] If the bus attibute points to an undefined bus, make sure
spring or blueprint throws an exception.

Added:
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints3.xml 
 (with props)
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
    cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/SpringBeansTest.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java?rev=1209672&r1=1209671&r2=1209672&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
(original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/configuration/spring/AbstractBeanDefinitionParser.java
Fri Dec  2 19:59:44 2011
@@ -57,6 +57,8 @@ public abstract class AbstractBeanDefini
     extends org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser {
     public static final String WIRE_BUS_ATTRIBUTE = AbstractBeanDefinitionParser.class.getName()
+ ".wireBus";
     public static final String WIRE_BUS_NAME = AbstractBeanDefinitionParser.class.getName()
+ ".wireBusName";
+    public static final String WIRE_BUS_CREATE 
+        = AbstractBeanDefinitionParser.class.getName() + ".wireBusCreate";
     public static final String WIRE_BUS_HANDLER 
         = "org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor";
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractBeanDefinitionParser.class);

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java?rev=1209672&r1=1209671&r2=1209672&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java (original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusDefinitionParser.java Fri
Dec  2 19:59:44 2011
@@ -63,6 +63,7 @@ public class BusDefinitionParser extends
             addBusWiringAttribute(bean, BusWiringType.PROPERTY, null, ctx);
         } else {
             addBusWiringAttribute(bean, BusWiringType.PROPERTY, bus, ctx);
+            bean.getRawBeanDefinition().setAttribute(WIRE_BUS_CREATE, Boolean.TRUE);
         }
         String id = element.getAttribute("id");
         if (!StringUtils.isEmpty(id)) {

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java?rev=1209672&r1=1209671&r2=1209672&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/BusWiringBeanFactoryPostProcessor.java
Fri Dec  2 19:59:44 2011
@@ -66,8 +66,9 @@ public class BusWiringBeanFactoryPostPro
         busName = n;
     }
     private static Bus getBusForName(String name,
-                                        ApplicationContext context) {
-        if (!context.containsBean(name)) {
+                                     ApplicationContext context,
+                                     boolean create) {
+        if (!context.containsBean(name) && (create || Bus.DEFAULT_BUS_ID.equals(name)))
{
             SpringBus b = new SpringBus();
             b.setApplicationContext(context);
             ConfigurableApplicationContext cctx = (ConfigurableApplicationContext)context;
@@ -76,8 +77,9 @@ public class BusWiringBeanFactoryPostPro
         return context.getBean(name, Bus.class);
     }
     private Object getBusForName(String name,
-                                        ConfigurableListableBeanFactory factory) {
-        if (!factory.containsBeanDefinition(name)) {
+                                 ConfigurableListableBeanFactory factory,
+                                 boolean create) {
+        if (!factory.containsBeanDefinition(name) && (create || Bus.DEFAULT_BUS_ID.equals(name)))
{
             DefaultListableBeanFactory df = (DefaultListableBeanFactory)factory;
             df.registerBeanDefinition(name, 
                                       new RootBeanDefinition(SpringBus.class));
@@ -88,7 +90,7 @@ public class BusWiringBeanFactoryPostPro
     public void postProcessBeanFactory(ConfigurableListableBeanFactory factory) throws BeansException
{
         Object inject = bus;
         if (inject == null) {
-            inject = getBusForName(Bus.DEFAULT_BUS_ID, factory);
+            inject = getBusForName(Bus.DEFAULT_BUS_ID, factory, true);
         } else {
             if (!factory.containsBeanDefinition(Bus.DEFAULT_BUS_ID)
                 && !factory.containsSingleton(Bus.DEFAULT_BUS_ID)) {
@@ -103,15 +105,18 @@ public class BusWiringBeanFactoryPostPro
                 continue;
             }
             String busname = (String)beanDefinition.getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
+            Boolean create = (Boolean)beanDefinition
+                .getAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
             Object inj = inject;
             if (busname != null) {
                 if (bus != null) {
                     continue;
                 }
-                inj = getBusForName(busname, factory);
+                inj = getBusForName(busname, factory, create == null ? false : create);
             }
             beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_NAME);
             beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_ATTRIBUTE);
+            beanDefinition.removeAttribute(AbstractBeanDefinitionParser.WIRE_BUS_CREATE);
             if (BusWiringType.PROPERTY == type) {
                 beanDefinition.getPropertyValues()
                     .addPropertyValue("bus", inj);
@@ -172,7 +177,7 @@ public class BusWiringBeanFactoryPostPro
 
     public static Bus addDefaultBus(ApplicationContext ctx) {
         if (!ctx.containsBean(Bus.DEFAULT_BUS_ID)) {
-            Bus b = getBusForName(Bus.DEFAULT_BUS_ID, ctx);
+            Bus b = getBusForName(Bus.DEFAULT_BUS_ID, ctx, true);
             if (ctx instanceof ConfigurableApplicationContext) {
                 ConfigurableApplicationContext cctx = (ConfigurableApplicationContext)ctx;
                 new BusWiringBeanFactoryPostProcessor(b).postProcessBeanFactory(cctx.getBeanFactory());
@@ -181,6 +186,6 @@ public class BusWiringBeanFactoryPostPro
         return ctx.getBean(Bus.DEFAULT_BUS_ID, Bus.class);
     }
     public static Bus addBus(ApplicationContext ctx, String name) {
-        return getBusForName(name, ctx);
+        return getBusForName(name, ctx, true);
     }
 }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java?rev=1209672&r1=1209671&r2=1209672&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/configuration/blueprint/AbstractBPBeanDefinitionParser.java
Fri Dec  2 19:59:44 2011
@@ -268,8 +268,9 @@ public abstract class AbstractBPBeanDefi
     }
 
     protected RefMetadata getBusRef(ParserContext context, String name) {
-
-        getBus(context, name);
+        if ("cxf".equals(name)) {
+            getBus(context, name);
+        }
         return createRef(context, name);
     }
 

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=1209672&r1=1209671&r2=1209672&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
Fri Dec  2 19:59:44 2011
@@ -58,6 +58,8 @@ import org.apache.cxf.message.Message;
 import org.apache.hello_world_soap_http.Greeter;
 import org.junit.After;
 import org.junit.Test;
+
+import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
@@ -431,5 +433,15 @@ public class SpringBeansTest extends Ass
             }
         }
     }
+    @Test
+    public void testEndpointWithUndefinedBus() throws Exception {
+        try {
+            new ClassPathXmlApplicationContext("/org/apache/cxf/jaxws/spring/endpoints3.xml");
+            fail("Should have thrown an exception");
+        } catch (BeanCreationException ex) {
+            assertEquals("ep2", ex.getBeanName());
+            assertTrue(ex.getMessage().contains("cxf1"));
+        }
+    }
 }
 

Added: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints3.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints3.xml?rev=1209672&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints3.xml (added)
+++ cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spring/endpoints3.xml Fri
Dec  2 19:59:44 2011
@@ -0,0 +1,40 @@
+<?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:cxf="http://cxf.apache.org/core"
+    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/core http://cxf.apache.org/schemas/core.xsd
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
+
+    <import resource="classpath:META-INF/cxf/cxf.xml" />
+
+
+	<jaxws:endpoint id="ep1" address="/path/one"
+        implementor="org.apache.hello_world_soap_http.GreeterImpl" 
+        bus="cxf"/>
+
+	<jaxws:endpoint id="ep2" address="/path/two"
+        implementor="org.apache.hello_world_soap_http.GreeterImpl" 
+        bus="cxf1"/>
+
+</beans>
\ No newline at end of file

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

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

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



Mime
View raw message