반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Jenkins
- java
- maven
- jsp
- spring-framework
- soap
- Pipeline
- oracle
- Spring
- JAR
- gitlab
- SpringFramework
- hashcode
- tomcat
- git
- Spring Framework
- 스프링프레임워크
- REST
- 스프링부트
- Gradle
- 개발
- Web
- springboot
- Linux
- mybatis
- Spring Boot
- War
- 이클립스
- 웹프로젝트
- annotaion
Archives
- Today
- Total
Verity's Daily Logs_
[SOAP]Web Service - Clien side 생성 본문
반응형
3. Client access service
3-1. wsdl 다운로드
http://localhost:8088/ws/user?wsdl
- 이전 글(Server side 생성)에서 만든 wsdl 주소로 접속해 해당 내용을 user.wsdl 이름으로 저장한다.
- 프로젝트 내 resources/wsdl 경로에 파일을 저장한다. (wsdl 폴더 생성 후 저장)
- 첫 줄에 아래 문구를 추가한다. (보통 추가되어 있음)
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
3-2. pom.xml - plugin 추가
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>3.5.0</version>
<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/user.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
Maven > Plugins > cxf-codegen > csf-codegen:wsdl2java 실행 및 결과
3-3. Configuration 추가
csf-codegen:wsdl2java 실행으로 얻은 UserService, User를 import 하도록 주의
Server side에서 만든 UserService, User 가 아님을 주의하자. (import 경로 확인 필수)
package com.happy.webservice.cxf.config;
import com.happy.cxf.ws.UserService;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class CxfClientConfig {
@Value("${server.serviceUrl}")
private String serviceUrl;
@Bean
public UserService userService() throws Exception {
JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
jaxWsProxyFactoryBean.setServiceClass(UserService.class);
jaxWsProxyFactoryBean.setAddress(serviceUrl);
UserService userService = (UserService) jaxWsProxyFactoryBean.create();
return userService;
}
}
3-4. application.yml 추가
server:
port: 8088
serviceUrl: <http://localhost:8088/ws/user>
3-5 Facade 클래스 추가
package com.happy.webservice.cxf.service;
import com.happy.cxf.ws.User;
import com.happy.cxf.ws.UserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class UserFacadeService {
@Resource
private UserService userService;
public String getUsername(String userId) {
String userName = userService.getUserName(userId);
return userName;
}
public User getUser(String userId) {
User user = userService.getUser(userId);
return user;
}
public List<User> getUserList(String userId) {
List<User> userList = userService.getUserList(userId);
return userList;
}
}
3-6 테스트용 Controller 추가
package com.happy.webservice.cxf.controller;
import com.happy.cxf.ws.User;
import com.happy.webservice.cxf.service.UserFacadeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/user-client")
public class UserController {
@Resource
private UserFacadeService userFacadeService;
@GetMapping("/get")
public String getUsername(String userId){
System.out.println("client#userId:" + userId);
return userFacadeService.getUsername(userId);
}
@GetMapping("/getUser")
public User getUser(String userId){
System.out.println("client#userId:" + userId);
return userFacadeService.getUser(userId);
}
@GetMapping("/getUserList")
public List<User> getUserList(String userId){
System.out.println("client#userId:" + userId);
return userFacadeService.getUserList(userId);
}
}
3-7. TEST
http://localhost:8088/user-client/get?userId=1
[참고] https://www.fatalerrors.org/a/spring-boot-quickly-integrates-cxf.html
반응형
'Spring Framework > Project' 카테고리의 다른 글
[SOAP]Web Service - Clien side Logging 출력 (0) | 2022.02.24 |
---|---|
[SOAP]Web Service - Server side 생성 (2) | 2022.02.16 |
[SOAP]Web Service Project 개요 (0) | 2022.02.14 |
[SOAP]프로젝트 생성 방법 (0) | 2022.02.14 |
[SOAP]Web Service (SOAP, REST) (0) | 2022.02.09 |
Comments