[英]Call SOAP web services by using Apache Camel and Spring Boot
我是 Apache 骆驼的新手。 目前,我正在尝试实现一个用例,其中我需要使用 Spring Boot 和 Apache Camel 来使用远程 SOAP Web 服务。
问题 -
阿维纳什
你可以。 首先,您需要获取 web 服务的 xsd 并在 resources/ws 文件夹中创建.xsd 文件
<xsd:schema targetNamespace="http://xx.com/xx" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://xx.com/xx">
<xsd:element name="MT_INPUT_REQUEST" type="DT_INPUT_REQUEST"/>
<xsd:complexType name="DT_INPUT_REQUEST">
<xsd:annotation>
<xsd:documentation xml:lang="EN">Key Account Order Header</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="x" type="xsd:string" minOccurs="0"/>
<xsd:element name="y" type="xsd:string" minOccurs="0"/>
<xsd:element name="ds" type="xsd:string" minOccurs="0"/>
<xsd:element name="da" type="xsd:string" minOccurs="0"/>
<xsd:element name="da" type="xsd:string" minOccurs="0"/>
<xsd:element name="ddas" type="xsd:string" minOccurs="0"/>
<xsd:element name="das" type="xsd:string" minOccurs="0"/>
<xsd:element name="dsa" type="xsd:string" minOccurs="0"/>
<xsd:element name="dasd" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="da" type="xsd:string" minOccurs="0"/>
<xsd:element name="dsa" type="xsd:string" minOccurs="0"/>
<xsd:element name="das" type="xsd:string" minOccurs="0"/>
<xsd:element name="da" type="xsd:string" minOccurs="0"/>
<xsd:element name="da" type="xsd:string" minOccurs="0"/>
<xsd:element name="das" type="xsd:string" minOccurs="0"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType></xsd:schema>
然后你需要创建这个 xsd 的 class 这个插件创建类只需运行 mvn clean install
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>iso8859-9</encoding>
<schemaDirectory>${basedir}/src/main/resources/ws</schemaDirectory>
<schemaIncludes>*.xsd</schemaIncludes>
</configuration>
</plugin>
你需要一个 java class 到字节 stream 的编组器你可以这样创建
public JaxbDataFormat marshaller() throws JAXBException {
JaxbDataFormat jaxbDataFormat = new JaxbDataFormat(JAXBContext.newInstance("xx.com"));
jaxbDataFormat.setEncoding("ISO-8859-9");
jaxbDataFormat.setFilterNonXmlChars(true);
return jaxbDataFormat;
}
之后,您必须创建一个引用的 xsds 的 class 并在 thar unmarshall 最终调用之后放置正文
.marshal(jaxbDataformat)
to("spring-ws:http://soapservice/bar")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.