我想從駱駝呼叫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文件。你能幫我找到問題嗎?
謝謝
帕維爾
謝謝你的回答。這不是問題,但另一方面它不會造成任何傷害。看到我的工作示例波紋管。 –
任何人都可以請告訴我如何運行這個例子? –