Spring WS-퀵 가이드
Spring Web Services (Spring-WS)는 Spring Community에서 개발 한 프로젝트 중 하나입니다. 주요 초점은 문서 중심 웹 서비스를 만드는 것입니다. Spring Web Services 프로젝트는 계약 우선을 용이하게합니다.SOAP Service Development는 다양한 방법으로 XML 페이로드를 조작 할 수있는 유연한 웹 서비스를 만드는 여러 방법을 제공합니다.
Spring 웹 서비스는 종속성 주입 및 구성과 같은 Spring 개념을 원활하게 사용합니다. Spring-WS에는 Spring 3.0 버전이 필요합니다. 계약 우선 개발로 시작합니다.WSDL Contract 그런 다음 JAVA를 사용하여 필요한 계약을 구현합니다.
JAVA 인터페이스가 WSDL / XSD 계약을 생성하는 계약-마지막 접근 방식과 반대입니다. WSDL 기반 계약은 계약 우선 접근 방식에서 JAVA 구현과 독립적입니다. JAVA 인터페이스를 변경해야하는 경우 기존 WSDL 계약의 변경 사항을 웹 서비스 사용자에게 전달할 필요가 없습니다. Spring-WS는 WSDL 계약과 JAVA 기반 구현 간의 느슨한 결합을 제공하는 것을 목표로합니다.
풍모
다음은 Spring Web Services의 기능입니다.
- XML Mapping to Objects − XML 기반 요청은 Message Payload, SOAP Action Header에 저장된 정보를 사용하거나 XPath Expression을 사용하여 모든 객체에 매핑 될 수 있습니다. 
- Multiple API Support to parse XML − 들어오는 XML 요청을 구문 분석하는 표준 JAXP API (DOM, SAX, StAX) 외에도 JDOM, dom4j, XOM과 같은 다른 라이브러리도 지원됩니다. 
- Multiple API Support to marshal XML− Spring Web Services는 Object / XML Mapping 모듈을 사용하여 JAXB 1 및 2, Castor, XMLBeans, JiBX 및 XStream 라이브러리를 지원합니다. Object / XML Mapping 모듈은 웹 서비스가 아닌 코드에서도 사용할 수 있습니다. 
- Spring based configurations − Spring Web Services는 Spring Web MVC와 유사한 아키텍처를 갖는 구성을 위해 Spring Application Contexts를 사용합니다. 
- Integrated WS-Security module − WS-Security 모듈을 사용하여 SOAP 메시지에 서명, 암호화, 복호화 또는 인증 할 수 있습니다. 
- Support for Acegi Security − Spring Web Services의 WS-Security 구현을 사용하여 Acegi 구성을 SOAP 서비스에 사용할 수 있습니다. 
건축물
Spring-WS 프로젝트는 다음과 같은 5 개의 주요 모듈로 구성됩니다.
- Spring-WS Core − 기본 모듈이며 다음과 같은 중앙 인터페이스를 제공합니다. WebServiceMessage 과 SoapMessage, 서버 측 프레임 워크, 강력한 메시지 디스패치 기능 및 웹 서비스 엔드 포인트 구현을위한 지원 클래스. 또한 웹 서비스 소비자 클라이언트를 다음과 같이 제공합니다.WebServiceTemplate. 
- Spring-WS Support −이 모듈은 JMS, 이메일 등을 지원합니다. 
- Spring-WS Security−이 모듈은 핵심 웹 서비스 모듈과 통합 된 WS-Security 구현을 제공합니다. 이 모듈을 사용하여 주요 토큰을 추가하고 SOAP 메시지에 서명, 암호화 및 해독 할 수 있습니다. 이 모듈은 인증 및 권한 부여를 위해 기존 Spring Security 구현을 사용할 수 있도록합니다. 
- Spring XML−이 모듈은 Spring Web Services를위한 XML 지원 클래스를 제공합니다. 이 모듈은 Spring-WS 프레임 워크에서 내부적으로 사용됩니다. 
- Spring OXM −이 모듈은 XML vs Object Mapping에 대한 지원 클래스를 제공합니다. 
 
                이 장에서는 Windows 및 Linux 기반 시스템에서 Spring-WS를 설정하는 과정을 이해합니다. Spring-WS는 쉽게 설치하고 현재와 통합 할 수 있습니다.Java environment 과 MAVEN복잡한 설정 절차없이 몇 가지 간단한 단계를 따르면됩니다. 설치하는 동안 사용자 관리가 필요합니다.
