diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/pom.xml b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/pom.xml new file mode 100644 index 00000000..142fa815 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/pom.xml @@ -0,0 +1,43 @@ + + + + lab-65-spring-ws-demo + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-65-cxf-ws-demo-user-service + + + + 2.2.4.RELEASE + + 1.8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-parent + ${spring.boot.version} + pom + import + + + + + + + + org.apache.cxf + cxf-spring-boot-starter-jaxws + 3.3.6 + + + + diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/UserServiceApplication.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/UserServiceApplication.java new file mode 100644 index 00000000..b76a9450 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/UserServiceApplication.java @@ -0,0 +1,14 @@ +package cn.iocoder.springboot.lab65.userservice; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class UserServiceApplication { + + public static void main(String[] args) { + // 启动 Spring Boot 应用 + SpringApplication.run(UserServiceApplication.class, args); + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/config/WebServicesConfig.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/config/WebServicesConfig.java new file mode 100644 index 00000000..be1d49a8 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/config/WebServicesConfig.java @@ -0,0 +1,28 @@ +package cn.iocoder.springboot.lab65.userservice.config; + +import cn.iocoder.springboot.lab65.userservice.service.UserService; +import org.apache.cxf.Bus; +import org.apache.cxf.bus.spring.SpringBus; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.xml.ws.Endpoint; + +@Configuration +public class WebServicesConfig { + + public static final String NAMESPACE_URI = "https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-65/lab-65-spring-ws-demo"; + + @Bean(name = Bus.DEFAULT_BUS_ID) + public SpringBus springBus() { + return new SpringBus(); + } + + @Bean + public Endpoint endpoint(UserService userService) { + Endpoint endpoint = Endpoint.create(userService); + endpoint.publish("/user");//发布地址 + return endpoint; + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/request/UserGetRequest.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/request/UserGetRequest.java new file mode 100644 index 00000000..e31db6a5 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/request/UserGetRequest.java @@ -0,0 +1,22 @@ +package cn.iocoder.springboot.lab65.userservice.request; + +/** + * 获得用户信息 Request + */ +public class UserGetRequest { + + /** + * 用户编号 + */ + private Integer id; + + public Integer getId() { + return id; + } + + public UserGetRequest setId(Integer id) { + this.id = id; + return this; + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/response/UserGetResponse.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/response/UserGetResponse.java new file mode 100644 index 00000000..68458748 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/response/UserGetResponse.java @@ -0,0 +1,47 @@ +package cn.iocoder.springboot.lab65.userservice.response; + +/** + * 获得用户信息 Response + */ +public class UserGetResponse { + + /** + * 用户编号 + */ + private Integer id; + /** + * 昵称 + */ + private String name; + /** + * 性别别 + */ + private Integer gender; + + public Integer getId() { + return id; + } + + public UserGetResponse setId(Integer id) { + this.id = id; + return this; + } + + public String getName() { + return name; + } + + public UserGetResponse setName(String name) { + this.name = name; + return this; + } + + public Integer getGender() { + return gender; + } + + public UserGetResponse setGender(Integer gender) { + this.gender = gender; + return this; + } +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/service/UserService.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/service/UserService.java new file mode 100644 index 00000000..aa3d7f93 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/service/UserService.java @@ -0,0 +1,17 @@ +package cn.iocoder.springboot.lab65.userservice.service; + +import cn.iocoder.springboot.lab65.userservice.config.WebServicesConfig; +import cn.iocoder.springboot.lab65.userservice.request.UserGetRequest; +import cn.iocoder.springboot.lab65.userservice.response.UserGetResponse; + +import javax.jws.WebService; + +@WebService(targetNamespace = WebServicesConfig.NAMESPACE_URI +// , +// name = "userPortName" +) +public interface UserService { + + UserGetResponse get(UserGetRequest request); + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/service/UserServiceImpl.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/service/UserServiceImpl.java new file mode 100644 index 00000000..7b0c6f71 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/java/cn/iocoder/springboot/lab65/userservice/service/UserServiceImpl.java @@ -0,0 +1,37 @@ +package cn.iocoder.springboot.lab65.userservice.service; + +import cn.iocoder.springboot.lab65.userservice.config.WebServicesConfig; +import cn.iocoder.springboot.lab65.userservice.request.UserGetRequest; +import cn.iocoder.springboot.lab65.userservice.response.UserGetResponse; +import org.springframework.stereotype.Service; + +import javax.jws.WebService; + +@WebService( + serviceName = "userService", // 服务名称 + targetNamespace = WebServicesConfig.NAMESPACE_URI, // WSDL 命名空间 + endpointInterface = "cn.iocoder.springboot.lab65.userservice.service.UserService" // Web Services 对应接口 +// name = "userPortType", // portType 名称,作为客户端生成代码时的接口名称 TODO +// portName = "userPortName" // port 名称 TODO +) +@Service +public class UserServiceImpl implements UserService { + + @Override + public UserGetResponse get(UserGetRequest request) { + UserGetResponse response = new UserGetResponse(); + response.setId(request.getId()); + response.setName("没有昵称:" + request.getId()); + response.setGender(request.getId() % 2 + 1); + return response; + } + +// @PayloadRoot(namespace = WebServicesConfig.NAMESPACE_URI, localPart = "UserCreateRequest") +// @ResponsePayload +// public UserCreateResponse create(@RequestPayload UserCreateRequest request) { +// UserCreateResponse response = new UserCreateResponse(); +// response.setId((int) (System.currentTimeMillis() / 1000)); +// return response; +// } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/resources/application.yml b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/resources/application.yml new file mode 100644 index 00000000..a3643e9b --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-user-service/src/main/resources/application.yml @@ -0,0 +1,3 @@ +# CXF 配置项,对应 CxfProperties 配置类 +cxf: + path: /ws/ # CXF CXFServlet 的匹配路径 diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/pom.xml b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/pom.xml new file mode 100644 index 00000000..df1533cc --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/pom.xml @@ -0,0 +1,77 @@ + + + + lab-65-spring-ws-demo + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-65-spring-ws-demo-application + + + + 2.2.4.RELEASE + + 1.8 + 1.8 + + + + + + org.springframework.boot + spring-boot-starter-parent + ${spring.boot.version} + pom + import + + + + + + + + org.springframework.boot + spring-boot-starter-web-services + + + + + wsdl4j + wsdl4j + + + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + 0.14.0 + + + + generate + + + + + + WSDL + + + http://127.0.0.1:8080/ws/users.wsdl + + + + cn.iocoder.springboot.lab65.demo.wsdl + + + + + + diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/DemoApplication.java b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/DemoApplication.java new file mode 100644 index 00000000..1a3adfe7 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/DemoApplication.java @@ -0,0 +1,14 @@ +package cn.iocoder.springboot.lab65.demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class DemoApplication { + + public static void main(String[] args) { + // 启动 Spring Boot 应用 + SpringApplication.run(DemoApplication.class, args); + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/client/UserClient.java b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/client/UserClient.java new file mode 100644 index 00000000..5ad60a72 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/client/UserClient.java @@ -0,0 +1,28 @@ +package cn.iocoder.springboot.lab65.demo.client; + +import cn.iocoder.springboot.lab65.demo.wsdl.UserCreateRequest; +import cn.iocoder.springboot.lab65.demo.wsdl.UserCreateResponse; +import cn.iocoder.springboot.lab65.demo.wsdl.UserGetRequest; +import cn.iocoder.springboot.lab65.demo.wsdl.UserGetResponse; +import org.springframework.ws.client.core.support.WebServiceGatewaySupport; + +public class UserClient extends WebServiceGatewaySupport { + + public UserGetResponse getUser(Integer id) { + // 创建请求对象 + UserGetRequest request = new UserGetRequest(); + request.setId(id); + // 执行请求 + return (UserGetResponse) getWebServiceTemplate().marshalSendAndReceive(request); + } + + public UserCreateResponse createUser(String name, Integer gender) { + // 创建请求对象 + UserCreateRequest request = new UserCreateRequest(); + request.setName(name); + request.setGender(gender); + // 执行请求 + return (UserCreateResponse) getWebServiceTemplate().marshalSendAndReceive(request); + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java new file mode 100644 index 00000000..34c19730 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java @@ -0,0 +1,29 @@ +package cn.iocoder.springboot.lab65.demo.config; + +import cn.iocoder.springboot.lab65.demo.client.UserClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.oxm.jaxb.Jaxb2Marshaller; + +@Configuration +public class WebServicesConfig { + + // 创建 Jaxb2Marshaller Bean,实现 XML 与 Bean 的互相转换 + @Bean + public Jaxb2Marshaller marshaller() { + Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); + marshaller.setContextPath("cn.iocoder.springboot.lab65.demo.wsdl"); // 用户服务的 WSDL 文件 + return marshaller; + } + + // 创建 UserClient Bean + @Bean + public UserClient countryClient(Jaxb2Marshaller marshaller) { + UserClient client = new UserClient(); + client.setDefaultUri("http://127.0.0.1:8080/ws"); // 用户服务的 Web Services 地址 + client.setMarshaller(marshaller); + client.setUnmarshaller(marshaller); + return client; + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java new file mode 100644 index 00000000..b9f4a9f0 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java @@ -0,0 +1,36 @@ +package cn.iocoder.springboot.lab65.demo.controller; + +import cn.iocoder.springboot.lab65.demo.client.UserClient; +import cn.iocoder.springboot.lab65.demo.wsdl.UserCreateResponse; +import cn.iocoder.springboot.lab65.demo.wsdl.UserGetResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/demo") +public class DemoController { + + @Autowired + private UserClient userClient; + + @GetMapping("/get") + public String get(@RequestParam("id") Integer id) { + // 执行 Web Services 请求 + UserGetResponse response = userClient.getUser(id); + // 响应 + return response.getName(); + } + + @GetMapping("/create") // 为了方便测试,实际使用 @PostMapping + public Integer create(@RequestParam("name") String name, + @RequestParam("gender") Integer gender) { + // 执行 Web Services 请求 + UserCreateResponse response = userClient.createUser(name, gender); + // 响应 + return response.getId(); + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/resources/application.yml b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/resources/application.yml new file mode 100644 index 00000000..f9e9468c --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/resources/application.yml @@ -0,0 +1,2 @@ +server: + port: 9090 diff --git a/lab-65/lab-65-cxf-ws-demo/pom.xml b/lab-65/lab-65-cxf-ws-demo/pom.xml new file mode 100644 index 00000000..81f5bd49 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/pom.xml @@ -0,0 +1,20 @@ + + + + lab-65 + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-65-cxf-ws-demo + pom + + lab-65-cxf-ws-demo-user-service + + + + + diff --git a/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-application/pom.xml b/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-application/pom.xml index 80345a4d..df1533cc 100644 --- a/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-application/pom.xml +++ b/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-application/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - lab4-64-spring-ws-demo + lab-65-spring-ws-demo cn.iocoder.springboot.labs 1.0-SNAPSHOT diff --git a/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-user-service/pom.xml b/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-user-service/pom.xml index f96323b9..2c82e19a 100644 --- a/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-user-service/pom.xml +++ b/lab-65/lab-65-spring-ws-demo/lab-65-spring-ws-demo-user-service/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - lab4-64-spring-ws-demo + lab-65-spring-ws-demo cn.iocoder.springboot.labs 1.0-SNAPSHOT diff --git a/lab-65/lab-65-spring-ws-demo/pom.xml b/lab-65/lab-65-spring-ws-demo/pom.xml index d7499d80..17153b8e 100644 --- a/lab-65/lab-65-spring-ws-demo/pom.xml +++ b/lab-65/lab-65-spring-ws-demo/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - lab4-64-spring-ws-demo + lab-65-spring-ws-demo pom lab-65-spring-ws-demo-user-service diff --git a/lab-65/pom.xml b/lab-65/pom.xml index b8c3259c..936c1f21 100644 --- a/lab-65/pom.xml +++ b/lab-65/pom.xml @@ -14,6 +14,7 @@ lab-65-spring-ws-demo lab-65-ws-feign-client + lab-65-cxf-ws-demo