예제: 웹 서비스 캐싱

웹 서비스 애플리케이션에 대한 일련의 캐시 정책 및 SOAP 메시지를 빌드할 수 있습니다.

다음은 간단한 웹 서비스 애플리케이션에 대한 일련의 캐시 정책을 빌드하는 예제입니다. 이 예에서 애플리케이션은 주식 시세를 저장하고 지정된 주식의 가격을 읽고 업데이트하며 구매하는 조작을 수행합니다.

다음은 애플리케이션이 수신할 수 있는 두 개의 SOAP 메시지 예로 HTTP 요청 헤더가 있습니다.

첫 번째 메시지 샘플에는 IBM®에 주식 시세를 요청하는 GetQuote 조작에 대한 SOAP 메시지가 있습니다. 이는 백엔드 및 캐싱에 대한 용이한 후보로부터 해당 데이터를 확보하는 읽기 전용 조작이며 캐시할 수 있습니다. 이 예에서 SOAP 메시지는 캐시되며, 리턴한 시세의 날짜를 현재로 유지하도록 항목에 제한시간을 배정합니다.

메시지 예 1
POST /soap/servlet/soaprouter 
HTTP/1.1  
Host: www.myhost.com  
Content-Type: text/xml; charset="utf-8"  
SOAPAction: urn:stockquote-lookup
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:getQuote xmlns:m="urn:stockquote">
<symbol>IBM</symbol>
</m:getQuote>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>  
요청에서 SOAPAction HTTP 헤더는 SOAP 스펙에 정의되고, 특정 HTTP 서버에 대한 요청을 디스패치하도록 HTTP 프록시 서버에서 사용됩니다. WebSphere® Application Server 동적 캐시는 캐시 정책에서 이 헤더를 사용하여 SOAP 메시지를 구분 분석하지 않고 ID를 빌드할 수 있습니다.

메시지 예 2에서는 BuyQuote 조작에 대한 SOAP 메시지를 보여줍니다. 메시지 1이 캐시 가능한 반면, 이 메시지는 백엔드 데이터베이스를 업데이트하기 때문에 캐시할 수 없습니다.

메시지 예 2
POST /soap/servlet/soaprouter 
HTTP/1.1  
Host: www.myhost.com
Content-Type: text/xml; charset="utf-8" 
SOAPAction: urn:stockquote-update
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<m:buyStock xmlns:m="urn:stockquote">
<symbol>IBM</symbol>
</m:buyStock>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>  

다음 그래픽에서는 SOAP 메시지와 함께 메소드를 호출하는 방법을 보여줍니다. 웹 서비스 용어, 특히 WSDL(Web Services Description Language)에서 서비스란 조작의 콜렉션(예: getQuote 및 buyStock)입니다. 본문 요소 네임스페이스(예: urn:stockquote)는 서비스를 정의하고, 첫 번째 본문 요소의 이름은 조작을 표시합니다.

SOAPmessages:캐싱으로 메소드 호출

다음은 getQuote 조작에 대한 WSDL 예입니다.

<?xml version="1.0"?>
<definitions name="StockQuoteService-interface"targetNamespace="http://www.getquote.com/StockQuoteService-interface"xmlns:tns="http://www.getquote.com/StockQuoteService-interface"xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns=soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns="http://schemas.xmlsoap.org/wsdl/"<message name="SymbolRequest">
<part name="return" type="xsd:string"/>
	  </message>
<portType name="StockQuoteService">
	    <operation name="getQuote">
<input message="tns:SymbolRequest"/>
<output message="tns:QuoteResponse"/>
</operation>
</portType>
<binding name="StockQuoteServiceBinding"type="tns:StockQuoteService">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
	    <operation name="getQuote">
<soap:operation soapAction="urn:stockquote-lookup"/>
<input>
<soap:body use="encoded" namespace="urn:stockquote"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<soap:body use="encoded" namespace="urn:stockquotes"encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
</definition>

웹 서비스 애플리케이션에 대한 일련의 캐시 정책을 빌드하려면 조작 중 캐시 가능한 서비스 조작을 인식하도록 WebSphere Application Server 동적 캐시를 구성하십시오.

WebSphere Application Server는 수신 메시지가 애플리케이션에 대해 정의된 캐시 정책에 따라 캐시될 수 있는지 여부를 판별하기 위해 HTTP 요청을 검사합니다. 이 예에서, buyStock 및 stock-update는 캐시되지 않지만 stockquote-lookup은 캐시됩니다. 이 웹 애플리케이션의 cachespec.xml 파일에서, 동적 캐시가 SOAPAction 및 서비스 조작을 모두 처리할 수 있도록 이들 서비스에 대한 캐시 정책을 정의해야 합니다.

WebSphere Application Server는 웹 서비스 캐시 ID에 있는 메시지 본문 및 조작을 사용하며, 이들 각각은 이와 연관된 컴포넌트를 가집니다. 따라서 각 웹 서비스 <cache-id> 규칙은 두 개의 컴포넌트만을 포함합니다. 첫 번째는 조작용입니다. 본문에 있는 SOAPAction 헤더 또는 서비스 조작을 사용하여 stockquote-lookup 조작을 수행할 수 있기 때문에, 각 메소드에 하나씩 두 개의 다른 <cache-id> 요소를 정의해야 합니다. 두 번째 컴포넌트는 "body" 유형이며, WebSphere Application Server가 메시지 본문을 캐시 ID로 통합시키는 방법을 정의합니다. ID에서 리터럴 수신 메시지를 사용하는 것이 적절하기는 하지만 본문의 해시를 사용할 수 있습니다.

WebSphere Application Server는 수신 HTTP 요청을 분석하여 어느 <cache-id> 규칙이 일치하는지 판별합니다. 그런 다음, 캐시 또는 무효화 ID를 구성하는 데 규칙이 적용됩니다.

다음은 SOAPAction 및 servicesOperation 규칙을 정의하는 cachespec.xml 파일의 샘플 코드입니다.

<cache>
<cache-entry>
	<class>webservice</class>
	<name>/soap/servlet/soaprouter</name>
	<sharing-policy>not-shared</sharing-policy>
	<cache-id>
		<component id="" type="SOAPAction">
			<value>urn:stockquote-lookup</value>
		</component>
		<component id="Hash" type="SOAPEnvelope"/>
			<timeout>3600</timeout>
			<priority>1<priority>
		</component>
	</cache-id>
	<cache-id>
		<component id="" type="serviceOperation">
			<value>urn:stockquote:getQuote</value>
		</component>
		<component id="Hash" type="SOAPEnvelope"/>
			<timeout>3600</timeout>
			<priority>1</priority>
		</component>
	</cache-id>
</cache-entry>
</cache>

주제 유형을 표시하는 아이콘 참조 주제



시간소인 아이콘 마지막 업데이트 날짜: last_date
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=cord&product=was-nd-mp&topic=rdyn_webservicescaching
파일 이름:rdyn_webservicescaching.html