Monday, September 28, 2015

Loading Governance Registry Entry into WSO2 Property Mediator and manipulate data

We can save resources in the Governance registry and use them in synapse configurations. In this post I'm going to share how we can load registry saved endpoint data into the message context and manipulate them using XPath queries.

First, click on the Registry resources and create a folder structure as governance/data/end points.



Create new address endpoint with sample stock quote service url
(http://localhost:9000/services/SimpleStockQuoteService). If you want to set up sample stock quote backed service, please refer this link.  Save this endpoint in registry by giving above created folder structure.



After creating the endpoint you can see that resource is appeared in endpoint collection.



 Let's create a Pass Through Proxy which refer the endpoint saved in the registry. Click on the "pick from Registry" radio button and browse the endpoint from Governance registry and create the proxy service.

Now we have created the proxy service which refers the register saved endpoint. Let's see how we
Can get the endpoint resource content into message context and manipulate them.

So the end point xml as follows

 <endpoint xmlns="http://ws.apache.org/ns/synapse" name="EP">  
   <address statistics="disable" trace="disable" uri="http://localhost:8280/services/echo">  
     <timeout>  
       <duration>0</duration>  
       <responseAction>discard</responseAction>  
     </timeout>  
     <markForSuspension>  
       <retriesBeforeSuspension>0</retriesBeforeSuspension>  
       <retryDelay>0</retryDelay>  
     </markForSuspension>  
     <suspendOnFailure>  
       <initialDuration>0</initialDuration>  
       <maximumDuration>0</maximumDuration>  
       <progressionFactor>1.0</progressionFactor>  
     </suspendOnFailure>  
   </address>  
 </endpoint>  

If we need to load this endpoint from registry to the message context and read the address URI and log it on the console. You can simply follow the following proxy configuration.

 <?xml version="1.0" encoding="UTF-8"?>  
 <proxy xmlns="http://ws.apache.org/ns/synapse"  
     name="testProxy1"  
     transports="https http"  
     startOnLoad="true"  
     trace="disable">  
   <description/>  
   <target endpoint="gov:/apps/custom/endpoint/dlr/EP.xml">  
    <inSequence>  
      <property name="resultOM"  
           expression="get-property('registry','gov:/apps/custom/endpoint/dlr/EP.xml')"  
           scope="default"  
           type="OM"/>  
      <property name="value" expression="$ctx:resultOM//file/name/@uri"/>  
      <log level="full"/>  
      <log level="custom" separator=",">  
       <property name="resultOM" expression="$ctx:resultOM"/>  
       <property name="resultOM1" expression="$ctx:value"/>  
      </log>  
    </inSequence>  
    <outSequence>  
      <send/>  
    </outSequence>  
   </target>  
 </proxy>  

You can load registry entry using following property.

 <property name="resultOM"   
       expression="get-property('registry','gov:/apps/custom/endpoint/dlr/EP.xml')"   
       scope="default"   
       type="OM"/>   

Then you can perform the XPath queries like following and retrieve attributes or values.

 <property name="value" expression="$ctx:resultOM//file/name/@uri"/>   

No comments :

Post a Comment