시스템 요구 사항
다음 표에는 시스템 요구 사항이 나열되어 있으며 후속 단계에서는 환경 설정 절차를 안내합니다.
| JDK | Java SE 2 JDK 1.5 이상 | 
| 기억 | 1GB RAM (권장) | 
| 디스크 공간 | 최소 요구 사항 없음 | 
| 운영 체제 버전 | Windows XP 이상, Linux | 
이제 Spring-WS를 설치하는 단계를 진행하겠습니다.
1 단계 : Java 설치 확인
먼저 시스템에 Java SDK (Software Development Kit)가 설치되어 있어야합니다. 이를 확인하려면 작업중인 플랫폼에 따라 다음 두 명령 중 하나를 실행하십시오.
Java 설치가 제대로 완료되면 Java 설치의 현재 버전과 사양이 표시됩니다. 다음 표에는 샘플 출력이 나와 있습니다.
| 플랫폼 | 명령 | 샘플 출력 | 
|---|---|---|
| 윈도우 | 명령 콘솔을 열고 입력하십시오- \> 자바 버전 | 자바 버전 '1.7.0_60' Java (TM) SE 런타임 환경 (빌드 1.7.0_60-b19) Java Hotspot (TM) 64 비트 서버 VM (빌드 24.60-b09, 혼합 모드) | 
| 리눅스 | 명령 터미널을 열고 입력하십시오- $ java-버전 | 자바 버전 "1.7.0_25" JDK 런타임 환경 열기 (rhel-2.3.10.4.el6_4-x86_64) JDK 64 비트 서버 VM 열기 (빌드 23.7-b01, 혼합 모드) | 
- 이 자습서의 독자는 시스템에 Java SDK 버전 1.7.0_60이 설치되어 있다고 가정합니다. 
- Java SDK가없는 경우 현재 버전을 https://www.oracle.com/technetwork/java/javase/downloads/index.html 그리고 그것을 설치하십시오. 
2 단계 : Java 환경 설정
환경 변수 설정 JAVA_HOME 시스템에서 Java가 설치된 기본 디렉토리 위치를 가리 킵니다.
| S. 아니. | 플랫폼 및 설명 | 
|---|---|
| 1 | Windows JAVA_HOME을 C : \ ProgramFiles \ java \ jdk1.7.0_60으로 설정합니다. | 
| 2 | Linux JAVA_HOME = / usr / local / java-current 내보내기 | 
Java 컴파일러 위치의 전체 경로를 시스템 경로에 추가하십시오.
| S. 아니. | 플랫폼 및 설명 | 
|---|---|
| 1 | Windows 시스템 변수 PATH의 끝에 문자열 "C : \ Program Files \ Java \ jdk1.7.0_60 \ bin"을 추가합니다. | 
| 2 | Linux 내보내기 PATH = $ PATH : $ JAVA_HOME / bin / | 
명령 실행 java -version 위에서 설명한대로 명령 프롬프트에서.
3 단계 : Maven 아카이브 다운로드
Maven 3.3.3 다운로드 https://maven.apache.org/download.cgi
| OS | 아카이브 이름 | 
|---|---|
| 윈도우 | apache-maven-3.3.3-bin.zip | 
| 리눅스 | apache-maven-3.3.3-bin.tar.gz | 
| 맥 | apache-maven-3.3.3-bin.tar.gz | 
4 단계 : Maven 아카이브 추출
Maven 3.3.3을 설치하려는 디렉토리에 아카이브를 추출하십시오. 아카이브에서 하위 디렉토리 apache-maven-3.3.3이 생성됩니다.
| OS | 위치 (설치에 따라 다를 수 있음) | 
|---|---|
| 윈도우 | C : \ Program Files \ Apache Software Foundation \ apache-maven-3.3.3 | 
| 리눅스 | / usr / local / apache-maven | 
| 맥 | / usr / local / apache-maven | 
5 단계 : Maven 환경 변수 설정
M2_HOME, M2 및 MAVEN_OPTS를 환경 변수에 추가하십시오.
| OS | 산출 | 
|---|---|
| 윈도우 | 시스템 속성을 사용하여 환경 변수를 설정합니다. M2_HOME = C : \ Program Files \ Apache Software Foundation \ apache-maven-3.3.3 M2 = % M2_HOME % \ bin MAVEN_OPTS = -Xms256m -Xmx512m | 
| 리눅스 | 명령 터미널을 열고 환경 변수를 설정합니다. export M2_HOME = / usr / local / apache-maven / apache-maven-3.3.3 내보내기 M2 = $ M2_HOME / bin 내보내기 MAVEN_OPTS = -Xms256m -Xmx512m | 
| 맥 | 명령 터미널을 열고 환경 변수를 설정합니다. export M2_HOME = / usr / local / apache-maven / apache-maven-3.3.3 내보내기 M2 = $ M2_HOME / bin 내보내기 MAVEN_OPTS = -Xms256m -Xmx512m | 
6 단계 : 시스템 경로에 Maven bin 디렉터리 위치 추가
이제 M2 변수를 시스템 경로에 추가하십시오.
| OS | 산출 | 
|---|---|
| 윈도우 | 시스템 변수 Path의 끝에 문자열; % M2 %를 추가합니다. | 
| 리눅스 | 내보내기 PATH = $ M2 : $ PATH | 
| 맥 | 내보내기 PATH = $ M2 : $ PATH | 
7 단계 : Maven 설치 확인
이제 콘솔을 열고 다음을 실행하십시오. mvn 명령.
| OS | 직무 | 명령 | 
|---|---|---|
| 윈도우 | 명령 콘솔 열기 | c : \> mvn-버전 | 
| 리눅스 | 명령 터미널 열기 | $ mvn-버전 | 
| 맥 | 터미널 열기 | 기계 : <joseph $ mvn --version | 
마지막으로, 위 명령의 출력을 확인하십시오. 아래에 표시된 것과 같아야합니다.
| OS | 산출 | 
|---|---|
| 윈도우 | Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17 : 27 : 37 + 05 : 30) Maven 홈 : C : \ Program Files \ Apache Software Foundation \ apache-maven-3.3.3 Java 버전 : 1.7.0_75, 공급 업체 : Oracle Corporation 자바 홈 : C : \ Program Files \ Java \ jdk1.7.0_75 \ jre 기본 로케일 : en_US, 플랫폼 인코딩 : Cp1252 | 
| 리눅스 | Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17 : 27 : 37 + 05 : 30) Maven 홈 : /usr/local/apache-maven/apache-maven-3.3.3 Java 버전 : 1.7.0_75, 공급 업체 : Oracle Corporation 자바 홈 : /usr/local/java-current/jdk1.7.0_75/jre | 
| 맥 | Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17 : 27 : 37 + 05 : 30) Maven 홈 : /usr/local/apache-maven/apache-maven-3.3.3 Java 버전 : 1.7.0_75, 공급 업체 : Oracle Corporation 자바 홈 : /Library/Java/Home/jdk1.7.0_75/jre | 
8 단계 : Eclipse IDE 설정
이 튜토리얼의 모든 예제는 Eclipse IDE를 사용하여 작성되었습니다. 독자는 컴퓨터에 최신 버전의 Eclipse를 설치하는 것이 좋습니다. Eclipse IDE를 설치하려면 다음 링크에서 최신 Eclipse 바이너리를 다운로드하십시오.https://www.eclipse.org/downloads/. 설치가 다운로드되면 편리한 위치에 바이너리 배포판의 압축을 풉니 다.
예를 들어 C:\eclipse 창문에서, 또는 /usr/local/eclipseLinux / Unix에서 마지막으로 PATH 변수를 적절하게 설정하십시오. Windows 컴퓨터에서 다음 명령을 실행하여 Eclipse를 시작하거나 eclipse.exe를 두 번 클릭하면됩니다.
%C:\eclipse\eclipse.exeEclipse는 UNIX (Solaris, Linux 등) 시스템에서 다음 명령을 실행하여 시작할 수 있습니다.
$/usr/local/eclipse/eclipse성공적으로 시작한 후 모든 것이 정상이면 다음 화면이 표시됩니다.
 
                9 단계 : Apache Tomcat 설정
최신 버전의 Tomcat을 다음에서 다운로드 할 수 있습니다. https://tomcat.apache.org/. 설치가 다운로드되면 편리한 위치에 바이너리 배포판의 압축을 풉니 다. 예를 들어C:\apache-tomcat-7.0.59 Windows 시스템 또는 /usr/local/apache-tomcat-7.0.59 Linux / Unix 시스템에서 CATALINA_HOME 설치 위치를 가리키는 환경 변수.
Windows 시스템에서 다음 명령을 실행하여 Tomcat을 시작하거나 startup.bat를 두 번 클릭하기 만하면됩니다.
%CATALINA_HOME%\bin\startup.bat
 
or
 
C:\apache-tomcat-7.0.59\bin\startup.batTomcat은 UNIX (Solaris, Linux 등) 시스템에서 다음 명령을 실행하여 시작할 수 있습니다.
$CATALINA_HOME/bin/startup.sh
 
or
 
/usr/local/apache-tomcat-7.0.59/bin/startup.sh성공적으로 시작한 후 Tomcat에 포함 된 기본 웹 응용 프로그램은 다음을 방문하여 사용할 수 있습니다. http://localhost:8080/. 모든 것이 정상이면 다음 화면이 표시됩니다.
 
                Tomcat 구성 및 실행에 대한 추가 정보는 여기에 포함 된 문서와 Tomcat 웹 사이트에서 찾을 수 있습니다. https://tomcat.apache.org
