我想从骆驼呼叫web服务。但每次我致电该服务时,我都会收到空。 你能帮我找到解决方案吗?从骆驼呼叫web服务
服务在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-插件(HalloWorld.java,HelloWorldImpl.java生成的对象的请求, HelloWorldRequest.java,HelloWorldResponse.java,HelloWorldService.java,ObjectFactory.java,package-info.java)。
在骆驼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));
}
}
从执行的输出是: 收到的数据:空
我希望我可以用CXF对象分析一些XML文件。你能帮我找到问题吗?
谢谢
帕维尔
谢谢你的回答。这不是问题,但另一方面它不会造成任何伤害。看到我的工作示例波纹管。 –
任何人都可以请告诉我如何运行这个例子? –