Author: ningjiang
Date: Sun Jun 22 23:54:16 2008
New Revision: 670454

URL: http://svn.apache.org/viewvc?rev=670454&view=rev
Log:
CAMEL-622 supports to set the setDefaultBus and DataFormat options from Spring 
configuration file

Added:
    
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
   (with props)
    
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/
    
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
   (with props)
Modified:
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
    
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
    
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java?rev=670454&r1=670453&r2=670454&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
 Sun Jun 22 23:54:16 2008
@@ -25,6 +25,7 @@
     String METHOD = "method";
     String SERVICE_CLASS = "serviceClass";
     String DATA_FORMAT = "dataFormat";
+    String SET_DEFAULT_BUS = "setDefaultBus";
     String WSDL_URL = "wsdlURL";
     String ADDRESS = "address";
     String SERVICE_NAME = "serviceName";

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java?rev=670454&r1=670453&r2=670454&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
 Sun Jun 22 23:54:16 2008
@@ -53,7 +53,7 @@
         if (endpoint.getApplicationContext() != null) {
             SpringBusFactory bf = new 
SpringBusFactory(endpoint.getApplicationContext());
             bus = bf.createBus();
-            if (endpoint.isSetDefaultBus()) {
+            if (CxfEndpointUtils.getSetDefaultBus(endpoint)) {
                 BusFactory.setDefaultBus(bus);
             }
         } else {

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=670454&r1=670453&r2=670454&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
 Sun Jun 22 23:54:16 2008
@@ -45,7 +45,7 @@
     private boolean isWrapped;
     private boolean isSpringContextEndpoint;
     private boolean inOut = true;
-    private boolean isSetDefaultBus;
+    private Boolean isSetDefaultBus;
     private ConfigurerImpl configurer;
     private CxfEndpointBean cxfEndpointBean;
 
@@ -113,11 +113,11 @@
         wsdlURL = url;
     }
 
-    public void setSetDefaultBus(boolean set) {
+    public void setSetDefaultBus(Boolean set) {
         isSetDefaultBus = set;
     }
 
-    public boolean isSetDefaultBus() {
+    public Boolean isSetDefaultBus() {
         return isSetDefaultBus;
     }
 

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java?rev=670454&r1=670453&r2=670454&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfProducer.java
 Sun Jun 22 23:54:16 2008
@@ -111,7 +111,7 @@
         if (endpoint.getApplicationContext() != null) {
             SpringBusFactory bf = new 
SpringBusFactory(endpoint.getApplicationContext());
             bus = bf.createBus();
-            if (endpoint.isSetDefaultBus()) {
+            if (CxfEndpointUtils.getSetDefaultBus(endpoint)) {
                 BusFactory.setDefaultBus(bus);
             }
         } else {

Modified: 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java?rev=670454&r1=670453&r2=670454&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/util/CxfEndpointUtils.java
 Sun Jun 22 23:54:16 2008
@@ -26,8 +26,10 @@
 import javax.xml.ws.WebServiceProvider;
 
 import org.apache.camel.CamelException;
+import org.apache.camel.component.cxf.CxfConstants;
 import org.apache.camel.component.cxf.CxfEndpoint;
 import org.apache.camel.component.cxf.DataFormat;
+import org.apache.camel.component.cxf.spring.CxfEndpointBean;
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.Message;
@@ -216,9 +218,35 @@
         }
     }
 
+    public static boolean getSetDefaultBus(CxfEndpoint endpoint) {
+        Boolean isSetDefaultBus = null;
+        // check the value of cxfEndpointBean's property
+        CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
+        if (cxfEndpointBean != null && cxfEndpointBean.getProperties() != 
null) {
+            String value =  
(String)cxfEndpointBean.getProperties().get(CxfConstants.SET_DEFAULT_BUS);
+            isSetDefaultBus = Boolean.valueOf(value);
+        }
+        // We will get the value from the cxfEndpontBean's properties
+        if (isSetDefaultBus != null && endpoint.isSetDefaultBus() == null) {
+            return isSetDefaultBus.booleanValue();
+        } else if (endpoint.isSetDefaultBus() != null) {
+            return endpoint.isSetDefaultBus().booleanValue();
+        } else { // return the default value false
+            return false;
+        }
+    }
+
     public static DataFormat getDataFormat(CxfEndpoint endpoint) throws 
CamelException {
         String dataFormatString = endpoint.getDataFormat();
         if (dataFormatString == null) {
+            CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
+            if (cxfEndpointBean != null && cxfEndpointBean.getProperties() != 
null) {
+                dataFormatString = (String) 
cxfEndpointBean.getProperties().get(CxfConstants.DATA_FORMAT);
+            }
+        }
+
+        // return the default value if nothing is set
+        if (dataFormatString == null) {
             return DataFormat.POJO;
         }
 

Modified: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java?rev=670454&r1=670453&r2=670454&view=diff
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
 (original)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsTest.java
 Sun Jun 22 23:54:16 2008
@@ -22,29 +22,46 @@
 import org.apache.camel.CamelContext;
 import org.apache.camel.component.cxf.CxfComponent;
 import org.apache.camel.component.cxf.CxfEndpoint;
+import org.apache.camel.component.cxf.DataFormat;
 import org.apache.camel.impl.DefaultCamelContext;
 
 public class CxfEndpointUtilsTest extends TestCase {
-    static final String CXF_BASE_URI = 
"cxf://http://www.example.com/testaddress";
+    // set up the port name and service name
+    protected static final QName SERVICE_NAME =
+        new QName("http://www.example.com/test";, "ServiceName");
+
+
+    private static final String CXF_BASE_URI = 
"cxf://http://www.example.com/testaddress";
         + "?serviceClass=org.apache.camel.component.cxf.HelloService"
         + "&portName={http://www.example.com/test}PortName";
-        + "&serviceName={http://www.example.com/test}ServiceName";;
+        + "&serviceName={http://www.example.com/test}ServiceName";
+        + "&setDefaultBus=true";
 
-    // set up the port name and service name
-    private static final QName SERVICE_NAME =
-        new QName("http://www.example.com/test";, "ServiceName");
 
-    CxfEndpoint cxfEndpoint;
 
-    protected void createEndpoint(String uri) throws Exception {
-        CamelContext context = new DefaultCamelContext();
-        cxfEndpoint = (CxfEndpoint)new 
CxfComponent(context).createEndpoint(uri);
+    protected String getEndpointURI() {
+        return CXF_BASE_URI;
     }
 
-    public void testGetQName() throws Exception {
-        createEndpoint(CXF_BASE_URI);
-        QName service = 
CxfEndpointUtils.getQName(cxfEndpoint.getServiceName());
+    protected CamelContext getCamelContext() throws Exception {
+        return new DefaultCamelContext();
+    }
+
+    protected CxfEndpoint createEndpoint(String uri) throws Exception {
+        CamelContext context = getCamelContext();
+        return (CxfEndpoint)new CxfComponent(context).createEndpoint(uri);
+    }
+
+    public void testGetProperties() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getEndpointURI());
+        QName service = CxfEndpointUtils.getQName(endpoint.getServiceName());
         assertEquals("We should get the right service name", service, 
SERVICE_NAME);
+        assertEquals("We should get the setDefaultBus value", 
CxfEndpointUtils.getSetDefaultBus(endpoint) , true);
+    }
+
+    public void testGetDataFormat() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getEndpointURI() + 
"&dataFormat=MESSAGE");
+        assertEquals("We should get the Message DataFormat", 
CxfEndpointUtils.getDataFormat(endpoint), DataFormat.MESSAGE);
     }
 
 

Added: 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java?rev=670454&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
 (added)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/util/CxfEndpointUtilsWithSpringTest.java
 Sun Jun 22 23:54:16 2008
@@ -0,0 +1,87 @@
+/**
+ * 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.util;
+
+import javax.xml.namespace.QName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.cxf.CxfEndpoint;
+import org.apache.camel.component.cxf.DataFormat;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfEndpointUtilsWithSpringTest extends CxfEndpointUtilsTest {
+    protected AbstractXmlApplicationContext applicationContext;
+
+    @Override
+    protected void setUp() throws Exception {
+        applicationContext = createApplicationContext();
+        super.setUp();
+        assertNotNull("Should have created a valid spring context", 
applicationContext);
+
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        if (applicationContext != null) {
+            applicationContext.destroy();
+        }
+        super.tearDown();
+    }
+
+    @Override
+    protected CamelContext getCamelContext() throws Exception {
+        return SpringCamelContext.springCamelContext(applicationContext);
+    }
+
+    protected ClassPathXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/util/CxfEndpointBeans.xml");
+    }
+
+    protected String getEndpointURI() {
+        return "cxf:bean:testEndpoint";
+    }
+
+    public void testGetDataFormat() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getEndpointURI() + 
"?dataFormat=MESSAGE");
+        assertEquals("We should get the Message DataFormat", 
CxfEndpointUtils.getDataFormat(endpoint),
+                     DataFormat.MESSAGE);
+    }
+
+    public void testGetURIOverCxfEndpointProperties() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getEndpointURI() + 
"?setDefaultBus=false");
+        assertEquals("We should get the setDefaultBus value", 
CxfEndpointUtils.getSetDefaultBus(endpoint),
+                     false);
+
+    }
+
+    public void testGetProperties() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getEndpointURI());
+        QName service = endpoint.getCxfEndpointBean().getServiceName();
+        assertEquals("We should get the right service name", service, 
SERVICE_NAME);
+        assertEquals("We should get the setDefaultBus value", 
CxfEndpointUtils.getSetDefaultBus(endpoint),
+                     true);
+    }
+
+    public void testGetDataFormatFromCxfEndpontProperties() throws Exception {
+        CxfEndpoint endpoint = createEndpoint(getEndpointURI() + 
"?dataFormat=PAYLOAD");
+        assertEquals("We should get the Message DataFormat", 
CxfEndpointUtils.getDataFormat(endpoint),
+                     DataFormat.PAYLOAD);
+    }
+
+}

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

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

Added: 
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
URL: 
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml?rev=670454&view=auto
==============================================================================
--- 
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
 (added)
+++ 
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/util/CxfEndpointBeans.xml
 Sun Jun 22 23:54:16 2008
@@ -0,0 +1,43 @@
+<?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://activemq.apache.org/camel/schema/cxfEndpoint";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://activemq.apache.org/camel/schema/cxfEndpoint 
http://activemq.apache.org/camel/schema/cxfEndpoint/camel-cxf.xsd
+    ">
+
+
+  <cxf:cxfEndpoint id="testEndpoint" address="http://localhost:9000/router";
+    serviceClass="org.apache.camel.component.cxf.HelloService"
+    endpointName="s:PortName"
+    serviceName="s:ServiceName"
+    xmlns:s="http://www.example.com/test";>
+    <cxf:properties>
+      <entry key="dataFormat" value="MESSAGE"/>
+      <entry key="setDefaultBus" value="true"/>
+    </cxf:properties>
+
+  </cxf:cxfEndpoint>
+
+
+
+
+
+</beans>

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

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

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


Reply via email to