Showing posts with label Property. Show all posts
Showing posts with label Property. Show all posts

Wednesday, March 30, 2016

[WSO2 ESB]How to retrive dynamic file which is saved in local folder?

Lets check out the way to retrieve file through ESB mediators.

In here I used

  • XML file which is contains a sequence (File which is saved in local folder)
  • Use Property mediator to retrieve file 
  • Use sequence mediator to run the dynamic file which is saved in local folder (In here I selected sequence mediator, because I saved sequence within XML file)
Lets begin...


  1. XML file should be put into a folder

  • In here Pre-defined sequence added to XML file and saved it with sequence name (dynamic_seq_2.xml). 
Sample configuration:

 <sequence name="dynamic_seq_2" xmlns="http://ws.apache.org/ns/synapse">  
   <in>  
     <log level="full">  
       <property name="message" value="*** Test Message ***"/>  
     </log>  
   </in>  
    <send>  
       <endpoint>  
         <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>  
       </endpoint>  
     </send>  
 </sequence>  

  • Saved "dynamic_seq_2.xml" file in "$ESB_HOME/repository/samples/resources/sequence/"
2. Start axis2 server.

Note: Sample axis2 server comes with ESB pack ($ESB_HOME/samples/axis2Server/). I used it.

          I used SimpleStockQuote service as the backend. Therefore you have to deploy SimpleStockQuote service if you didn't do.

Navigate to $ESB_HOME/samples/axis2Server/src/SimpleStockQuote/ through terminal.
Run "ant" command
 $ ant  

          Then start axis2 server.

Navigate to $ESB_HOME/samples/axis2Server/ through terminal.
Start server
 $ sh axis2server.sh  

3  Start WSO2 ESB server

4. Navigate to Source View (Home > Manage > Service Bus  > Source View  > Service Bus Configuration)

Change registry provider as "ESBRegistry" and give path to the folder which you saved dynamic sequence.

Sample configuration:

 <registry provider="org.wso2.carbon.mediation.registry.ESBRegistry">  
     <parameter name="root">file:repository/samples/resources/</parameter>  
     <parameter name="cachableDuration">15000</parameter>  
 </registry>  

5. Restart ESB

6. Navigate to sequences (Home > Manage > Service Bus > Sequences) and Click on "Add sequences"

7. Create a sequence

   Add property which will have path to retrieve dynamic sequence.

   Add sequence mediator with dynamic key. Give previously created property as Referring sequence.

Sample Configuration

 <sequence name="seq5">  
     <property name="property" scope="default" type="STRING" value="sequence/dynamic_seq_2.xml"/>  
     <sequence key="{get-property('property')}"  
      xmlns:ns3="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>  
 </sequence>  

8.  Create a proxy service with sequence.

Sample Configuration:

 <proxy name="dynamicKeySeq" startOnLoad="true" trace="disable" transports="http https">  
     <description/>  
     <target inSequence="seq5"/>  
 </proxy>  

9.  Invoke proxy service.

Sample Message:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://org.apache.synapse/xsd">  
   <soapenv:Body>  
    <ser:placeOrder>  
      <!--Optional:-->  
      <ser:order>  
       <!--Optional:-->  
       <xsd:price>91.7473384496671</xsd:price>  
       <!--Optional:-->  
       <xsd:quantity>7616</xsd:quantity>  
       <!--Optional:-->  
       <xsd:symbol>IBM</xsd:symbol>  
      </ser:order>  
    </ser:placeOrder>  
   </soapenv:Body>  
 </soapenv:Envelope>  

Then ESB logs should be indicating redirecting through dynamic sequence.

[2016-03-30 10:32:50,908]  INFO - LogMediator To: http://localhost:8280/services/dynamicKeySeq, WSAction: urn:placeOrder, SOAPAction: urn:placeOrder, ReplyTo: http://www.w3.org/2005/08/addressing/anonymous, MessageID: urn:uuid:02abb47f-bd35-4717-98e3-b3f1f7e2b73e, Direction: request, message = *** Test Message ***, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://org.apache.synapse/xsd" xmlns:ser="http://services.samples"><soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:Action>urn:placeOrder</wsa:Action><wsa:To>http://localhost:8280/services/dynamicKeySeq</wsa:To></soapenv:Header><soapenv:Body>
      <ser:placeOrder>
         <!--Optional:-->
         <ser:order>
            <!--Optional:-->
            <xsd:price>91.7473384496671</xsd:price>
            <!--Optional:-->
            <xsd:quantity>7616</xsd:quantity>
            <!--Optional:-->
            <xsd:symbol>IBM</xsd:symbol>
         </ser:order>
      </ser:placeOrder>
   </soapenv:Body></soapenv:Envelope>

Note: Configuring part of ESB to retrieve local files, done with first 4 steps. Retrieving part done through adding mediator. Confirming and validation part done through sequence mediator logs.

According to your requirements, can modify mediators and relevant configurations.

All comments and value additions are warmly welcome !! :)

Tuesday, March 29, 2016

[WSO2 ESB] How to read a value of SOAP element using property mediator

Hi all,

Property mediator in WSO2 ESB is a very useful mediator and can be use for various mediation purposes. In here I used property mediator to read SOAP element value.

1. I created a sequence with property mediator. Sample Configuration as follows:

 <sequence name="propertySeq">  
     <property expression="//ser:getSimpleQuote/ser:symbol/text()"  
       name="testProperty" scope="default" type="STRING"  
       xmlns:ns="http://org.apache.synapse/xsd"  
       xmlns:ser="http://services.samples" xmlns:xsd="http://sample.wso2.org/xsd"/>  
     <log level="custom">  
       <property expression="get-property('testProperty')"  
         name="PropertyValue" xmlns:ns="http://org.apache.synapse/xsd"/>  
     </log>  
   </sequence>  

2. I created a proxy service with above sequence.

 <proxy name="propertyProx" startOnLoad="true" trace="disable" transports="http https">  
     <description/>  
     <target endpoint="SimpleStockQuote" inSequence="propertySeq"/>  
 </proxy>  
 <endpoint name="SimpleStockQuote">  
     <address uri="http://localhost:9000/services/SimpleStockQuoteService/"/>  
 </endpoint>  

3. Invoke proxy service. 

Note: Through property mediator, I will retrieve value of "symbol" and used logs to indicated retruved value.

Sample SOAP message will be as follows:

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples">  
   <soapenv:Header/>  
   <soapenv:Body>  
    <ser:getSimpleQuote>  
      <!--Optional:-->  
      <ser:symbol>WSO2</ser:symbol>  
    </ser:getSimpleQuote>  
   </soapenv:Body>  
 </soapenv:Envelope>  

Logs should be illustrate as follows: 

 [2016-03-29 18:28:22,380] INFO - LogMediator PropertyValue = WSO2  

Note: According to message type and according to the content you want to add to property mediator, you can change above configurations.

Happy Coding !! :)