Windows 시스템에서 다음 명령을 실행하여 Tomcat을 중지 할 수 있습니다.
%CATALINA_HOME%\bin\shutdown
or
C:\apache-tomcat-7.0.59\bin\shutdownUNIX (Solaris, Linux 등) 시스템에서 다음 명령을 실행하여 Tomcat을 중지 할 수 있습니다.
$CATALINA_HOME/bin/shutdown.sh
or
/usr/local/apache-tomcat-7.0.59/bin/shutdown.sh이 마지막 단계를 마치면 다음 장에서 논의 할 첫 번째 웹 서비스 예제를 진행할 준비가 된 것입니다.
Spring-WS Framework를 사용하여 실제 SOAP 기반 웹 서비스 작성을 시작하겠습니다. Spring-WS 프레임 워크를 사용하여 첫 번째 예제를 작성하기 전에 Spring Web Services-Environment Setup 장 에서 설명한대로 Spring-WS 환경이 올바르게 설정되었는지 확인해야합니다 . 독자가 Eclipse IDE에 대한 기본적인 작업 지식이 있다고 가정합니다.
따라서 HR 포털에서 휴가를 예약하기위한 웹 서비스 방법을 노출하는 간단한 Spring WS 애플리케이션을 작성해 보겠습니다.
계약 우선 접근법
Spring-WS는 계약 우선 접근 방식을 사용하므로 XML StructuresJAVA 기반 구현 코드를 작성하기 전에 준비하십시오. 우리는 Leave와 Employee라는 하위 개체가있는 LeaveRequest 개체를 정의하고 있습니다.
다음은 필요한 XML 구조입니다-
Leave.xml
<Leave xmlns = "http://tutorialspoint.com/hr/schemas">
   <StartDate>2016-07-03</StartDate>
   <EndDate>2016-07-07</EndDate>
</Leave>Employee.xml
<Employee xmlns = "http://tutorialspoint.com/hr/schemas">
   <Number>404</Number>
   <FirstName>Mahesh</FirstName>
   <LastName>Parashar</LastName>
</Employee>LeaveRequest.xml
<LeaveRequest xmlns = "http://tutorialspoint.com/hr/schemas">
   <Leave>
      <StartDate>2016-07-03</StartDate>
      <EndDate>2016-07-07</EndDate>
   </Leave>
   
   <Employee>
      <Number>404</Number>
      <FirstName>Mahesh</FirstName>
      <LastName>Parashar</LastName>
   </Employee>
</LeaveRequest>hr.xsd
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
   xmlns:hr = "http://tutorialspoint.com/hr/schemas"
   elementFormDefault = "qualified"
   targetNamespace = "http://tutorialspoint.com/hr/schemas">
   
   <xs:element name = "LeaveRequest">
      <xs:complexType>
         <xs:all>
            <xs:element name = "Leave" type = "hr:LeaveType"/>
            <xs:element name = "Employee" type = "hr:EmployeeType"/>
         </xs:all>
      </xs:complexType>
   </xs:element>
   
   <xs:complexType name = "LeaveType">
      <xs:sequence>
         <xs:element name = "StartDate" type = "xs:date"/>
         <xs:element name = "EndDate" type = "xs:date"/>
      </xs:sequence>
   </xs:complexType>
   
   <xs:complexType name = "EmployeeType">
      <xs:sequence>
         <xs:element name = "Number" type = "xs:integer"/>
         <xs:element name = "FirstName" type = "xs:string"/>
         <xs:element name = "LastName" type = "xs:string"/>
      </xs:sequence>
   </xs:complexType>
</xs:schema>프로젝트 생성
이제 명령 콘솔을 열고 C : \ MVN 디렉터리로 이동하여 다음을 실행하겠습니다. mvn 명령.
C:\MVN>mvn archetype:generate -DarchetypeGroupId = org.springframework.ws
-DarchetypeArtifactId = spring-ws-archetype -DgroupId = com.tutorialspoint.hr
-DartifactId = leaveServiceMaven이 처리를 시작하고 완전한 Java 애플리케이션 프로젝트 구조를 생성합니다.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] Using property: groupId = com.tutorialspoint.hr
[INFO] Using property: artifactId = leaveService
Define value for property 'version':  1.0-SNAPSHOT: :
[INFO] Using property: package = com.tutorialspoint.hr
Confirm properties configuration:
groupId: com.tutorialspoint.hr
artifactId: leaveService
version: 1.0-SNAPSHOT
package: com.tutorialspoint.hr
 Y: :
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating project from Old (1.x) Archetype:
 spring-ws-archetype:2.0.0-M1
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: groupId, Value: com.tutorialspoint.hr
[INFO] Parameter: packageName, Value: com.tutorialspoint.hr
[INFO] Parameter: package, Value: com.tutorialspoint.hr
[INFO] Parameter: artifactId, Value: leaveService
[INFO] Parameter: basedir, Value: C:\mvn
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\mvn\leaveService
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.989 s
[INFO] Finished at: 2017-01-21T11:18:31+05:30
[INFO] Final Memory: 17M/178M
[INFO] ------------------------------------------------------------------------이제 이동 C:/MVN예배 규칙서. 이름이 지정된 Java 애플리케이션 프로젝트가 표시됩니다.leaveService(artifactId에 지정된대로). pom.xml을 업데이트하고 C : \ MVN \ leaveService \ src \ main \ java \ com \ tutorialspoint \ hr \ service 폴더에 HumanResourceService.java 및 HumanResourceServiceImpl.java를 추가합니다. 완료되면 C : \ MVN \ leaveService \ src \ main \ java \ com \ tutorialspoint \ hr \ ws 폴더에 LeaveEndpoint.java를 추가합니다.
pom.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/maven-v4_0_0.xsd">
   
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.tutorialspoint.hr</groupId>
   <artifactId>leaveService</artifactId>
   <packaging>war</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>leaveService Spring-WS Application</name>
   <url>http://www.springframework.org/spring-ws</url>
   
   <build>
      <finalName>leaveService</finalName>
   </build>
   
   <dependencies>
      <dependency>
         <groupId>org.springframework.ws</groupId>
         <artifactId>spring-ws-core</artifactId>
         <version>2.4.0.RELEASE</version>
      </dependency>
      
      <dependency>
         <groupId>jdom</groupId>
         <artifactId>jdom</artifactId>
         <version>1.0</version>
      </dependency>
      
      <dependency>
         <groupId>jaxen</groupId>
         <artifactId>jaxen</artifactId>
         <version>1.1</version>
      </dependency>
      
      <dependency>
         <groupId>wsdl4j</groupId>
         <artifactId>wsdl4j</artifactId>
         <version>1.6.2</version>
      </dependency>
   </dependencies>
