diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/pom.xml b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/pom.xml new file mode 100644 index 00000000..d338beca --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/pom.xml @@ -0,0 +1,95 @@ + + + + lab-65-cxf-ws-demo + cn.iocoder.springboot.labs + 1.0-SNAPSHOT + + 4.0.0 + + lab-65-cxf-ws-demo-application + + + + 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 + + + + + + + org.apache.cxf + cxf-codegen-plugin + 3.2.5 + + + generate-sources + generate-sources + + ${project.build.directory}/generated/cxf + + + src/main/resources/wsdl/user.wsdl + classpath:wsdl/user.wsdl + + + + + wsdl2java + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/DemoApplication.java similarity index 100% rename from lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/DemoApplication.java rename to lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/DemoApplication.java diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java new file mode 100644 index 00000000..0745b3cd --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/config/WebServicesConfig.java @@ -0,0 +1,19 @@ +package cn.iocoder.springboot.lab65.demo.config; + +import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserService; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class WebServicesConfig { + + @Bean + public UserService userService() { + JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); + jaxWsProxyFactoryBean.setServiceClass(UserService.class); + jaxWsProxyFactoryBean.setAddress("http://127.0.0.1:8080/ws/user"); + return (UserService) jaxWsProxyFactoryBean.create(); + } + +} diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java new file mode 100644 index 00000000..6f5f72b2 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java @@ -0,0 +1,42 @@ +package cn.iocoder.springboot.lab65.demo.controller; + +import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserGetRequest; +import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserGetResponse; +import https.github_com.yunaiv.springboot_labs.tree.master.lab_65.lab_65_spring_ws_demo.UserService; +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 UserService userService; + + @GetMapping("/get") + public String get(@RequestParam("id") Integer id) { + UserGetRequest request = new UserGetRequest(); + request.setId(id); + // 执行 Web Services 请求 + UserGetResponse response = userService.get(request); + // 响应 + return response.getName(); + } + +// @GetMapping("/create") // 为了方便测试,实际使用 @PostMapping +// public Integer create(@RequestParam("name") String name, +// @RequestParam("gender") Integer gender) { +// // 请求 +// UserCreateRequest request = new UserCreateRequest(); +// request.setName(name); +// request.setGender(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-cxf-ws-demo-application/src/main/resources/application.yml similarity index 100% rename from lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/src/main/resources/application.yml rename to lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/resources/application.yml diff --git a/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/resources/wsdl/user.wsdl b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/resources/wsdl/user.wsdl new file mode 100644 index 00000000..180e4b08 --- /dev/null +++ b/lab-65/lab-65-cxf-ws-demo/lab-65-cxf-ws-demo-application/src/main/resources/wsdl/user.wsdl @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 deleted file mode 100644 index df1533cc..00000000 --- a/lab-65/lab-65-cxf-ws-demo/lab-65-spring-ws-demo-application/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - 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/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 deleted file mode 100644 index 5ad60a72..00000000 --- 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 +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index 34c19730..00000000 --- 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 +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index b9f4a9f0..00000000 --- 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 +++ /dev/null @@ -1,36 +0,0 @@ -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/pom.xml b/lab-65/lab-65-cxf-ws-demo/pom.xml index 81f5bd49..06c8a0bb 100644 --- a/lab-65/lab-65-cxf-ws-demo/pom.xml +++ b/lab-65/lab-65-cxf-ws-demo/pom.xml @@ -13,7 +13,7 @@ pom lab-65-cxf-ws-demo-user-service - + lab-65-cxf-ws-demo-application diff --git a/lab-65/lab-65-ws-feign-client/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java b/lab-65/lab-65-ws-feign-client/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java index 9dd5da73..dd8c6f51 100644 --- a/lab-65/lab-65-ws-feign-client/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java +++ b/lab-65/lab-65-ws-feign-client/src/main/java/cn/iocoder/springboot/lab65/demo/controller/DemoController.java @@ -20,6 +20,7 @@ public class DemoController { @GetMapping("/get") public String get(@RequestParam("id") Integer id) { + // 请求 UserGetRequest request = new UserGetRequest(); request.setId(id); // 执行 Web Services 请求 @@ -31,7 +32,7 @@ public class DemoController { @GetMapping("/create") // 为了方便测试,实际使用 @PostMapping public Integer create(@RequestParam("name") String name, @RequestParam("gender") Integer gender) { - // 创建 + // 请求 UserCreateRequest request = new UserCreateRequest(); request.setName(name); request.setGender(gender);