Author: ningjiang
Date: Fri Jan 11 07:06:13 2008
New Revision: 611197
URL: http://svn.apache.org/viewvc?rev=611197&view=rev
Log:
Added the supporting of calling the service with the different operation target namespace
Added:
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
(with props)
Modified:
activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
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/CxfProducer.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java
activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java?rev=611197&r1=611196&r2=611197&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfBinding.java
Fri Jan 11 07:06:13 2008
@@ -28,6 +28,7 @@
import java.util.List;
import java.util.Set;
+import javax.xml.namespace.QName;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
@@ -46,13 +47,13 @@
protected static Object getBody(Message message) {
Set<Class<?>> contentFormats = message.getContentFormats();
if (contentFormats != null) {
- for (Class<?> contentFormat : contentFormats) {
+ for (Class<?> contentFormat : contentFormats) {
Object answer = message.getContent(contentFormat);
if (answer != null) {
return answer;
}
}
- }
+ }
return null;
}
@@ -71,12 +72,14 @@
}
if (body instanceof InputStream) {
answer.setContent(InputStream.class, body);
- // we need copy context
+ // we need copy context
} else if (body instanceof List) {
//just set the operation's parament
answer.setContent(List.class, body);
//just set the method name
- answer.setContent(String.class, in.getHeader(CxfConstants.OPERATION_NAME));
+ answer.put(CxfConstants.OPERATION_NAME, (String)in.getHeader(CxfConstants.OPERATION_NAME));
+ answer.put(CxfConstants.OPERATION_NAMESPACE, (String)in.getHeader(CxfConstants.OPERATION_NAMESPACE));
+
} else if (body instanceof DOMSource) {
DOMSource source = (DOMSource) body;
try {
@@ -84,15 +87,15 @@
answer.setContent(InputStream.class, bais);
} catch (Exception e) {
throw new RuntimeCamelException(e);
- }
-
+ }
+
}
-
-
+
+
return answer;
}
-
-
+
+
public void storeCxfResponse(CxfExchange exchange, Message response) {
// no need to process headers as we use the CXF message
CxfMessage out = exchange.getOut();
@@ -108,7 +111,7 @@
out.setBody(response);
}
}
-
+
public void storeCxfFault(CxfExchange exchange, Message message) {
CxfMessage fault = exchange.getFault();
if (fault != null) {
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=611197&r1=611196&r2=611197&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
Fri Jan 11 07:06:13 2008
@@ -31,11 +31,12 @@
String PORT_NAME = "portName";
String PROTOCOL_NAME_RES = "res";
String OPERATION_NAME = "operationName";
+ String OPERATION_NAMESPACE = "operationNameSpace";
String SPRING_CONTEXT_ENDPOINT = "bean:";
String CAMEL_TRANSPORT_PREFIX = "camel:";
String CXF_EXCHANGE = "org.apache.cxf.message.exchange";
String CAMEL_EXCHANGE = "org.apache.camel.exchange";
-
+
}
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=611197&r1=611196&r2=611197&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
Fri Jan 11 07:06:13 2008
@@ -48,17 +48,19 @@
import java.io.InputStream;
import java.net.MalformedURLException;
+import javax.xml.namespace.QName;
+
/**
* Sends messages from Camel into the CXF endpoint
- *
+ *
* @version $Revision$
*/
public class CxfProducer extends DefaultProducer <CxfExchange> {
private CxfEndpoint endpoint;
private Client client;
private DataFormat dataFormat;
-
-
+
+
public CxfProducer(CxfEndpoint endpoint) throws CamelException {
super(endpoint);
@@ -68,10 +70,10 @@
client = createClientFormClientFactoryBean(null);
} else {
// create CxfClient for message
- client = createClientForStreamMessge();
+ client = createClientForStreamMessge();
}
}
-
+
private Client createClientForStreamMessge() throws CamelException {
CxfClientFactoryBean cfb = new CxfClientFactoryBean();
if (null != endpoint.getServiceClass()) {
@@ -85,24 +87,24 @@
}
return createClientFormClientFactoryBean(cfb);
}
-
- //If cfb is null ,we will try to find a right cfb to use.
- private Client createClientFormClientFactoryBean(ClientFactoryBean cfb) throws CamelException
{
+
+ //If cfb is null ,we will try to find a right cfb to use.
+ private Client createClientFormClientFactoryBean(ClientFactoryBean cfb) throws CamelException
{
Bus bus = BusFactory.getDefaultBus();
if (endpoint.isSpringContextEndpoint()) {
CxfEndpointBean endpointBean = endpoint.getCxfEndpointBean();
if (cfb == null) {
cfb = CxfEndpointUtils.getClientFactoryBean(endpointBean.getServiceClass());
- }
+ }
endpoint.configure(cfb);
CxfEndpointBean cxfEndpointBean = endpoint.getCxfEndpointBean();
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 {
@@ -110,21 +112,21 @@
Class serviceClass = ClassLoaderUtils.loadClass(endpoint.getServiceClass(),
this.getClass());
if (cfb == null) {
cfb = CxfEndpointUtils.getClientFactoryBean(serviceClass);
- }
+ }
cfb.setAddress(endpoint.getAddress());
- if (null != endpoint.getServiceClass()) {
+ if (null != endpoint.getServiceClass()) {
cfb.setServiceClass(ObjectHelper.loadClass(endpoint.getServiceClass()));
- }
+ }
if (null != endpoint.getWsdlURL()) {
cfb.setWsdlURL(endpoint.getWsdlURL());
- }
+ }
} catch (ClassNotFoundException e) {
throw new CamelException(e);
}
} else { // we can't see any service class from the endpoint
if (cfb == null) {
cfb = new ClientFactoryBean();
- }
+ }
if (null != endpoint.getWsdlURL()) {
cfb.setWsdlURL(endpoint.getWsdlURL());
} else {
@@ -137,22 +139,21 @@
}
if (endpoint.getPortName() != null) {
cfb.setEndpointName(CxfEndpointUtils.getPortName(endpoint));
-
- }
- if (endpoint.getWsdlURL() != null) {
+
+ }
+ if (endpoint.getWsdlURL() != null) {
cfb.setWsdlURL(endpoint.getWsdlURL());
}
- }
- cfb.setBus(bus);
+ }
+ cfb.setBus(bus);
return cfb.create();
}
-
+
public void process(Exchange exchange) {
CxfExchange cxfExchange = endpoint.createExchange(exchange);
process(cxfExchange);
- if (exchange.getPattern() != ExchangePattern.InOnly) {
- exchange.copyFrom(cxfExchange);
- }
+ exchange.copyFrom(cxfExchange);
+
}
public void process(CxfExchange exchange) {
@@ -161,21 +162,29 @@
try {
if (dataFormat.equals(DataFormat.POJO)) {
//InputStream is = m.getContent(InputStream.class);
- // now we just deal with the POJO invocations
+ // now we just deal with the POJO invocations
List paraments = inMessage.getContent(List.class);
- String operation = inMessage.getContent(String.class);
- Message response = new MessageImpl();
- if (operation != null && paraments != null) {
+ String operationName = (String)inMessage.get(CxfConstants.OPERATION_NAME);
+ String operationNameSpace = (String)inMessage.get(CxfConstants.OPERATION_NAMESPACE);
+ Message response = new MessageImpl();
+ if (operationName != null && paraments != null) {
// now we just deal with the invoking the paraments
+ // we need to check out the operation Namespace
try {
- Object[] result = client.invoke(operation, paraments.toArray());
+ Object[] result = null;
+ if (operationNameSpace == null) {
+ result = client.invoke(operationName, paraments.toArray());
+ } else {
+ QName operation = new QName(operationNameSpace, operationName);
+ result = client.invoke(operation, paraments.toArray());
+ }
response.setContent(Object[].class, result);
cxfBinding.storeCxfResponse(exchange, response);
} catch (Exception ex) {
response.setContent(Exception.class, ex);
- cxfBinding.storeCxfFault(exchange, response);
+ cxfBinding.storeCxfFault(exchange, response);
}
- }
+ }
} else {
// get the invocation context
org.apache.cxf.message.Exchange ex = exchange.getExchange();
@@ -202,35 +211,35 @@
Object result = cxfClient.dispatch(params, null, ex);
// need to get the binding object to create the message
BindingOperationInfo boi = ex.get(BindingOperationInfo.class);
- Message response = null;
+ Message response = null;
if (boi == null) {
- // it should be the raw message
- response = new MessageImpl();
+ // it should be the raw message
+ response = new MessageImpl();
} else {
// create the message here
- Endpoint ep = ex.get(Endpoint.class);
+ Endpoint ep = ex.get(Endpoint.class);
response = ep.getBinding().createMessage();
- }
+ }
response.setExchange(ex);
- ex.setOutMessage(response);
+ ex.setOutMessage(response);
invokingContext.setResponseContent(response, result);
cxfBinding.storeCxfResponse(exchange, response);
}
} catch (Exception e) {
//TODO add the falut message handling work
throw new RuntimeCamelException(e);
- }
-
+ }
+
}
@Override
protected void doStart() throws Exception {
- super.doStart();
+ super.doStart();
}
@Override
protected void doStop() throws Exception {
- super.doStop();
+ super.doStop();
}
}
Added: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java?rev=611197&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
(added)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
Fri Jan 11 07:06:13 2008
@@ -0,0 +1,80 @@
+package org.apache.camel.component.cxf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultExchange;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.bus.CXFBusFactory;
+import org.apache.cxf.endpoint.ServerImpl;
+import org.apache.cxf.frontend.ServerFactoryBean;
+import org.apache.hello_world_soap_http.GreeterImpl;
+
+public class CxfProducerRouterTest extends ContextTestSupport {
+ private static final transient Log LOG = LogFactory.getLog(CxfProducerRouterTest.class);
+ private final static String SIMPLE_SERVER_ADDRESS = "http://localhost:28080/test";
+ private ServerImpl simpleServer;
+ private final static String ECHO_OPERATION = "echo";
+ private final static String TEST_MESSAGE = "Hello World!";
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ // start a simple front service
+ ServerFactoryBean svrBean = new ServerFactoryBean();
+ svrBean.setAddress(SIMPLE_SERVER_ADDRESS);
+ svrBean.setServiceClass(HelloService.class);
+ svrBean.setServiceBean(new HelloServiceImpl());
+ svrBean.setBus(CXFBusFactory.getDefaultBus());
+
+ simpleServer = (ServerImpl)svrBean.create();
+ simpleServer.start();
+
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (simpleServer != null) {
+ simpleServer.stop();
+ }
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:EndpointA").to(getSimpleEndpointUri());
+ }
+ };
+ }
+
+ public void testInvokingSimpleServerWithParams() throws Exception {
+ Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
+ final List<String> params = new ArrayList<String>();
+ params.add(TEST_MESSAGE);
+ senderExchange.getIn().setBody(params);
+ senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);
+
+ Exchange exchange = template.send("direct:EndpointA", senderExchange);
+
+ org.apache.camel.Message out = exchange.getOut();
+ Object[] output = (Object[])out.getBody();
+ LOG.info("Received output text: " + output[0]);
+ assertEquals("reply body on Camel", "echo " + TEST_MESSAGE, output[0]);
+ }
+
+
+ private String getSimpleEndpointUri() {
+ return "cxf://" + SIMPLE_SERVER_ADDRESS
+ + "?serviceClass=org.apache.camel.component.cxf.HelloService";
+ }
+
+}
Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerRouterTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java?rev=611197&r1=611196&r2=611197&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfProducerTest.java
Fri Jan 11 07:06:13 2008
@@ -94,7 +94,7 @@
org.apache.camel.Message out = exchange.getOut();
Object[] output = (Object[])out.getBody();
LOG.info("Received output text: " + output[0]);
- assertEquals("reply body on Camel", TEST_MESSAGE, output[0]);
+ assertEquals("reply body on Camel", "echo " + TEST_MESSAGE, output[0]);
}
Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java?rev=611197&r1=611196&r2=611197&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfRouterTest.java
Fri Jan 11 07:06:13 2008
@@ -89,7 +89,7 @@
HelloService client = (HelloService) proxyFactory.create();
String result = client.echo("hello world");
- assertEquals("we should get the right answer from router", "hello world", result);
+ assertEquals("we should get the right answer from router", "echo hello world", result);
}
Modified: activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java?rev=611197&r1=611196&r2=611197&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/HelloServiceImpl.java
Fri Jan 11 07:06:13 2008
@@ -26,7 +26,7 @@
public String echo(String text) {
LOG.info("call for echo with " + text);
- return text;
+ return "echo " + text;
}
public void ping() {
|