!! 프로젝트 생성하기

[{Java2HtmlPlugin 

mvn archetype:create -DarchetypeGroupId=org.springframework.ws \
  -DarchetypeArtifactId=spring-ws-archetype \
  -DarchetypeVersion=1.0.1 \
  -DgroupId=com.mycompany.hr \
  -DartifactId=holidayService
}]

!! web.xml 파일

[{Java2HtmlPlugin 

<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>MyCompany HR Holiday Service</display-name>

    <!-- take especial notice of the name of this servlet -->
    <servlet>
        <servlet-name>spring-ws</servlet-name>
        <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>spring-ws</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>
}]

!! [[servlet명]-ws-servlet.xml 파일
이 파일은 EndPoints, WebServiceMessageReceivers 를 정의한다. 여기서 파일명은 openframework-ws-servlet.xml 이라고 가정한다. 

[{Java2HtmlPlugin 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


</beans>
}]

!! Endpoint 구현하기
XML 메시지를 다루기 위해 Endpoint를 구현해야 한다. 여기서 XML을 다루기 위해 사용할수 있는 방식은 JDOM, DOM, dom4j, XOM, SAX, 그리고 StAX 가 있다. 

[{Java2HtmlPlugin 

package openframework.ws;

import java.text.SimpleDateFormat;
import java.util.Date;

import openframework.service.HumanResourceService;

import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;

public class HolidayEndpoint extends AbstractJDomPayloadEndpoint {

	private XPath startDateExpression;
	private XPath endDateExpression;
	private XPath nameExpression;
	private HumanResourceService humanResourceService;

	public HolidayEndpoint(HumanResourceService humanResourceService) throws JDOMException {
		this.humanResourceService = humanResourceService;
		Namespace namespace = Namespace.getNamespace("hr", "http://openframework.or.kr/hr/schemas");
		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);
	}

	protected Element invokeInternal(Element holidayRequest) throws Exception {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date startDate = dateFormat.parse(startDateExpression.valueOf(holidayRequest));
		Date endDate = dateFormat.parse(endDateExpression.valueOf(holidayRequest));
		String name = nameExpression.valueOf(holidayRequest);

		humanResourceService.bookHoliday(startDate, endDate, name);
		return null;
	}
}
}]

openframework-ws-servlet.xml 파일에 다음 설정을 추가한다. 

[{Java2HtmlPlugin 

<beans xmlns="http://www.springframework.org/schema/beans">
    <bean id="holidayEndpoint" class="openframework.ws.HolidayEndpoint">
        <constructor-arg ref="hrService"/>
    </bean>

    <bean id="hrService" class="openframework.service.StubHumanResourceService"/>
</beans>
}]

!! 메시지를 Endpoint로 보내기

[{Java2HtmlPlugin 

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
    <property name="mappings">
        <props>
            <prop key="{http://openframework.or.kr/hr/schemas}HolidayRequest">holidayEndpoint</prop>
        </props>
    </property>
    <property name="interceptors">
        <bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
    </property>
</bean>
}]

!! WSDL 배포하기

[{Java2HtmlPlugin 

<bean id="holiday" class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">   
  <property name="builder">
    <bean class="org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder">
      <property name="schema" value="/WEB-INF/xsd/hr.xsd"/>
      <property name="portTypeName" value="HumanResource"/>
      <property name="locationUri" value="http://localhost:8888/holidayService/"/>
      <property name="targetNamespace" value="http://openframework.or.kr/hr/definitions"/>
    </bean>
  </property>
</bean>
}]

여기서 bean의 id값인 holiday는 wsdl을 가져올때 사용되는 값이다. 간단하게는 http://[[서버주소]/[[context명]/[[bean의 id].wsdl 이라는 URL을 사용하면 WSDL을 가져올수 있다. 위와 같은 경우 다음과 같은 URL을 가지게 된다. 

[http://localhost:8888/spring-ws/holiday.wsdl]