Nhắc đến SOAP thì là XML, XSD, WSDL, JAXB, JAX-WS, (Apache CXF & Spring-boot)
, SOAPUI.
Thông thường generate file java từ wsdl sẽ có 2 file chính là XxxService và XxxPortType, ví dụ có CustomerService.java và CustomerPortType.java
Example cách gọi SOAP client
try {
CustomerService service = new CustomerService(new URL("http://quachson.com/example/customer?wsdl"));
CustomerPortType portType = service.getCustomerPortType();
GetOrderRequest request = new GetOrderRequest();
request.setCustomerId(1L);
GetOrderResponse response = portType.getOrders(request);
// handle response ...
} catch(MalformedURLException e) {
... write log
}
Muốn build endpoint từ java file được generated từ wsdl thì implement lại XxxPortType
Google để lấy version mới nhất
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>3.4.1</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
<version>4.1.0</version>
</dependency>
Nếu dùng Java version >10 thì nên add thêm dependency JAXB API 2.1
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.1</version>
</dependency>
example apache cxf plugin, google thêm thì search: cxf code-gen plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>4.1.0</version> <!--must the same version above -->
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.build.directory}/generated-sources/cxf</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/query.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>