我想从 Camel 调用网络服务。但是每次调用该服务时我都会收到 null 。你能帮我找到解决办法吗?
该服务在tomcat上运行,我可以用soapUI对其进行测试。这是来自 SoapUI 的请求。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://helloworld.localhost">
<soapenv:Header/>
<soapenv:Body>
<hel:HelloWorldRequest>
<hel:input>Pavel</hel:input>
</hel:HelloWorldRequest>
</soapenv:Body>
</soapenv:Envelope>
并且响应返回 Hello Pavel。我按照 CamelInAction 指南创建了合同优先的 Web 服务。我能够运行读取文件并将其发送到 Web 服务的路由。
路线的代码如下。
public class FileToWsRoute extends RouteBuilder {
public void configure() {
from("file://src/data?noop=false")
.process(new FileProcessor())
.to("cxf:bean:helloWorld");
}
}
FileProcessor 类如下所示:
public class FileProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
System.out.println("We just downloaded: "
+ exchange.getIn().getHeader("CamelFileName"));
String text =
"<?xml version='1.0' ?>"
+"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:hel=\"http://helloworld.localhost\">"
+"<soapenv:Header/>"
+ "<soapenv:Body>"
+ " <hel:HelloWorldRequest>"
+ " <hel:input>WhatsUP</hel:input>"
+ " </hel:HelloWorldRequest>"
+ "</soapenv:Body>"
+"</soapenv:Envelope>";
exchange.getIn().setBody(text);
}
}
在下一个版本中,我想通过 cxf-codegen-plugin 生成的对象(HalloWorld.java,HelloWorldImpl.java,HelloWorldRequest.java,HelloWorldResponse.java,HelloWorldService.java,ObjectFactory.java,package-info.java )。
在 camel-cxf.xml 我有:
<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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.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-jetty.xml"/>
<cxf:cxfEndpoint id="helloWorld"
address="http://localhost:8080/ode/processes/HelloWorld"
serviceClass="localhost.helloworld.HelloWorld"
wsdlURL="wsdl/HelloWorld.wsdl"/>
</beans>
要读取来自 Web 服务的响应,我正在使用这条路线。
public class WsToQueueRoute extends RouteBuilder {
public void configure() {
from("cxf:bean:helloWorld")
.to("seda:incomingOrders")
.transform().constant("OK");
}
}
最后一条路由从 seda 获取数据...
public class QueueToProcessRoute extends RouteBuilder {
public void configure() {
from("seda:incomingOrders")
.process(new PrintResult());
}
}
...并打印结果。
public class PrintResult implements Processor {
public void process(Exchange exchange) throws Exception {
System.out.println("Data received: "
+ exchange.getIn().getBody(String.class));
}
}
执行的输出是:收到的数据:null
我希望有一些可以用 cxf 对象解析的 XML 文件。你能帮我找出问题吗?
谢谢
帕维尔