Author: ningjiang
Date: Tue Jun 17 02:59:53 2008
New Revision: 668598
URL: http://svn.apache.org/viewvc?rev=668598&view=rev
Log:
CAMEL-614 support configure cxf through the camel context spring configuration
file
Added:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java
(with props)
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
(with props)
Modified:
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/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
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=668598&r1=668597&r2=668598&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
Tue Jun 17 02:59:53 2008
@@ -29,6 +29,7 @@
import org.apache.camel.impl.DefaultConsumer;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.feature.AbstractFeature;
@@ -46,11 +47,16 @@
public CxfConsumer(CxfEndpoint endpoint, Processor processor) throws
Exception {
super(endpoint, processor);
+ Bus bus = null;
this.endpoint = endpoint;
boolean isWebServiceProvider = false;
-
- // now we just use the default bus here
- Bus bus = BusFactory.getDefaultBus();
+ if (endpoint.getApplicationContext() != null) {
+ SpringBusFactory bf = new
SpringBusFactory(endpoint.getApplicationContext());
+ bus = bf.createBus();
+ } else {
+ // now we just use the default bus here
+ bus = BusFactory.getDefaultBus();
+ }
ServerFactoryBean svrBean = null;
if (endpoint.isSpringContextEndpoint()) {
@@ -59,13 +65,6 @@
isWebServiceProvider =
CxfEndpointUtils.hasAnnotation(endpointBean.getServiceClass(),
WebServiceProvider.class);
endpoint.configure(svrBean);
- CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
- if (cxfEndpointBean.getServiceName() != null) {
- svrBean.setServiceName(cxfEndpointBean.getServiceName());
- }
- if (cxfEndpointBean.getEndpointName() != null) {
- svrBean.setEndpointName(cxfEndpointBean.getEndpointName());
- }
} else { // setup the serverFactoryBean with the URI parameters
Class serviceClass =
ClassLoaderUtils.loadClass(endpoint.getServiceClass(), this.getClass());
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=668598&r1=668597&r2=668598&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
Tue Jun 17 02:59:53 2008
@@ -25,6 +25,7 @@
import org.apache.camel.spring.SpringCamelContext;
import org.apache.cxf.configuration.spring.ConfigurerImpl;
import org.apache.cxf.message.Message;
+import org.springframework.context.ApplicationContext;
/**
@@ -172,5 +173,14 @@
configurer.configureBean(beanId, beanInstance);
}
+ public ApplicationContext getApplicationContext() {
+ if (getCamelContext() instanceof SpringCamelContext) {
+ SpringCamelContext context = (SpringCamelContext)
getCamelContext();
+ return context.getApplicationContext();
+ } else {
+ return null;
+ }
+ }
+
}
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=668598&r1=668597&r2=668598&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
Tue Jun 17 02:59:53 2008
@@ -38,6 +38,7 @@
import org.apache.camel.util.ObjectHelper;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.Endpoint;
@@ -106,7 +107,14 @@
// If cfb is null, we will try to find the right cfb to use.
private Client createClientFromClientFactoryBean(ClientFactoryBean cfb)
throws CamelException {
- Bus bus = BusFactory.getDefaultBus();
+ Bus bus = null;
+ if (endpoint.getApplicationContext() != null) {
+ SpringBusFactory bf = new
SpringBusFactory(endpoint.getApplicationContext());
+ bus = bf.createBus();
+ } else {
+ // now we just use the default bus here
+ bus = BusFactory.getDefaultBus();
+ }
if (endpoint.isSpringContextEndpoint()) {
CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
if (cfb == null) {
@@ -114,12 +122,6 @@
}
endpoint.configure(cfb);
- if (cxfEndpointBean.getServiceName() != null) {
- cfb.setServiceName(cxfEndpointBean.getServiceName());
- }
- if (cxfEndpointBean.getEndpointName() != null) {
- cfb.setEndpointName(cxfEndpointBean.getEndpointName());
- }
} else { // set up the clientFactoryBean by using URI information
if (null != endpoint.getServiceClass()) {
try {
Modified:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java?rev=668598&r1=668597&r2=668598&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
(original)
+++
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/CxfEndpointBeanTest.java
Tue Jun 17 02:59:53 2008
@@ -16,21 +16,57 @@
*/
package org.apache.camel.component.cxf.spring;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.cxf.CxfConstants;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.message.Message;
+import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
*
*/
public class CxfEndpointBeanTest extends TestCase {
+ private ClassPathXmlApplicationContext ctx;
+ protected void setUp() throws Exception {
+ ctx = new ClassPathXmlApplicationContext(new
String[]{"org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml"});
+ }
+
+ protected void tearDown() throws Exception {
+ ctx.close();
+ }
public void testCxfEndpointBeanDefinitionParser() {
- ClassPathXmlApplicationContext ctx =
- new ClassPathXmlApplicationContext(new
String[]{"org/apache/camel/component/cxf/spring/CxfEndpointBeans.xml"});
CxfEndpointBean routerEndpoint =
(CxfEndpointBean)ctx.getBean("routerEndpoint");
assertEquals("Got the wrong endpoint address",
routerEndpoint.getAddress(), "http://localhost:9000/router");
assertEquals("Got the wrong endpont service class",
routerEndpoint.getServiceClass().getCanonicalName(),
"org.apache.camel.component.cxf.HelloService");
+
+ }
+
+ public void testCxfBusConfiguration() throws InterruptedException {
+ // get the camelContext from application context
+ CamelContext camelContext = (CamelContext) ctx.getBean("camel");
+ ProducerTemplate template = camelContext.createProducerTemplate();
+ Exchange exchange = template.send("cxf:bean:routerEndpoint", new
Processor() {
+ public void process(final Exchange exchange) {
+ final List<String> params = new ArrayList<String>();
+ params.add("hello");
+ exchange.getIn().setBody(params);
+ exchange.getIn().setHeader(CxfConstants.OPERATION_NAME,
"echo");
+ }
+ });
+ assertTrue("There should have a timeout exception",
exchange.isFailed());
+
}
}
Added:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java?rev=668598&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java
(added)
+++
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java
Tue Jun 17 02:59:53 2008
@@ -0,0 +1,43 @@
+/**
+ * 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.spring;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cxf.CxfConstants;
+
+/**
+ *
+ */
+public class MyProcessor implements Processor {
+
+ public void process(Exchange exchange) throws Exception {
+ // TODO Auto-generated method stub
+ Thread.sleep(4000);
+ Message in = exchange.getIn();
+ // Get the parameter list
+ List parameter = in.getBody(List.class);
+ // Get the operation name
+ String operation = (String)in.getHeader(CxfConstants.OPERATION_NAME);
+ Object result = operation + " " + (String)parameter.get(0);
+ exchange.getOut().setBody(result);
+ }
+
+}
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/spring/MyProcessor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml?rev=668598&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
(added)
+++
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
Tue Jun 17 02:59:53 2008
@@ -0,0 +1,53 @@
+<?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"
+ 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://activemq.apache.org/camel/schema/cxfEndpoint
http://activemq.apache.org/camel/schema/cxfEndpoint/camel-cxf.xsd
+ http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd
+ http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+ ">
+
+
+ <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9000/router"
+ serviceClass="org.apache.camel.component.cxf.HelloService"/>
+
+
+ <cxf:cxfEndpoint id="serviceEndpoint"
address="http://localhost:9002/helloworld"
+ serviceClass="org.apache.camel.component.cxf.HelloService"/>
+
+ <!-- Setting the http conduit policy -->
+ <http-conf:conduit
name="{http://cxf.component.camel.apache.org/}HelloServicePort.http-conduit">
+ <http-conf:client ReceiveTimeout="2000"
+ MaxRetransmits="1"
+ AllowChunking="false" />
+ </http-conf:conduit>
+
+ <bean id="myProcessor"
class="org.apache.camel.component.cxf.spring.MyProcessor"/>
+
+ <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
+ <route>
+ <from uri="cxf:bean:routerEndpoint" />
+ <process ref="myProcessor" />
+ </route>
+ </camelContext>
+
+</beans>
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/spring/CxfEndpointBeansRouter.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml