Sunday, June 12, 2016

How to read registry resource text (.txt file) using class mediator - ESB 4.9.0

In the mediation process, users might need to access the registry resources using a class mediator, which are stored in the governance/config registries in WSO2 ESB. In this sample I have tried to read a text file using a class mediator. 

You can follow Registry API for the Synapse  for more use full method. 


 package com.wso2.test;  
 import org.apache.synapse.MessageContext;  
 import org.apache.synapse.mediators.AbstractMediator;  
 import org.apache.synapse.registry.Registry;  
 import org.apache.synapse.config.Entry;  
 import org.apache.axiom.om.impl.llom.OMTextImpl;  

 public class RecourceFinder extends AbstractMediator { 
  
      String REGISTRY_MAPPING_STORAGE_URL = "conf:/repository/new";  
      String fileName = "converted.txt";  
      public boolean mediate(MessageContext context) {   
           Registry wso2Reg = context.getConfiguration().getRegistry();  
           Entry entry = new Entry(REGISTRY_MAPPING_STORAGE_URL+"/"+fileName);  
           Object obj = wso2Reg.getResource(entry, null);  
           OMTextImpl textImpl = (OMTextImpl) obj;  
           try{  
           String value = textImpl.getText();  
           System.out.println(value);  
           }catch(Exception e){  
                e.printStackTrace();  
           }  
     return true;  
      }  
 }  


No comments :

Post a Comment