camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r749772 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ main/java/org/apache/camel/component/cxf/spring/ test/java/org/apache/camel/component/cxf/ test/resources/org/apache/camel/component/cxf/
Date Tue, 03 Mar 2009 21:49:10 GMT
Author: wtam
Date: Tue Mar  3 21:49:10 2009
New Revision: 749772

URL: http://svn.apache.org/viewvc?rev=749772&view=rev
Log:
[CAMEL-1416] Using # notation to reference CXF serviceClass is not working

Added:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java
  (with props)
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
  (with props)
Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java?rev=749772&r1=749771&r2=749772&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfComponent.java
Tue Mar  3 21:49:10 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.component.cxf;
 
+import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.camel.CamelContext;
@@ -60,6 +61,16 @@
                     CxfEndpointBean.class);
 
             result = new CxfSpringEndpoint(this, bean);
+           
+            // Apply Spring bean properties (including # notation referenced bean).  Note
that the
+            // Spring bean properties values can be overridden by property defined in URI
query.
+            // The super class (DefaultComponent) will invoke "setProperties" after this
method 
+            // with to apply properties defined by URI query. 
+            if (bean.getProperties() != null) {
+                Map<String, Object> copy = new HashMap<String, Object>();
+                copy.putAll(bean.getProperties());     
+                setProperties(result, copy);      
+            }
             
         } else {
             // endpoint URI does not specify a bean

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java?rev=749772&r1=749771&r2=749772&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSpringEndpoint.java
Tue Mar  3 21:49:10 2009
@@ -17,16 +17,12 @@
 package org.apache.camel.component.cxf;
 
 import java.lang.reflect.Proxy;
-import java.util.HashMap;
-import java.util.Map;
-
 import javax.xml.namespace.QName;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.cxf.spring.CxfEndpointBean;
 import org.apache.camel.component.cxf.util.CxfEndpointUtils;
 import org.apache.camel.spring.SpringCamelContext;
-import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
@@ -66,30 +62,11 @@
     private void init(CxfEndpointBean bean) throws Exception {
         this.bean = bean;
         
-        // set properties from bean which can be overridden by endpoint URI
-        setPropertiesBean();
-        
         // create configurer
         configurer = new ConfigurerImpl(((SpringCamelContext)getCamelContext())
             .getApplicationContext());
     }
 
-    /**
-     * Read properties from the CxfEndpointBean and copy them to the 
-     * properties of this class.  Note that the properties values can 
-     * be overridden by values in URI query as the DefaultComponent 
-     * will perform "setProperties" later (after the constructor). 
-     */
-    private void setPropertiesBean() throws Exception {
-        if (bean.getProperties() != null) {
-            Map<String, Object> copy = new HashMap<String, Object>();
-            copy.putAll(bean.getProperties());
-            
-            // pass the copy the method modifies the properties map
-            IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), 
-                    this, copy);      
-        }
-    }
     
     /**
      * 

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java?rev=749772&r1=749771&r2=749772&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java
(original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanDefinitionParser.java
Tue Mar  3 21:49:10 2009
@@ -73,25 +73,36 @@
         }
     }
 
+    /**
+     * Override mapToProperty() to handle the '#' reference notation ourselves.  We put those

+     * properties with '#' in property map and let component to invoke setProperties() on
the
+     * endpoint. 
+     */
+    @Override
+    protected void mapToProperty(BeanDefinitionBuilder bean, String propertyName, String
val) {
+        if (ID_ATTRIBUTE.equals(propertyName)) {
+            return;
+        }
+
+        if (org.springframework.util.StringUtils.hasText(val)) {
+            if (val.startsWith("#")) {
+                Map<String, Object> map = getPropertyMap(bean);
+                map.put(propertyName, val);
+            } else {
+                bean.addPropertyValue(propertyName, val);
+            }
+        }
+        
+    }
 
     @Override
     protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean)
{
         super.doParse(element, ctx, bean);
         bean.setLazyInit(false);
         
-        // put the id into the properties
-        PropertyValue propertyValue = (PropertyValue)bean.getBeanDefinition().getPropertyValues()
-            .getPropertyValue("properties");
-        
-        Map<String, Object> map = null;
-        if (propertyValue == null) {
-            map = new HashMap<String, Object>();
-            bean.addPropertyValue("properties", map);
-        } else {
-            map = (Map<String, Object>)propertyValue.getValue();
-        }
-        String id = resolveId(element, bean.getBeanDefinition(), ctx);
-        map.put("beanId", id);        
+        // put the bean id into the property map
+        Map<String, Object> map = getPropertyMap(bean);
+        map.put("beanId", resolveId(element, bean.getBeanDefinition(), ctx));        
     }
 
     @Override
@@ -111,6 +122,21 @@
     protected boolean hasBusProperty() {
         return true;
     }
+
+    @SuppressWarnings("unchecked")
+    private Map<String, Object> getPropertyMap(BeanDefinitionBuilder bean) {
+        PropertyValue propertyValue = (PropertyValue)bean.getBeanDefinition().getPropertyValues()
+            .getPropertyValue("properties");
+        
+        Map<String, Object> map = null;
+        if (propertyValue == null) {
+            map = new HashMap<String, Object>();
+            bean.addPropertyValue("properties", map);
+        } else {
+            map = (Map<String, Object>)propertyValue.getValue();
+        }
+        return map;
+    }
     
     // To make the CxfEndpointBean clear without touching any Spring relates class 
     // , we implements the ApplicationContextAware here

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java?rev=749772&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java
(added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java
Tue Mar  3 21:49:10 2009
@@ -0,0 +1,40 @@
+/**
+ * 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.camel.component.cxf;
+
+import org.apache.camel.CamelContext;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+/**
+ * Unit test to verify using '#' notation to reference serviceClass.
+ * 
+ * @version $Revision$
+ */
+@ContextConfiguration
+public class ServiceClassRefTest extends AbstractJUnit38SpringContextTests {
+
+    @Autowired
+    protected CamelContext context;
+    
+    public void testServiceClassNameCreatedByRefNotation() throws Exception {
+        CxfEndpoint endpoint = context.getEndpoint("cxf:bean:fromEndpoint", CxfEndpoint.class);
+        assertEquals("org.apache.camel.component.cxf.HelloServiceImpl", endpoint.getServiceClass());
+    }
+
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/ServiceClassRefTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml?rev=749772&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
(added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
Tue Mar  3 21:49:10 2009
@@ -0,0 +1,42 @@
+<?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://camel.apache.org/schema/cxfEndpoint"
+	
+	xsi:schemaLocation="
+       http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring  http://camel.apache.org/schema/spring/camel-spring.xsd
+       http://camel.apache.org/schema/cxfEndpoint http://camel.apache.org/schema/cxf/camel-cxf.xsd
+    ">
+    
+    <bean id="myServiceClass" class="org.apache.camel.component.cxf.HelloServiceImpl"/>
+    
+	<cxf:cxfEndpoint id="fromEndpoint" address="http://localhost:9000/helloworld"
+		serviceClass="#myServiceClass" />
+		
+	<cxf:cxfEndpoint id="toEndpoint" address="http://localhost:9002/helloworld"
+		serviceClass="org.apache.camel.component.cxf.HelloService" />
+
+	<camelContext id="camelContext"
+		xmlns="http://camel.apache.org/schema/spring">
+		<route>
+			<from uri="cxf:bean:fromEndpoint"/>
+			<to uri="cxf:bean:toEndpoint"/>
+		</route>
+	</camelContext>
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/ServiceClassRefTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message