Showing posts with label Registry. Show all posts
Showing posts with label Registry. 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 !! :)

Monday, January 12, 2015

Storing in Carbon Registry


In WSO2, "Carbon" is the unique OSGi-based middleware platform for all WSO2 carbon products. In every carbon product like Message Broker, Complex Event Processor (CEP) and Enterprise Service Bus (ESB) has in-built carbon registry as one of common carbon feature. That in-built registry can be easily access by product management console.

Using carbon registry as a service for a carbon component

When developing an external carbon component as stat publisher for Message Broker, had to use in-built carbon registry to store UI data of stat publisher component. For developing purpose, in-built carbon registry can be use as follows: (Used the example of stat publisher component)

  • Carbon platform is OSGi based platform. Therefore have to access carbon registry as a service.  

  •  First have to retrieve registry service from Activator Class of the component. (Every OSGi bundle has bundle activator class)

  • Importing package
 import org.wso2.carbon.registry.core.service.RegistryService    

  •  src reference         
  @scr.reference name="org.wso2.carbon.registry.service"   
          interface="org.wso2.carbon.registry.core.service.RegistryService"  
          cardinality="1..1" policy="dynamic" bind="setRegistryService"   
          unbind="unsetRegistryService"  

  •  In activator class must have separate two methods to set registry to a variable and to unset.  

         /**     
         **Set RegistryService  
         **@param registryService - Registry for this server  
          */  
           protected void setRegistryService(RegistryService registryService) {  
           StatPublisherValueHolder.setRegistryService(registryService );  
           }  
         /**     
          **Remove RegistryService  
          **@param registryService - Registry for this server  
          */  
           protected void removeRegistryService(RegistryService registryService) {  
           StatPublisherValueHolder.setRegistryService(null);  
           }  

  • Through pointed registry service variable, can be used it to do any function within component context registry. Registry can be retrieve through registry service as follows;
 Registry registry = StatPublisherValueHolder.getRegistryService()  
                              .getConfigSystemRegistry(tenantId);    
                      
         ** In here use tenant ID to identify the carbon component instance. It will be useful in multitenancy environment.

Happy Storing in Carbon :)

Comments and Questions are well come !