</project>HumanResourceService.java
package com.tutorialspoint.hr.service;
import java.util.Date;
public interface HumanResourceService {
   void bookLeave(Date startDate, Date endDate, String name);
}HumanResourceServiceImpl.java
package com.tutorialspoint.hr.service;
import java.util.Date;
import org.springframework.stereotype.Service;
@Service
public class HumanResourceServiceImpl implements HumanResourceService {
   public void bookLeave(Date startDate, Date endDate, String name) {
      System.out.println("Booking holiday for [" + startDate + "-" + endDate + "]
         for [" + name + "] ");
   }
}LeaveEndpoint.java
package com.tutorialspoint.hr.ws;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import com.tutorialspoint.hr.service.HumanResourceService;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
@Endpoint
public class LeaveEndpoint {
   private static final String NAMESPACE_URI = "http://tutorialspoint.com/hr/schemas";
   private XPath startDateExpression;
   private XPath endDateExpression;
   private XPath nameExpression;
   private HumanResourceService humanResourceService;
   @Autowired
   public LeaveEndpoint(HumanResourceService humanResourceService) throws JDOMException {
      this.humanResourceService = humanResourceService;
      Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
      startDateExpression = XPath.newInstance("//hr:StartDate");
      startDateExpression.addNamespace(namespace);
      endDateExpression = XPath.newInstance("//hr:EndDate");
      endDateExpression.addNamespace(namespace);
      nameExpression = XPath.newInstance("concat(//hr:FirstName,' ',//hr:LastName)");
      nameExpression.addNamespace(namespace);
   }
   @PayloadRoot(namespace = NAMESPACE_URI, localPart = "LeaveRequest")                  
   public void handleLeaveRequest(@RequestPayload Element leaveRequest) throws Exception {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      Date startDate = dateFormat.parse(startDateExpression.valueOf(leaveRequest));
      Date endDate = dateFormat.parse(endDateExpression.valueOf(leaveRequest));
      String name = nameExpression.valueOf(leaveRequest);
      humanResourceService.bookLeave(startDate, endDate, name);
   }
}/WEB-INF/spring-ws-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context = "http://www.springframework.org/schema/context"
   xmlns:sws = "http://www.springframework.org/schema/web-services"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services
   http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
   <context:component-scan base-package = "com.tutorialspoint.hr"/>
   <bean id = "humanResourceService"
      class = "com.tutorialspoint.hr.service.HumanResourceServiceImpl" />
   <sws:annotation-driven/>
   <sws:dynamic-wsdl id = "leave"
      portTypeName = "HumanResource"
      locationUri = "/leaveService/"
      targetNamespace = "http://tutorialspoint.com/hr/definitions">
      <sws:xsd location = "/WEB-INF/hr.xsd"/>
   </sws:dynamic-wsdl>
</beans>/WEB-INF/web.xml
<web-app xmlns = "http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version = "2.4">
   <display-name>TutorialsPoint HR Leave Service</display-name>
   <servlet>
      <servlet-name>spring-ws</servlet-name>
      <servlet-class>
         org.springframework.ws.transport.http.MessageDispatcherServlet
      </servlet-class>
      <init-param>
         <param-name>transformWsdlLocations</param-name>
         <param-value>true</param-value>
      </init-param>
   </servlet>
   <servlet-mapping>
      <servlet-name>spring-ws</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>
</web-app>/WEB-INF/hr.xsd
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema"
   xmlns:hr = "http://tutorialspoint.com/hr/schemas"
   elementFormDefault = "qualified"
   targetNamespace = "http://tutorialspoint.com/hr/schemas">
   <xs:element name = "LeaveRequest">
      <xs:complexType>
         <xs:all>
            <xs:element name = "Leave" type = "hr:LeaveType"/>
            <xs:element name = "Employee" type = "hr:EmployeeType"/>
         </xs:all>
      </xs:complexType>
   </xs:element>
   <xs:complexType name = "LeaveType">
      <xs:sequence>
         <xs:element name = "StartDate" type = "xs:date"/>
         <xs:element name = "EndDate" type = "xs:date"/>
      </xs:sequence>
   </xs:complexType>
   <xs:complexType name = "EmployeeType">
      <xs:sequence>
         <xs:element name = "Number" type = "xs:integer"/>
         <xs:element name = "FirstName" type = "xs:string"/>
         <xs:element name = "LastName" type = "xs:string"/>
      </xs:sequence>
   </xs:complexType>
</xs:schema>프로젝트 구축
이제 명령 콘솔을 열고 C : \ MVN \ leaveService 디렉터리로 이동하여 다음을 실행하겠습니다. mvn 명령.
C:\MVN\leaveService>mvn clean packageMaven이 프로젝트 빌드를 시작합니다.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building leaveService Spring-WS Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ leaveService ---
[INFO] Deleting C:\mvn\leaveService\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ leaveServi
ce ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ leaveService --
-
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 3 source files to C:\mvn\leaveService\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ le
aveService ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\mvn\leaveService\src\test\resource
s
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ leaveSe
rvice ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ leaveService ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ leaveService ---
[INFO] Packaging webapp
[INFO] Assembling webapp [leaveService] in [C:\mvn\leaveService\target\leaveServ
ice]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\mvn\leaveService\src\main\webapp]
[INFO] Webapp assembled in [7159 msecs]
[INFO] Building war: C:\mvn\leaveService\target\leaveService.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.667 s
[INFO] Finished at: 2017-01-21T11:56:43+05:30
[INFO] Final Memory: 18M/173M
[INFO] ------------------------------------------------------------------------Eclipse에서 프로젝트 가져 오기
Eclipse에서 프로젝트를 가져 오려면 아래 단계를 따르십시오.
- Eclipse를 엽니 다. 
- 고르다 File → Import → 선택권. 
- Maven 프로젝트 옵션을 선택합니다. 다음 버튼을 클릭하십시오. 
- 프로젝트 위치를 선택하십시오. leaveService project Maven을 사용하여 생성되었습니다. 
- 마침 버튼을 클릭합니다. 
프로젝트 실행
소스 및 구성 파일 생성이 완료되면 애플리케이션을 내 보냅니다. 애플리케이션을 마우스 오른쪽 버튼으로 클릭하고 내보내기 → WAR 파일 옵션을 사용하고 Tomcat의 webapps 폴더에 leaveService.war 파일을 저장합니다.
Tomcat 서버를 시작하고 표준 브라우저를 사용하여 webapps 폴더에서 다른 웹 페이지에 액세스 할 수 있는지 확인하십시오. http : // localhost : 8080 / leaveService / leave.wsdl URL에 액세스 해보십시오. Spring Web Application에 문제가 없으면 다음 화면이 표시됩니다.
 
                이전 장 Spring -WS-First Application 에서는 Spring WS Configuration을 사용하여 WSDL을 자동으로 생성했습니다. 이 경우 Spring WS를 사용하여 기존 WSDL을 노출하는 방법을 표시합니다.
