[英]Is Camel Automatically generate SOAP Message?
如果我們提供所需的對象結構,Apache Camel是否會自動生成SOAP消息?
如果不是,為什么我應該使用Camel調用Web服務?
請提供具體原因,以幫助它調用任何SOAP Web服務。
我的駱駝配置是
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("In ........");
exchange.getIn().setBody("<country>india</country>");
System.out.println("in process method");
System.out.println(exchange.getExchangeId() + " : " + exchange.getFromRouteId() + " : " + exchange.isFailed());
}
}).
to("cxf://http://www.webservicex.net/airport.asmx?" + "wsdlURL=http://www.webservicex.net/airport.asmx?wsdl&"
+ "serviceName={http://www.webserviceX.NET}airport&" + "portName={http://www.webserviceX.NET}airportSoap&"
+ "defaultOperationName=GetAirportInformationByCountry&" + "dataFormat=MESSAGE")
.to("file:/home/viral?fileName=output.txt");
}
});
謝謝。
如果我們提供所需的對象結構,Apache Camel是否會自動生成SOAP消息?
總體而言,
您不需要自己制作SOAP信封。 您只需要編寫自定義Processor
在其中定義SOAP消息。 另外,在camelContext
您需要定義endpoint
和route
。 如果發生錯誤,它也將處理soapfault
,或者您也可以編寫自己的自定義錯誤SOAP響應。
更新以回復您的評論:
如果要制作通用的駱駝處理器,則可以每次將消息正文添加到XML文件中,並設置為SOAPBody,如下所示
...
@Override
public void process(Exchange exchange) throws Exception {
System.out.println("In ........");
try {
File file = new File("soapbody.xml"); // generic body in separate XML file for every time
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
String body = doc.toString();
exchange.getIn().setBody(body );
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("in process method");
System.out.println(exchange.getExchangeId() + " : " + exchange.getFromRouteId() + " : " + exchange.isFailed());
}
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.