Example: Caching web services
You can build a set of cache policies and SOAP messages for a web services application.
The following is a example of building a set of cache policies for a simple web services application. The application in this example stores stock quotes and has operations to read, update the price of, and buy a given stock symbol.
Following are two SOAP message examples that the application can receive, with accompanying HTTP Request headers.
The first message sample contains a SOAP message for a GetQuote operation, requesting a quote for IBM®. This is a read-only operation that gets its data from the back end, and is a good candidate for caching. In this example the SOAP message is cached and a timeout is placed on its entries to guarantee the quotes it returns are current.
POST /soap/servlet/soaprouter HTTP/1.1 Host: www.myhost.com Content-Type: text/xml; charset=The SOAPAction HTTP header in the request is defined in the SOAP specification and is used by HTTP proxy servers to dispatch requests to particular HTTP servers. WebSphere® Application Server dynamic cache can use this header in its cache policies to build IDs without having to parse the SOAP message.utf-8SOAPAction: 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>
Message example 2 illustrates a SOAP message for a BuyQuote operation. While message 1 is cacheable, this message is not, because it updates the back end database.
POST /soap/servlet/soaprouter HTTP/1.1 Host: www.myhost.com Content-Type: text/xml; charset=utf-8SOAPAction: 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>
<?xml version=To build a set of cache policies for a web services application, configure WebSphere Application Server dynamic cache to recognize cacheable service operation of the operation.1.0?> <definitions name=StockQuoteService-interfacetargetNamespace=https://www.getquote.com/StockQuoteService-interfacexmlns:tns=https://www.getquote.com/StockQuoteService-interfacexmlns:xsd=https://www.w3.org/2001/XMLSchemaxmlns=soap=http://schemas.xmlsoap.org/wsdl/soap/xmlns=http://schemas.xmlsoap.org/wsdl/<message name=SymbolRequest> <part name=returntype=xsd:string/> </message> <portType name=StockQuoteService> <operation name=getQuote> <input message=tns:SymbolRequest/> <output message=tns:QuoteResponse/> </operation> </portType> <binding name=StockQuoteServiceBindingtype=tns:StockQuoteService> <soap:binding style=rpctransport=http://schemas.xmlsoap.org/soap/http/> <operation name=getQuote> <soap:operation soapAction=urn:stockquote-lookup/> <input> <soap:body use=encodednamespace=urn:stockquoteencodingStyle=http://schemas.xmlsoap.org/soap/encoding//> </input> <output> <soap:body use=encodednamespace=urn:stockquotesencodingStyle=http://schemas.xmlsoap.org/soap/encoding//> </output> </operation> </binding> </definition>
WebSphere Application Server inspects the HTTP request to determine whether or not an incoming message can be cached based on the cache policies defined for an application. In this example, buyStock and stock-update are not cached, but stockquote-lookup is cached. In the cachespec.xml file for this web application, the cache policies need defining for these services so that the dynamic cache can handle both SOAPAction and service operation.
WebSphere Application Server uses the operation
and the message body in web services cache IDs, each of which has
a component associated with them. Therefore, each web services <cache-id>
rule
contains only two components. The first is for the operation. Because
you can perform the stockquote-lookup operation by either using a
SOAPAction header or a service operation in the body, you must define
two different <cache-id>
elements, one for
each method. The second component is of type body
, and defines
how WebSphere Application Server should incorporate
the message body into the cache ID. You can use a hash of the body,
although it is legal to use the literal incoming message in the ID.
The incoming HTTP request is analyzed by WebSphere Application
Server to determine which of the <cache-id>
rules
match. Then, the rules are applied to form cache or invalidation IDs.
<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>