| 단계 | 기술 | 
|---|---|
| 1 | Spring WS-First Application 장에 설명 된대로 com.tutorialspoint 패키지 아래에 이름이 leaveService 인 프로젝트를 만듭니다. | 
| 2 | / WEB-INF / wsdl 하위 폴더 아래에 WSDL leave.wsdl을 생성합니다. | 
| 삼 | / WEB-INF 하위 폴더에서 spring-ws-servlet.xml을 업데이트합니다. 여기서는 dynamic-wsdl 대신 static-wsdl 태그를 사용하고 있습니다. | 
| 4 | 마지막 단계는 모든 소스 및 구성 파일의 내용을 만들고 아래 설명 된대로 응용 프로그램을 내보내는 것입니다. | 
/WEB-INF/spring-ws-servlet.xml
<wsdl:definitions xmlns:wsdl = "http://schemas.xmlsoap.org/wsdl/"
   xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:schema = "http://tutorialspoint.com/hr/schemas"
   xmlns:tns = "http://tutorialspoint.com/hr/definitions"
   targetNamespace = "http://tutorialspoint.com/hr/definitions">
   
   <wsdl:types>
      <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
         <xsd:import namespace = "http://tutorialspoint.com/hr/schemas"
            schemaLocation = "hr.xsd"/>
      </xsd:schema>
   </wsdl:types>
   
   <wsdl:message name = "LeaveRequest">
      <wsdl:part element = "schema:LeaveRequest" name = "LeaveRequest"/>
   </wsdl:message>
   
   <wsdl:portType name = "HumanResource">
      <wsdl:operation name = "Leave">
         <wsdl:input message = "tns:LeaveRequest" name = "LeaveRequest"/>
      </wsdl:operation>
   </wsdl:portType>
   
   <wsdl:binding name = "HumanResourceBinding" type = "tns:HumanResource">
      <soap:binding style = "document"
         transport = "http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name = "Leave">
         <soap:operation soapAction = "http://mycompany.com/RequestLeave"/>
         <wsdl:input name = "LeaveRequest">
            <soap:body use = "literal"/>
         </wsdl:input>
      </wsdl:operation>
   </wsdl:binding>
   
   <wsdl:service name = "HumanResourceService">
      <wsdl:port binding = "tns:HumanResourceBinding" name = "HumanResourcePort">
         <soap:address location = "http://localhost:8080/leaveService/"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>/WEB-INF/spring-ws-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context = "http://www.springframework.org/schema/context"
   xmlns:sws = "http://www.springframework.org/schema/web-services"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services
   http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
   <context:component-scan base-package = "com.tutorialspoint.hr"/>
   <sws:annotation-driven/>
   <sws:static-wsdl id = "leave" location = "/WEB-INF/wsdl/leave.wsdl"/>
</beans>프로젝트 실행
소스 및 구성 파일 생성이 끝나면 애플리케이션을 내 보내야합니다. 응용 프로그램을 마우스 오른쪽 버튼으로 클릭하고 내보내기 → WAR 파일 옵션을 사용하고 Tomcat의 webapps 폴더에 leaveService.war 파일을 저장하십시오.
이제 Tomcat 서버를 시작하고 표준 브라우저를 사용하여 webapps 폴더에서 다른 웹 페이지에 액세스 할 수 있는지 확인하십시오. http : // localhost : 8080 / leaveService / leave.wsdl URL에 액세스 해보십시오. Spring Web Application에서 모든 것이 정상이면 다음 화면이 표시됩니다.
 
                이 장에서는 Spring WS를 사용하여 웹 애플리케이션 서버를 만드는 방법을 이해합니다.
| 단계 | 기술 | 
|---|---|
| 1 | Spring WS-First Application 장에 설명 된대로 com.tutorialspoint 패키지 아래에 countryService라는 이름의 프로젝트를 작성하십시오. | 
| 2 | 다음 단계에 설명 된대로 countries.xsd, 도메인 클래스, CountryRepository 및 CountryEndPoint를 작성하십시오. | 
| 삼 | / WEB-INF 하위 폴더에서 spring-ws-servlet.xml을 업데이트합니다. | 
| 4 | 마지막 단계는 모든 소스 및 구성 파일에 대한 내용을 만들고 아래 설명 된대로 응용 프로그램을 내보내는 것입니다. | 
countries.xsd
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema" 
   xmlns:tns = "http://tutorialspoint/schemas"
   targetNamespace = "http://tutorialspoint/schemas" 
   elementFormDefault = "qualified">
   <xs:element name = "getCountryRequest">
      <xs:complexType>
         <xs:sequence>
            <xs:element name = "name" type = "xs:string"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:element name = "getCountryResponse">
      <xs:complexType>
         <xs:sequence>
            <xs:element name = "country" type = "tns:country"/>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   <xs:complexType name = "country">
      <xs:sequence>
         <xs:element name = "name" type = "xs:string"/>
         <xs:element name = "population" type = "xs:int"/>
         <xs:element name = "capital" type = "xs:string"/>
         <xs:element name = "currency" type = "tns:currency"/>
      </xs:sequence>
   </xs:complexType>
   <xs:simpleType name = "currency">
      <xs:restriction base = "xs:string">
         <xs:enumeration value = "GBP"/>
         <xs:enumeration value = "USD"/>
         <xs:enumeration value = "INR"/>
      </xs:restriction>
   </xs:simpleType>
</xs:schema>프로젝트 생성
명령 콘솔을 열고 C : \ MVN 디렉토리로 이동하여 다음을 실행하겠습니다. mvn 명령.
C:\MVN>mvn archetype:generate -DarchetypeGroupId = org.springframework.ws 
-DarchetypeArtifactId = spring-ws-archetype -DgroupId = com.tutorialspoint 
-DartifactId = countryServiceMaven이 처리를 시작하고 완전한 Java 애플리케이션 프로젝트 구조를 생성합니다.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] Using property: groupId = com.tutorialspoint
[INFO] Using property: artifactId = countryService
Define value for property 'version':  1.0-SNAPSHOT: :
[INFO] Using property: package = com.tutorialspoint
Confirm properties configuration:
groupId: com.tutorialspoint
artifactId: countryService
version: 1.0-SNAPSHOT
package: com.tutorialspoint
 Y: :
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating project from Old (1.x) Archetype:
 spring-ws-archetype:2.0.0-M1
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: groupId, Value: com.tutorialspoint
[INFO] Parameter: packageName, Value: com.tutorialspoint
[INFO] Parameter: package, Value: com.tutorialspoint
[INFO] Parameter: artifactId, Value: countryService
[INFO] Parameter: basedir, Value: C:\mvn
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] project created from Old (1.x) Archetype in dir: C:\mvn\countryService
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.989 s
[INFO] Finished at: 2017-01-21T11:18:31+05:30
[INFO] Final Memory: 17M/178M
[INFO] ------------------------------------------------------------------------이제 C : / MVN 디렉토리로 이동합니다. countryService (artifactId에 지정된대로)라는 이름으로 작성된 Java 애플리케이션 프로젝트가 표시됩니다. pom.xml을 업데이트하십시오.
pom.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/maven-v4_0_0.xsd">
   
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.tutorialspoint.hr</groupId>
   <artifactId>countryService</artifactId>
   <packaging>war</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>countryService Spring-WS Application</name>
   <url>http://www.springframework.org/spring-ws</url>
   
   <build>
      <finalName>countryService</finalName>
   </build>
   
   <dependencies>
      <dependency>
         <groupId>org.springframework.ws</groupId>
         <artifactId>spring-ws-core</artifactId>
         <version>2.4.0.RELEASE</version>
      </dependency>
      
      <dependency>
         <groupId>jdom</groupId>
         <artifactId>jdom</artifactId>
         <version>1.0</version>
      </dependency>
      
      <dependency>
         <groupId>jaxen</groupId>
         <artifactId>jaxen</artifactId>
         <version>1.1</version>
      </dependency>
      
      <dependency>
         <groupId>wsdl4j</groupId>
         <artifactId>wsdl4j</artifactId>
         <version>1.6.2</version>
      </dependency>
   </dependencies>
