Tuesday, July 5, 2011

Putting OSB to REST

this is my URI that I "GET" in my browser:

http://acme.com:7009/GUTools/Caches/LoadCache/validityDate=2001-07-05/id=90

being GUTools/Caches/LoadCache the URI of my "REST" AnyXML Proxy Service

assign $inbound/ctx:transport/ctx:request/http:relative-URI/text() to relativeURI

(relativeURI = validityDate=2001-07-05/id=90)

assign
let $mySequence := fn:tokenize($relativeURI, "/")
return
<parameters>
{for $item in $mySequence
return <parameter><name>{fn:substring-before($item, '=')}</name><value>{fn:substring-after($item, '=')}</value></parameter>
}
</parameters>

to parameters


this is $parameters :

<parameters>
<parameter>
<name>validityDate</name>
<value>2001-07-05</value>
</parameter>
<parameter>
<name>id</name>
<value>90</value>
</parameter>
</parameters>


For Each [ parameter ] in [ ./parameter ] of [ parameters ]
Indexed by [ parameterIndex ] with total count in [ parameterCount ]

log $parameter/name/text()
log $parameter/value/text()


Great! I was able to get all the parameters from the URI. At this point I can process them using simple XPath to thet their value:

$parameters/parameter[name='validityDate']/value/text()

this returns 2001-07-05


I can invoke from a CRON job this command:

lwp-request -m GET http://acme.com:7009//GUTools/Caches/LoadCache/validityDate=2001-07-02

to trigger the Proxy Service with a simple GET (no more bloody SOAP)

No comments: