Skip to content

Commit 87639c6

Browse files
author
YunaiV
committed
开始 WebService 入门示例
1 parent e51ad0a commit 87639c6

File tree

12 files changed

+218
-172
lines changed

12 files changed

+218
-172
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>lab-65-cxf-ws-demo</artifactId>
7+
<groupId>cn.iocoder.springboot.labs</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>lab-65-cxf-ws-demo-application</artifactId>
13+
14+
<properties>
15+
<!-- 依赖相关配置 -->
16+
<spring.boot.version>2.2.4.RELEASE</spring.boot.version>
17+
<!-- 插件相关配置 -->
18+
<maven.compiler.target>1.8</maven.compiler.target>
19+
<maven.compiler.source>1.8</maven.compiler.source>
20+
</properties>
21+
22+
<dependencyManagement>
23+
<dependencies>
24+
<dependency>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-starter-parent</artifactId>
27+
<version>${spring.boot.version}</version>
28+
<type>pom</type>
29+
<scope>import</scope>
30+
</dependency>
31+
</dependencies>
32+
</dependencyManagement>
33+
34+
<dependencies>
35+
<!-- 实现 CXF 对 Web Services 的自动配置 -->
36+
<dependency>
37+
<groupId>org.apache.cxf</groupId>
38+
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
39+
<version>3.3.6</version>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.cxf</groupId>
47+
<artifactId>cxf-codegen-plugin</artifactId>
48+
<version>3.2.5</version>
49+
<executions>
50+
<execution>
51+
<id>generate-sources</id>
52+
<phase>generate-sources</phase>
53+
<configuration>
54+
<sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
55+
<wsdlOptions>
56+
<wsdlOption>
57+
<wsdl>src/main/resources/wsdl/user.wsdl</wsdl>
58+
<wsdlLocation>classpath:wsdl/user.wsdl</wsdlLocation>
59+
</wsdlOption>
60+
</wsdlOptions>
61+
</configuration>
62+
<goals>
63+
<goal>wsdl2java</goal>
64+
</goals>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
<!-- &lt;!&ndash; maven-jaxb2-plugin 插件,用于实现将 WSDL 生成目标类 &ndash;&gt;-->
69+
<!-- <plugin>-->
70+
<!-- <groupId>org.jvnet.jaxb2.maven2</groupId>-->
71+
<!-- <artifactId>maven-jaxb2-plugin</artifactId>-->
72+
<!-- <version>0.14.0</version>-->
73+
<!-- <executions>-->
74+
<!-- <execution>-->
75+
<!-- <goals>-->
76+
<!-- <goal>generate</goal>-->
77+
<!-- </goals>-->
78+
<!-- </execution>-->
79+
<!-- </executions>-->
80+
<!-- <configuration>-->
81+
<!-- &lt;!&ndash; WSDL 源文件地址 &ndash;&gt;-->
82+
<!-- <schemaLanguage>WSDL</schemaLanguage>-->
83+
<!-- <schemas>-->
84+
<!-- <schema>-->
85+
<!-- <url>http://127.0.0.1:8080/ws/users.wsdl</url>-->
86+
<!-- </schema>-->
87+
<!-- </schemas>-->
88+
<!-- &lt;!&ndash; 生成代码目标包 &ndash;&gt;-->
89+
<!-- <generatePackage>cn.iocoder.springboot.lab65.demo.wsdl</generatePackage>-->
90+
<!-- </configuration>-->
91+
<!-- </plugin>-->
92+
</plugins>
93+
</build>
94+
95+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cn.iocoder.springboot.lab65.demo.config;
2+
3+
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserService;
4+
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
5+
import org.springframework.context.annotation.Bean;
6+
import org.springframework.context.annotation.Configuration;
7+
8+
@Configuration
9+
public class WebServicesConfig {
10+
11+
@Bean
12+
public UserService userService() {
13+
JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
14+
jaxWsProxyFactoryBean.setServiceClass(UserService.class);
15+
jaxWsProxyFactoryBean.setAddress("http://127.0.0.1:8080/ws/user");
16+
return (UserService) jaxWsProxyFactoryBean.create();
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package cn.iocoder.springboot.lab65.demo.controller;
2+
3+
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserGetRequest;
4+
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserGetResponse;
5+
import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserService;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestParam;
10+
import org.springframework.web.bind.annotation.RestController;
11+
12+
@RestController
13+
@RequestMapping("/demo")
14+
public class DemoController {
15+
16+
@Autowired
17+
private UserService userService;
18+
19+
@GetMapping("/get")
20+
public String get(@RequestParam("id") Integer id) {
21+
UserGetRequest request = new UserGetRequest();
22+
request.setId(id);
23+
// 执行 Web Services 请求
24+
UserGetResponse response = userService.get(request);
25+
// 响应
26+
return response.getName();
27+
}
28+
29+
// @GetMapping("/create") // 为了方便测试,实际使用 @PostMapping
30+
// public Integer create(@RequestParam("name") String name,
31+
// @RequestParam("gender") Integer gender) {
32+
// // 请求
33+
// UserCreateRequest request = new UserCreateRequest();
34+
// request.setName(name);
35+
// request.setGender(gender);
36+
// // 执行 Web Services 请求
37+
// UserCreateResponse response = userClient.createUser(name, gender);
38+
// // 响应
39+
// return response.getId();
40+
// }
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" name="userService" targetNamespace="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo">
2+
<wsdl:types>
3+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo" elementFormDefault="unqualified" targetNamespace="https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo" version="1.0">
4+
<xs:element name="get" type="tns:get"/>
5+
<xs:element name="getResponse" type="tns:getResponse"/>
6+
<xs:complexType name="get">
7+
<xs:sequence>
8+
<xs:element minOccurs="0" name="arg0" type="tns:userGetRequest"/>
9+
</xs:sequence>
10+
</xs:complexType>
11+
<xs:complexType name="userGetRequest">
12+
<xs:sequence>
13+
<xs:element minOccurs="0" name="id" type="xs:int"/>
14+
</xs:sequence>
15+
</xs:complexType>
16+
<xs:complexType name="getResponse">
17+
<xs:sequence>
18+
<xs:element minOccurs="0" name="return" type="tns:userGetResponse"/>
19+
</xs:sequence>
20+
</xs:complexType>
21+
<xs:complexType name="userGetResponse">
22+
<xs:sequence>
23+
<xs:element minOccurs="0" name="gender" type="xs:int"/>
24+
<xs:element minOccurs="0" name="id" type="xs:int"/>
25+
<xs:element minOccurs="0" name="name" type="xs:string"/>
26+
</xs:sequence>
27+
</xs:complexType>
28+
</xs:schema>
29+
</wsdl:types>
30+
<wsdl:message name="getResponse">
31+
<wsdl:part element="tns:getResponse" name="parameters"> </wsdl:part>
32+
</wsdl:message>
33+
<wsdl:message name="get">
34+
<wsdl:part element="tns:get" name="parameters"> </wsdl:part>
35+
</wsdl:message>
36+
<wsdl:portType name="UserService">
37+
<wsdl:operation name="get">
38+
<wsdl:input message="tns:get" name="get"> </wsdl:input>
39+
<wsdl:output message="tns:getResponse" name="getResponse"> </wsdl:output>
40+
</wsdl:operation>
41+
</wsdl:portType>
42+
<wsdl:binding name="userServiceSoapBinding" type="tns:UserService">
43+
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
44+
<wsdl:operation name="get">
45+
<soap:operation soapAction="" style="document"/>
46+
<wsdl:input name="get">
47+
<soap:body use="literal"/>
48+
</wsdl:input>
49+
<wsdl:output name="getResponse">
50+
<soap:body use="literal"/>
51+
</wsdl:output>
52+
</wsdl:operation>
53+
</wsdl:binding>
54+
<wsdl:service name="userService">
55+
<wsdl:port binding="tns:userServiceSoapBinding" name="UserServiceImplPort">
56+
<soap:address location="http://127.0.0.1:8080/ws/user"/>
57+
</wsdl:port>
58+
</wsdl:service>
59+
</wsdl:definitions>

lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/pom.xml

-77
This file was deleted.

lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/client/UserClient.java

-28
This file was deleted.

lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java

-29
This file was deleted.

lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java

-36
This file was deleted.

0 commit comments

Comments
 (0)