Author: ningjiang
Date: Mon Feb  1 10:43:36 2010
New Revision: 905241

URL: http://svn.apache.org/viewvc?rev=905241&view=rev
Log:
CAMEL-2432 camel-cxf endpoint should support to take the configuration 
information from the application context

Added:
    
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
   (with props)
    
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
   (with props)
    
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
   (with props)
Modified:
    
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java

Modified: 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=905241&r1=905240&r2=905241&view=diff
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
 (original)
+++ 
camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
 Mon Feb  1 10:43:36 2010
@@ -35,11 +35,13 @@
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.spi.HeaderFilterStrategy;
 import org.apache.camel.spi.HeaderFilterStrategyAware;
+import org.apache.camel.spring.SpringCamelContext;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.endpoint.Client;
@@ -55,6 +57,7 @@
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
+import org.springframework.context.ApplicationContext;
 
 /**
  * Defines the <a href="http://camel.apache.org/cxf.html";>CXF Endpoint</a>.
@@ -190,7 +193,17 @@
     }
 
     protected Bus doGetBus() {
-        return BusFactory.newInstance().createBus();
+        BusFactory busFactory = BusFactory.newInstance();
+        // need to check if the camelContext is SpringCamelContext and
+        // update the bus configuration with the applicationContext
+        // which SpringCamelContext holds
+        if (getCamelContext() instanceof SpringCamelContext) {
+            SpringCamelContext springCamelContext = 
(SpringCamelContext)getCamelContext();
+            ApplicationContext applicationContext = 
springCamelContext.getApplicationContext();
+            busFactory = new 
org.apache.cxf.bus.spring.SpringBusFactory(applicationContext);
+        }
+        return busFactory.createBus();
+        
     }
     
     /**
@@ -423,7 +436,7 @@
                 LOG.debug("Using DefaultBus " + bus);
             }
         }
-        
+
         if (!getBusHasBeenCalled.getAndSet(true) && isSetDefaultBus) {
             BusFactory.setDefaultBus(bus);
             if (LOG.isDebugEnabled()) {

Added: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java?rev=905241&view=auto
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
 (added)
+++ 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfTimeoutTest.java
 Mon Feb  1 10:43:36 2010
@@ -0,0 +1,90 @@
+/**
+ * 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 java.net.SocketTimeoutException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.apache.hello_world_soap_http.Greeter;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class CxfTimeoutTest extends CamelSpringTestSupport {
+
+    protected static final String GREET_ME_OPERATION = "greetMe";
+    protected static final String TEST_MESSAGE = "Hello World!";
+    protected static final String JAXWS_SERVER_ADDRESS = 
"http://localhost:9023/SoapContext/SoapPort";;
+
+    @BeforeClass
+    public static void startService() {
+        Greeter implementor = new GreeterImplWithSleep();
+        Endpoint.publish(JAXWS_SERVER_ADDRESS, implementor); 
+    }
+
+    @Test
+    public void testInvokingJaxWsServerWithBusUriParams() throws Exception {
+        sendTimeOutMessage("cxf://" + JAXWS_SERVER_ADDRESS + 
"?serviceClass=org.apache.hello_world_soap_http.Greeter&bus=#cxf");
+    }
+    
+    @Test
+    public void testInvokingJaxWsServerWithoutBusUriParams() throws Exception {
+        sendTimeOutMessage("cxf://" + JAXWS_SERVER_ADDRESS + 
"?serviceClass=org.apache.hello_world_soap_http.Greeter");
+    }
+    
+    @Test
+    public void testInvokingJaxWsServerWithCxfEndpoint() throws Exception {
+        sendTimeOutMessage("cxf://bean:springEndpoint");
+    }
+    
+    protected void sendTimeOutMessage(String endpointUri) throws Exception {
+        try {
+            sendJaxWsMessage(endpointUri);
+            fail("Expecting the exception here");
+        } catch (RuntimeCamelException e) {
+            assertNotNull("We should get the exception cause here", 
e.getCause());
+            assertTrue("We should get the socket time out exception here", 
e.getCause().getCause() instanceof SocketTimeoutException);            
+        }
+    }
+
+    protected Exchange sendJaxWsMessage(String endpointUri) {
+        Exchange exchange = template.send(endpointUri, new Processor() {
+            public void process(final Exchange exchange) {
+                final List<String> params = new ArrayList<String>();
+                params.add(TEST_MESSAGE);
+                exchange.getIn().setBody(params);
+                exchange.getIn().setHeader(CxfConstants.OPERATION_NAME, 
GREET_ME_OPERATION);
+            }
+        });
+        return exchange;
+    }
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        // we can put the http conduit configuration here
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml");
+    }
+
+}
\ No newline at end of file

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

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

Added: 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java?rev=905241&view=auto
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
 (added)
+++ 
camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/GreeterImplWithSleep.java
 Mon Feb  1 10:43:36 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.hello_world_soap_http.GreeterImpl;
+
+public class GreeterImplWithSleep extends GreeterImpl {
+
+    @Override
+    public String greetMe(String hi) {
+
+        try {            
+            Thread.sleep(10000);
+        } catch (Exception ignore) {
+
+        }
+        return "";
+    }
+}

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

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

Added: 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml?rev=905241&view=auto
==============================================================================
--- 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
 (added)
+++ 
camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
 Mon Feb  1 10:43:36 2010
@@ -0,0 +1,48 @@
+<?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/cxf";
+       xmlns:http-conf="http://cxf.apache.org/transports/http/configuration";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/cxf 
http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://cxf.apache.org/transports/http/configuration 
http://cxf.apache.org/schemas/configuration/http-conf.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+   <import resource="classpath:META-INF/cxf/cxf.xml"/>
+   <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
+   <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+   
+   <http-conf:conduit name="*.http-conduit">
+               <http-conf:client ReceiveTimeout="100" />
+   </http-conf:conduit>
+
+   <cxf:cxfEndpoint id="springEndpoint" 
address="http://localhost:9023/SoapContext/SoapPort";
+               serviceClass="org.apache.hello_world_soap_http.Greeter"/>
+
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"; 
errorHandlerRef="noErrorHandler">
+     <route errorHandlerRef="noErrorHandler">
+        <from uri="direct:start"/>
+        <to uri="cxf:bean:springEndpoint"/>
+     </route>
+   </camelContext>
+
+   <bean id="noErrorHandler" 
class="org.apache.camel.builder.NoErrorHandlerBuilder"/>
+
+</beans>
\ No newline at end of file

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

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

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


Reply via email to