在Apache Camel中使用soap服务

时间:2017-03-30 09:49:35

标签: apache apache-camel

我想使用Java DSL在apache camel中使用soap web服务。没有CXF.i的任何方法已经尝试使用带有弹簧的CXF。

1 个答案:

答案 0 :(得分:0)

这是一个只使用camel http而不使用cxf的简单示例。如果您需要对SOAP请求字符串执行一些修改,您只需更改"常量"类似于" spel"。

<setBody><constant><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
  <MyAction>
     <myparam>ABC</myparam>
  </MyAction>
</soapenv:Body>
</soapenv:Envelope>]]></constant></setBody>
<setHeader headerName="SOAPAction"><constant>MySOAPAction</constant></setHeader>
<setHeader headerName="CamelHttpMethod"><constant>POST</constant></setHeader>
<setHeader headerName="Content-Type"><constant>text/xml;charset=UTF-8</constant></setHeader>
<to uri="http://myserver:1234" />

与Java DSL相同

public class MyRouteBuilder extends RouteBuilder {
  public void configure() {
    from("direct:start")
      .setBody(constant("")) // String SOAP content from XML example
      .setHeader("SOAPAction", constant("MySOAPAction"))
      .setHeader("CamelHttpMethod", constant("POST"))
      .setHeader("Content-Type", constant("text/xml;charset=UTF-8"))
      .to("http://myserver:1234")
      .log("SOAP service called"); // Here you can process service response
    }
}