</project>도메인 클래스 생성
C : \ mvn \ countryService \ src \ main \ resources 폴더에있는 countries.xsd를 복사하십시오. 명령 콘솔을 열고 C : \ mvn \ countryService \ src \ main \ resources 디렉터리로 이동하여 다음을 실행하겠습니다.xjc countries.xsd를 사용하여 도메인 클래스를 생성하는 명령.
C:\MVN\countryService\src\main\resources>xjc -p com.tutorialspoint countries.xsdMaven은 처리를 시작하고 com.tutorialspoint 패키지에 도메인 클래스를 만듭니다.
parsing a schema...
compiling a schema...
com\tutorialspoint\Country.java
com\tutorialspoint\Currency.java
com\tutorialspoint\GetCountryRequest.java
com\tutorialspoint\GetCountryResponse.java
com\tutorialspoint\ObjectFactory.java
com\tutorialspoint\package-info.javaC : \ mvn \ countryService \ src \ main 폴더에 java 폴더를 만듭니다. C : \ mvn \ countryService \ src \ main \ java 폴더의 모든 클래스를 복사합니다. 국가 데이터베이스와 국가 서버를 각각 나타내는 CountryRepository 및 CountryEndPoint를 만듭니다.
CountryRepository.java
package com.tutorialspoint;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.propertyeditors.CurrencyEditor;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@Component
public class CountryRepository {
   private static final List<Country> countries = new ArrayList<Country>();
   public CountryRepository(){
      initData();
   }
   public void initData() {
      Country us = new Country();
      us.setName("United States");
      us.setCapital("Washington");
      us.setCurrency(Currency.USD);
      us.setPopulation(46704314);
   
      countries.add(us);
   
      Country india = new Country();
      india.setName("India");
      india.setCapital("New Delhi");
      india.setCurrency(Currency.INR);
      india.setPopulation(138186860);
      countries.add(india);
    
      Country uk = new Country();
      uk.setName("United Kingdom");
      uk.setCapital("London");
      uk.setCurrency(Currency.GBP);
      uk.setPopulation(63705000);
   
      countries.add(uk);
   }
   public Country findCountry(String name) {
      Assert.notNull(name);
      Country result = null;
      for (Country country : countries) {
         if (name.trim().equals(country.getName())) {
            result = country;
         }
      }
      return result;
   }
}CountryEndPoint.java
package com.tutorialspoint.ws;
import org.jdom.JDOMException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import com.tutorialspoint.Country;
import com.tutorialspoint.CountryRepository;
import com.tutorialspoint.GetCountryRequest;
import com.tutorialspoint.GetCountryResponse;
@Endpoint
public class CountryEndPoint {
   private static final String NAMESPACE_URI = "http://tutorialspoint/schemas";
   private CountryRepository countryRepository;
   @Autowired
   public CountryEndPoint(CountryRepository countryRepository) throws JDOMException {
      this.countryRepository = countryRepository;
   }
   @PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCountryRequest")
   @ResponsePayload
   public GetCountryResponse getCountry(@RequestPayload GetCountryRequest request) 
      throws JDOMException {
      
      Country country = countryRepository.findCountry(request.getName());
      GetCountryResponse response = new GetCountryResponse();
      response.setCountry(country);
      return response;
   }
}/WEB-INF/spring-ws-servlet.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context = "http://www.springframework.org/schema/context"
   xmlns:sws = "http://www.springframework.org/schema/web-services"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services
   http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
   <context:component-scan base-package = "com.tutorialspoint"/>
   <sws:annotation-driven/>
   <sws:dynamic-wsdl id="countries"
      portTypeName = "CountriesPort"
      locationUri = "/countryService/"
      targetNamespace = "http://tutorialspoint.com/definitions">
      <sws:xsd location = "/WEB-INF/countries.xsd"/>
   </sws:dynamic-wsdl>
</beans>/WEB-INF/web.xml
<web-app xmlns = "http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version = "2.4">
   <display-name>TutorialsPoint Country Service</display-name>
   <servlet>
      <servlet-name>spring-ws</servlet-name>
      <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet
      </servlet-class>
      <init-param>
         <param-name>transformWsdlLocations</param-name>
         <param-value>true</param-value>
      </init-param>
   </servlet>
   
   <servlet-mapping>
      <servlet-name>spring-ws</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>
