Month: January 2015

VIM editor -Use Full commands

From command mode to insert mode – i
From command mode to visual mode – v
From insert/visual mode to command mode – Esc

command mode

search from top to bottom – /”searchpattern”
search from bottom to top – ?”searchpattern”

once search string is entered –
To find next match in downwards direction – n
To find the next match in upwards direction – N

copy – y (yank)
copy current line – yy

delete/cut – d
delete/cut current line -dd

undo -u
redo – Ctrl+r

Select+copy/cut+paste
1 . Enter ‘v’ (visual mode)
2. select the text
3 . press ‘d’ for cut or press ‘y’ for copy
4 . go the place where you want to paste and press ‘p’ to paste

WSO2 ESB – JSON PATH

Logging content from JSON payload using json path

If Payload is a json object as follow

{“symbol”:”WSO2″, “ID”:”StockQuote”}

1 .

<log level=”custom”>
<property name=”jsonlog” expression=”json-eval($.)”/>
</log>

This will log the entire json object – {“symbol”:”WSO2″, “ID”:”StockQuote”}

 

2 .

<log level=”custom”>
<property name=”jsonlog” expression=”json-eval($.symbol)”/>
</log>

 

This will log the symbol -wso2

 

reference

1 .https://docs.wso2.com/display/ESB480/JSON+Support

WSO2 ESB – Wrap XML tags around JSON return

ESB receive request in the format of JSON as follow

{“symbol”:”WSO2″, “ID”:”StockQuote”}

 

But request to the back end service should be in following format

<?xml version=”1.0″ encoding=”utf-8″?>
<soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”><soapenv:Body&gt;
<ns:xmlwrap xmlns:ns=”http://services.samples”&gt;{“symbol”:”WSO2″, “ID”:”StockQuote”}</ns:xmlwrap>
</soapenv:Body>
</soapenv:Envelope>

 

read the json using json path and use payloadFactory mediator to construct the desired request

<?xml version=”1.0″ encoding=”UTF-8″?>
<proxy xmlns=”http://ws.apache.org/ns/synapse&#8221;
name=”JSONProxy”
transports=”https,http”
statistics=”disable”
trace=”disable”
startOnLoad=”true”>
<target>
<inSequence>
<property name=”JSON_PAYLOAD” expression=”json-eval($.)”/>
<log level=”custom”>
<property name=”jsonlog” expression=”$ctx:JSON_PAYLOAD”/>
</log>
<payloadFactory media-type=”xml”>
<format>
<ns:xmlwrap xmlns:ns=”http://services.samples”>$1</ns:xmlwrap&gt;
</format>
<args>
<arg evaluator=”xml” expression=”get-property(‘JSON_PAYLOAD’)”/>
</args>
</payloadFactory>
<log level=”full”/>
<header name=”Action” value=”urn:getQuote”/>
</inSequence>
<outSequence>
<send/>
</outSequence>
<endpoint>
<address uri=”http://localhost:9001/services/SimpleStockQuoteService&#8221;
format=”soap11″/>
</endpoint>
</target>
<description/>
</proxy>

 

output

<?xml version=”1.0″ encoding=”utf-8″?><soapenv:Envelope xmlns:soapenv=”http://schemas.xmlsoap.org/soap/envelope/”&gt;
<soapenv:Body><ns:xmlwrap xmlns:ns=”http://services.samples”&gt;{“symbol”:”WSO2″, “ID”:”StockQuote”}
</ns:xmlwrap>
</soapenv:Body>
</soapenv:Envelope>

WSO2 ESB – Add Custom level log

By setting the log level to “custom” , we can add custom log in ESB proxy .

1. Log a custom String value (e.g Hello World)

<log level=”custom”>
<property name=”MyCustomLog” value=”Hello World”/>
</log>

 

2. Log a property value using custom log level. use expression attribute to read the value of property.

<property name=”Symbol” value=”wso2″/>

———————————————————————————

<log level=”custom”>
<property name=”customlog” expression=”$ctx:Symbol”/>
</log>

OR

<log level=”custom”>
<property name=”customlog” expression=”get-property(‘Symbol’)/>
</log>

 

WSO2 ESB -Pass data from ClassMediator to Proxy

The Class Mediator creates an instance of a custom-specified class and sets it as a mediator. So you can  add your java logic in your Class Mediator.
Once You have written the Class Mediator create a jar out of it and place it in ESB_HOME/repository/components/lib folder. You can even create the Mediator as OSGI bundle.In that case place the bundle in ESB_HOME/repository/components/dropins/ folder

You can refer doc[1] to learn how to create CustomMediator(ClassMediator) and pass data from proxy to custom java code. But this post gives small idea  on how to pass data from custom java code (ClassMediator) to proxy .

How to pass data from java code to proxy ?

You can use setProperty method inside the mediator class to set the value for a property and in the proxy by calling getProperty() you can retrieve that value of that property.Thus you can pass data from the Java code to Proxy.
Please check the example given below.

1.Set the property value ( setProperty(“message”,”hello world!” ))

public boolean mediate(MessageContext mc) {

mc.setProperty(“message”,”hello world!” );

return true;
}

2. Sapmple proxy which read the property value ( get-property(‘message’) )

<?xml version=”1.0″ encoding=”UTF-8″?>
<proxy xmlns=”http://ws.apache.org/ns/synapse
name=”ClassMediator”
transports=”https,http”
statistics=”disable”
trace=”disable”
startOnLoad=”true”>
<target>
<inSequence>
<class name=”org.wso2.carbon.mediator.CustomMediator”/>
<log level=”custom”>
<property name=”customlog” expression=”get-property(‘message’)”/>
</log>
</inSequence>
</target>
<description/>
</proxy>

Download the source of example here

1. https://docs.wso2.com/display/ESB470/Sample+380%3A+Writing+your+own+Custom+Mediation+in+Java