Camel是否自动生成SOAP消息?

时间:2015-06-04 10:06:48

标签: java web-services soap apache-camel

如果我们提供所需的对象结构,Apache Camel会自动生成SOAP消息吗?

如果不是为什么我应该使用Camel来调用Web服务?

请提供具体原因,以帮助调用任何SOAP Web服务。

我的Camel配置

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");

            }
        });

感谢。

1 个答案:

答案 0 :(得分:2)

  

如果我们提供所需的对象结构,Apache Camel会自动生成SOAP消息吗?

总的来说,

您不需要自己制作SOAP信封。您只需编写定义SOAP消息的自定义Processor即可。加上camelContext,您需要定义endpointroute。如果出现错误,它也会处理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());
}
...