</web-app>프로젝트 구축
명령 콘솔을 열어 보겠습니다. C : \ MVN \ countryService 디렉터리로 이동하여 다음을 실행합니다.mvn 명령.
C:\MVN\countryService>mvn clean packageMaven이 프로젝트 빌드를 시작합니다.
INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building countryService Spring-WS Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ countryService ---
[INFO] Deleting C:\mvn\countryService\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ countrySer
vice ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ countryService
---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. 
build is platform dependent!
[INFO] Compiling 4 source files to C:\mvn\countryService\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ co
untryService ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\mvn\countryService\src\test\resour
ces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ country
Service ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ countryService ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ countryService ---
[INFO] Packaging webapp
[INFO] Assembling webapp [countryService] in [C:\mvn\countryService\target\count
ryService]
[INFO] Processing war project
[INFO] Copying webapp resources [C:\mvn\countryService\src\main\webapp]
[INFO] Webapp assembled in [5137 msecs]
[INFO] Building war: C:\mvn\countryService\target\countryService.war
[INFO] WEB-INF\web.xml already added, skipping
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.484 s
[INFO] Finished at: 2017-01-28T09:07:59+05:30
[INFO] Final Memory: 19M/170M
[INFO] ------------------------------------------------------------------------프로젝트 실행
소스 및 구성 파일을 생성했으면 Tomcat의 webapps 폴더에 countryService.war 파일을 내 보냅니다.
이제 Tomcat 서버를 시작하고 표준 브라우저를 사용하여 webapps 폴더에서 다른 웹 페이지에 액세스 할 수 있는지 확인하십시오. URL (http : // localhost : 8080 / countryService /)에 대한 POST 요청을 만들고 SOAP 클라이언트를 사용하여 다음 요청을 수행합니다.
<x:Envelope xmlns:x = "http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:tns = "http://tutorialspoint/schemas">
   <x:Header/>
   <x:Body>
      <tns:getCountryRequest>
         <tns:name>United States</tns:name>
      </tns:getCountryRequest>
   </x:Body>
</x:Envelope>다음 결과가 표시됩니다.
<SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Header/>
   <SOAP-ENV:Body>
      <ns2:getCountryResponse xmlns:ns2 = "http://tutorialspoint/schemas">
         <ns2:country>
            <ns2:name>United States</ns2:name>
            <ns2:population>46704314</ns2:population>
            <ns2:capital>Washington</ns2:capital>
            <ns2:currency>USD</ns2:currency>
         </ns2:country>
      </ns2:getCountryResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>이 장에서는 Spring WS를 사용하여 생성 된 웹 애플리케이션 서비스를 단위 테스트하는 방법을 이해한다.
| 단계 | 기술 | 
|---|---|
| 1 | Spring WS – Write Server 장에서 만든 프로젝트 countryService를 업데이트합니다. src / test / java 폴더를 추가합니다. | 
| 2 | – src / test / java / com / tutorialspoint / ws 폴더 아래에 CustomerEndPointTest.java를 만든 다음 아래 설명 된대로 POM.xml을 업데이트합니다. | 
| 삼 | src / main / resources 하위 폴더 아래에 spring-context.xml을 추가하십시오. | 
| 4 | 마지막 단계는 모든 소스 및 구성 파일에 대한 내용을 만들고 아래 설명 된대로 응용 프로그램을 테스트하는 것입니다. | 
POM.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<project xmlns = "http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 
   http://maven.apache.org/maven-v4_0_0.xsd">
   
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.tutorialspoint</groupId>
   <artifactId>countryService</artifactId>
   <packaging>war</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>countryService Spring-WS Application</name>
   <url>http://www.springframework.org/spring-ws</url>
   <build>
      <finalName>countryService</finalName>
   </build>
   
   <dependencies>
      <dependency>
         <groupId>org.springframework.ws</groupId>
         <artifactId>spring-ws-core</artifactId>
         <version>2.4.0.RELEASE</version>
      </dependency>
      
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-test</artifactId>
         <version>2.5</version>
      </dependency>
      
      <dependency>
         <groupId>org.springframework.ws</groupId>
         <artifactId>spring-ws-test</artifactId>
         <version>2.4.0.RELEASE</version>
      </dependency>
      
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-tx</artifactId>
         <version>3.1.2.RELEASE</version>
      </dependency>
      
      <dependency>
         <groupId>jdom</groupId>
         <artifactId>jdom</artifactId>
         <version>1.0</version>
      </dependency>
      
      <dependency>
         <groupId>jaxen</groupId>
         <artifactId>jaxen</artifactId>
         <version>1.1</version>
      </dependency>
      
      <dependency>
         <groupId>wsdl4j</groupId>
         <artifactId>wsdl4j</artifactId>
         <version>1.6.2</version>
      </dependency>
      
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>4.5</version>
         <scope>test</scope>
      </dependency>
   </dependencies>
</project>spring-context.xml
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context = "http://www.springframework.org/schema/context"
   xmlns:sws = "http://www.springframework.org/schema/web-services"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://www.springframework.org/schema/web-services
   http://www.springframework.org/schema/web-services/web-services-2.0.xsd
   http://www.springframework.org/schema/context 
   http://www.springframework.org/schema/context/spring-context-3.0.xsd">
   <context:component-scan base-package = "com.tutorialspoint"/>
   <sws:annotation-driven/>
   <bean id = "schema" class = "org.springframework.core.io.ClassPathResource">
      <constructor-arg index = "0" value = "countries.xsd" />
   </bean>
</beans>CustomerEndPointTest.java
package com.tutorialspoint.ws;
import javax.xml.transform.Source;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.test.server.MockWebServiceClient;
import org.springframework.xml.transform.StringSource;
import static org.springframework.ws.test.server.RequestCreators.withPayload;
import static org.springframework.ws.test.server.ResponseMatchers.payload;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration( locations = "/spring-context.xml" )
public class CustomerEndPointTest {
   @Autowired
   private ApplicationContext applicationContext;
   private MockWebServiceClient mockClient;
   @Before
   public void createClient() {
      mockClient = MockWebServiceClient.createClient(applicationContext);
      GenericApplicationContext ctx = (GenericApplicationContext) applicationContext;
      final XmlBeanDefinitionReader definitionReader = new XmlBeanDefinitionReader(ctx);
      definitionReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
      definitionReader.setNamespaceAware(true);
   }
   @Test
   public void testCountryEndpoint() throws Exception {
      Source requestPayload = new StringSource(
         "<getCountryRequest xmlns = 'http://tutorialspoint/schemas'>"+
         "<name>United States</name>"+
         "</getCountryRequest>");				
      Source responsePayload = new StringSource(
         "<getCountryResponse xmlns='http://tutorialspoint/schemas'>" +
         "<country>" +
         "<name>United States</name>"+
         "<population>46704314</population>"+
         "<capital>Washington</capital>"+
         "<currency>USD</currency>"+
         "</country>"+
         "</getCountryResponse>");
      mockClient.sendRequest(withPayload(requestPayload)).andExpect(payload(responsePayload));
   }	
}프로젝트 구축
명령 콘솔을 열고 C : \ MVN \ countryService 디렉토리로 이동하여 다음 mvn 명령을 실행하겠습니다.
C:\MVN\countryService>mvn testMaven이 프로젝트 빌드 및 테스트를 시작합니다.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building countryService Spring-WS Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ countrySer
vice ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ countryService
---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ co
untryService ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\countryService\src\test\resour
ces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ country
Service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ countryService ---
[INFO] Surefire report directory: C:\MVN\countryService\target\surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.tutorialspoint.ws.CustomerEndPointTest
Feb 27, 2017 11:49:30 AM org.springframework.test.context.TestContextManager ret
rieveTestExecutionListeners
INFO: @TestExecutionListeners is not present for class [class com.tutorialspoint
.ws.CustomerEndPointTest]: using defaults.
Feb 27, 2017 11:49:30 AM org.springframework.beans.factory.xml.XmlBeanDefinition
Reader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-context.xml]
Feb 27, 2017 11:49:30 AM org.springframework.context.support.GenericApplicationC
ontext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext@b
2eddc0: startup date [Mon Feb 27 11:49:30 IST 2017]; root of context hierarchy
Feb 27, 2017 11:49:31 AM org.springframework.ws.soap.addressing.server.Annotatio
nActionEndpointMapping afterPropertiesSet
INFO: Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
Feb 27, 2017 11:49:31 AM org.springframework.ws.soap.saaj.SaajSoapMessageFactory
 afterPropertiesSet
INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.386 sec
Feb 27, 2017 11:49:31 AM org.springframework.context.support.GenericApplicationC
ontext doClose
INFO: Closing org.springframework.context.support.GenericApplicationContext@b2ed
dc0: startup date [Mon Feb 27 11:49:30 IST 2017]; root of context hierarchy
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.517 s
[INFO] Finished at: 2017-02-27T11:49:31+05:30
[INFO] Final Memory: 11M/109M
[INFO] ------------------------------------------------------------------------이 장에서는 Spring WS-Writing Server에서 Spring WS를 사용하여 생성 한 웹 애플리케이션 서버용 클라이언트를 생성하는 방법을 배운다 .
| 단계 | 기술 | 
|---|---|
| 1 | Spring WS – Writing Server 장에 설명 된대로 com.tutorialspoint 패키지에서 countryService 프로젝트를 업데이트하십시오. | 
| 2 | 다음 단계에 설명 된대로 com.tutorialspoint.client 패키지 아래에 CountryServiceClient.java를 만들고 com.tutorialspoint 패키지 아래에 MainApp.java를 만듭니다. | 
CountryServiceClient.java
package com.tutorialspoint.client;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import com.tutorialspoint.GetCountryRequest;
import com.tutorialspoint.GetCountryResponse;
public class CountryServiceClient extends WebServiceGatewaySupport {
   public GetCountryResponse getCountryDetails(String country){
      String uri = "http://localhost:8080/countryService/";
      GetCountryRequest request = new GetCountryRequest();
      request.setName(country);
      GetCountryResponse response =(GetCountryResponse) getWebServiceTemplate()
         .marshalSendAndReceive(uri, request);
      return response;
   }
}MainApp.java
package com.tutorialspoint;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import com.tutorialspoint.client.CountryServiceClient;
public class MainApp {
   public static void main(String[] args) {
      CountryServiceClient client = new CountryServiceClient();
      Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
      marshaller.setContextPath("com.tutorialspoint");
      client.setMarshaller(marshaller);
      client.setUnmarshaller(marshaller);
      GetCountryResponse response = client.getCountryDetails("United States");
      System.out.println("Country : " + response.getCountry().getName());
      System.out.println("Capital : " + response.getCountry().getCapital());
      System.out.println("Population : " + response.getCountry().getPopulation());
      System.out.println("Currency : " + response.getCountry().getCurrency());
   }
}웹 서비스 시작
Tomcat 서버를 시작하고 표준 브라우저를 사용하여 webapps 폴더에서 다른 웹 페이지에 액세스 할 수 있는지 확인하십시오.
웹 서비스 클라이언트 테스트
Eclipse에서 애플리케이션의 MainApp.java를 마우스 오른쪽 버튼으로 클릭하고 run as Java Application명령. 응용 프로그램에서 모든 것이 정상이면 다음 메시지가 인쇄됩니다.
Country : United States
Capital : Washington
Population : 46704314
Currency : USD여기에서 클라이언트를 만들었습니다. CountryServiceClient.javaSOAP 기반 웹 서비스의 경우. MainApp은 CountryServiceClient를 사용하여 웹 서비스에 대한 히트를 만들고 게시 요청을하고 데이터를 가져옵니다.
이번 장 에서는 Spring WS-Writing Server using Spring WS 장에서 생성 한 웹 애플리케이션 서버용 Spring WS-Writing Client 에서 생성 한 클라이언트를 단위 테스트하는 방법을 배운다 .
| 단계 | 기술 | 
|---|---|
| 1 | Spring WS-Writing Server 장에 설명 된대로 com.tutorialspoint 패키지 아래에서 countryService 프로젝트를 업데이트하십시오. | 
| 2 | 아래 단계에 설명 된대로 SRC → Test → Java 폴더 아래의 com.tutorialspoint 패키지 아래에 CountryServiceClientTest.java를 만듭니다. | 
CountryServiceClientTest.java
package com.tutorialspoint;
import static org.junit.Assert.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
import com.tutorialspoint.client.CountryServiceClient;
public class CountryServiceClientTest {
   CountryServiceClient client;
   
   @Before
   public void setUp() throws Exception {
      client = new CountryServiceClient();
      Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
      marshaller.setContextPath("com.tutorialspoint");
      client.setMarshaller(marshaller);
      client.setUnmarshaller(marshaller);
   }
   @Test
   public void test() {
      GetCountryResponse response = client.getCountryDetails("United States");
      Country expectedCountry = new Country();
      expectedCountry.setCapital("Washington");
      Country actualCountry = response.getCountry();
      Assert.assertEquals(expectedCountry.getCapital(), actualCountry.getCapital());
   }
}웹 서비스 시작
Tomcat 서버를 시작하고 표준 브라우저를 사용하여 webapps 폴더에서 다른 웹 페이지에 액세스 할 수 있는지 확인하십시오.
단위 테스트 웹 서비스 클라이언트
명령 콘솔을 열고 C : \ MVN \ countryService 디렉토리로 이동하여 다음 mvn 명령을 실행하겠습니다.
C:\MVN\countryService>mvn testMaven이 프로젝트 빌드 및 테스트를 시작합니다.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building countryService Spring-WS Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ countrySer
vice ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ countryService
---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 10 source files to C:\MVN\countryService\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ co
untryService ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\MVN\countryService\src\test\resour
ces
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ country
Service ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. b
uild is platform dependent!
[INFO] Compiling 2 source files to C:\MVN\countryService\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ countryService ---
[INFO] Surefire report directory: C:\MVN\countryService\target\surefire-reports
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.tutorialspoint.CountryServiceClientTest
Feb 27, 2017 8:45:26 PM org.springframework.ws.soap.saaj.SaajSoapMessageFactory
afterPropertiesSet
INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
Feb 27, 2017 8:45:26 PM org.springframework.oxm.jaxb.Jaxb2Marshaller createJaxbC
ontextFromContextPath
INFO: Creating JAXBContext with context path [com.tutorialspoint]
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.457 sec
Running com.tutorialspoint.ws.CustomerEndPointTest
Feb 27, 2017 8:45:27 PM org.springframework.test.context.TestContextManager retr
ieveTestExecutionListeners
INFO: @TestExecutionListeners is not present for class [class com.tutorialspoint
.ws.CustomerEndPointTest]: using defaults.
Feb 27, 2017 8:45:27 PM org.springframework.beans.factory.xml.XmlBeanDefinitionR
eader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [spring-context.xml]
Feb 27, 2017 8:45:27 PM org.springframework.context.support.GenericApplicationCo
ntext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext@5
17c642: startup date [Mon Feb 27 20:45:27 IST 2017]; root of context hierarchy
Feb 27, 2017 8:45:28 PM org.springframework.ws.soap.addressing.server.Annotation
ActionEndpointMapping afterPropertiesSet
INFO: Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
Feb 27, 2017 8:45:28 PM org.springframework.ws.soap.saaj.SaajSoapMessageFactory
afterPropertiesSet
INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.243 sec
Feb 27, 2017 8:45:28 PM org.springframework.context.support.GenericApplicationCo
ntext doClose
INFO: Closing org.springframework.context.support.GenericApplicationContext@517c
642: startup date [Mon Feb 27 20:45:27 IST 2017]; root of context hierarchy
Results :
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.686 s
[INFO] Finished at: 2017-02-27T20:45:28+05:30
[INFO] Final Memory: 17M/173M
[INFO] ------------------------------------------------------------------------