Add new attachment

Only authorized users are allowed to upload new attachments.

This page (revision-6) was last changed on 28-Oct-2007 19:56 by DongGukLee  

This page was created on 28-Oct-2007 14:19 by DongGukLee

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Difference between version and

At line 150 removed 3 lines
!! Spring WebService
Spring WebService의 핵심 인터페이스는 WebServiceMessage이다.
SoapMessage는 SOAP관련 WebServiceMessage의 하위클래스이다.
At line 154 removed 247 lines
실제 WebServiceMessage를 생성하는 메소드는 WebServiceMessageFactory에 들어있다.
__SaajSoapMessageFactory__
SOAP with Attachments API for Java를 사용한다.
[{Java2HtmlPlugin
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory" />
}]
<div class="information">
SAAJ는 DOM에 기초한다. 이 말은 메모리에 저장된다는 것을 뜻하기 때문에 좀더 큰 SOAP메시지의 경우 적절하지 않다고 볼수 있다. 이 경우 AxiomSoapMessageFactory가 더 적절하다.
</div>
__AxiomSoapMessageFactory__
StAX(Streaming API for XML)에 기초한 AXis 2 Object Model를 사용한다.
[{Java2HtmlPlugin
<bean id="messageFactory" class="org.springframework.ws.soap.axiom.AxiomSoapMessageFactory">
<property name="payloadCaching" value="true"/>
</bean>
}]
__SOAP 버전__
현재 1.1, 1.2 버전을 지원한다. 디폴트는 1.1이다.
[{Java2HtmlPlugin
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
</property>
</bean>
</beans>
}]
!! MessageContext
요청(클라이언트측)과 응답(서버측)이라는 두가지를 포함하는 객체이다.
__클라이언트 측__
클라이언트에서는 webServiceTemplate를 통해 MessageContext가 생성한다.
[{Java2HtmlPlugin
import java.io.StringReader;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.transport.WebServiceMessageSender;
public class WebServiceClient {
private static final String MESSAGE = "<message xmlns=\"http://tempuri.org\">Hello Web Service World</message>";
private final WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
public void setDefaultUri(String defaultUri) {
webServiceTemplate.setDefaultUri(defaultUri);
}
// send to the configured default URI
public void simpleSendAndReceive() {
StreamSource source = new StreamSource(new StringReader(MESSAGE));
StreamResult result = new StreamResult(System.out);
webServiceTemplate.sendSourceAndReceiveToResult(source, result);
}
// send to an explicit URI
public void customSendAndReceive() {
StreamSource source = new StreamSource(new StringReader(MESSAGE));
StreamResult result = new StreamResult(System.out);
webServiceTemplate.sendSourceAndReceiveToResult("http://localhost:8080/AnotherWebService", source, result);
}
}
}]
[{Java2HtmlPlugin
<beans xmlns="http://www.springframework.org/schema/beans">
<bean id="webServiceClient" class="WebServiceClient">
<property name="defaultUri" value="http://localhost:8080/WebService"/>
</bean>
</beans>
}]
!! MessageDispatcher
Spring-WS의 서버측은 XML메시지를 endpoint로 전달하는 클래스로 디자인되었다.
다음은 Spring WS에서의 request를 처리 절차이다.
[http://static.springframework.org/spring-ws/site/reference/html/images/sequence.png]
!! MessageDispatcherServlet
기본적으로 web.xml 파일에 정의할때 사용된다.
!! WSDL 노출
[{Java2HtmlPlugin
<bean id="orders" class="org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition">
<constructor-arg value="/WEB-INF/wsdl/Orders.wsdl"/>
</bean>
}]
[{Java2HtmlPlugin
http://localhost:8080/spring-ws/orders.wsdl
}]
!! XSD에서 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/Orders.xsd"/>
<property name="portTypeName" value="Orders"/>
<property name="locationUri" value="http://localhost:8080/ordersService/"/>
</bean>
</property>
</bean>
}]
DynamicWsdl11Definition 는 WSDL을 생성하기 위해 Wsdl11DefinitionBuilder 를 사용한다. 위 예제에서는 XsdBasedSoap11Wsdl4jDefinitionBuilder를 사용했다. 동적으로 WSDL을 생성하기 위해서는 xsd에 request나 response로 끝나는 element가 있어야 한다. 이를테면 다음의 예를 보자.
[{Java2HtmlPlugin
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema elementFormDefault="qualified"
targetNamespace="http://openframework.or.kr/hr/schemas" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:hr="http://openframework.or.kr/hr/schemas">
<xs:element name="HolidayRequest">
<xs:complexType>
<xs:all>
<xs:element name="Holiday" type="hr:HolidayType"/>
<xs:element name="Employee" type="hr:EmployeeType"/>
</xs:all>
</xs:complexType>
</xs:element>
....
</xs:schema>
}]
위 소스의 경우 HolidayRequest라는 element가 있다. 이런 경우 자동으로 생성되는 WSDL에는 HolidayRequest 요소와 함께 Holiday라는 operation이 생성된다.
[{Java2HtmlPlugin
<?xml version="1.0" encoding="UTF-8"?><wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:schema="http://openframework.or.kr/hr/schemas" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://openframework.or.kr/hr/definitions" targetNamespace="http://openframework.or.kr/hr/definitions">
<wsdl:types>
....
</wsdl:types>
<wsdl:message name="HolidayRequest">
....
</wsdl:message>
<wsdl:portType name="HumanResource">
<wsdl:operation name="Holiday">
<wsdl:input message="tns:HolidayRequest" name="HolidayRequest">
</wsdl:input>
</wsdl:operation>
</wsdl:portType>
....
</wsdl:binding>
</wsdl:definitions>
}]
!! DispatcherServlet에 Spring-WS 묶기
!! Endpoints
[{Java2HtmlPlugin
public interface PayloadEndpoint {
/**
* Invokes an operation.
*/
Source invoke(Source request) throws Exception;
}
}]
Endpoint는 Spring-WS의 서버측 지원에 대한 핵심이다.
!! AbstractDomPayloadEndpoint
[{Java2HtmlPlugin
package samples;
public class SampleEndpoint extends AbstractDomPayloadEndpoint {
private String responseText;
public SampleEndpoint(String responseText) {
this.responseText = responseText;
}
protected Element invokeInternal(
Element requestElement,
Document document) throws Exception {
String requestText = requestElement.getTextContent();
System.out.println("Request text: " + requestText);
Element responseElement = document.createElementNS("http://samples", "response");
responseElement.setTextContent(responseText);
return responseElement;
}
}
}]
[{Java2HtmlPlugin
<bean id="sampleEndpoint" class="samples.SampleEndpoint">
<constructor-arg value="Hello World!"/>
</bean>
}]
위 소스를 사용했을때 응답 메시지는 다음과 같다.
[{Java2HtmlPlugin
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<request xmlns="http://samples">
Hello
</request>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
}]
Version Date Modified Size Author Changes ... Change note
6 28-Oct-2007 19:56 4.93 kB DongGukLee to previous
5 28-Oct-2007 19:26 12.412 kB DongGukLee to previous | to last
4 28-Oct-2007 16:53 8.382 kB DongGukLee to previous | to last
3 28-Oct-2007 14:47 4.922 kB DongGukLee to previous | to last
2 28-Oct-2007 14:46 4.922 kB DongGukLee to previous | to last
1 28-Oct-2007 14:19 1.444 kB DongGukLee to last
« This page (revision-6) was last changed on 28-Oct-2007 19:56 by DongGukLee