Wednesday, February 17, 2016

[WSO2 ESB]Invoke Contentful API

Lets say we want to invoke Contentful API which contains the response with Content-Type:application/

1. First we tried setting the Accept header before send the message. But that didn't change the Content-Type of the  server response.
<header name="Accept" scope="transport" value="application/json"/>
2. The second attempt was to set the BinaryRelayBuilder and ExpandingMessageFormatter in the axis2.xml file under <messageBuilders> and <messageFormatters> sections.
<messageBuilder class="org.wso2.carbon.relay.BinaryRelayBuilder" contentType="application/"/>
<messageFormatter class="org.wso2.carbon.relay.ExpandingMessageFormatter" contentType="application/"/>
Now the message building error solved. But the response contains in binary format.
<ns:binary xmlns:ns="">-------CAgIH0KICAgICAgICBdCiAgICAg--------</ns:binary>
3. Finally we used the default json builder and formatter with our contentful media type(application/ to resolve the issue. (make sure to remove the configuration added in above 1 and 2 steps)
<messageBuilder class="org.apache.synapse.commons.json.JsonStreamBuilder" contentType="application/"/>
<messageFormatter class="org.apache.synapse.commons.json.JsonStreamFormatter" contentType="application/"/>

Thursday, February 11, 2016

[WSO2 ESB] How to remove default namespace at message enrich.

1.Lets say we need to add new element (eg: foo) to the message body using enrich mediator.

 <source type="inline" clone="true">
<target type="body" action="child"/>
2. After enriched, the  message will be as bellow.
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="">
        <foo xmlns="">test</foo>
3. You can see foo element contains with default synapse namespace.
4. You can avoid this adding empty namespace (xmlns="") to foo element in enrich mediator configuration.
 <source type="inline" clone="true">
 <foo xmlns="">test</foo>
<target type="body" action="child"/>

Friday, February 5, 2016

[WSO2 ESB] How to remove jsonObject root element from message body

Eg: Sample SOAP message

<soap:Envelope xmlns:soap="" xmlns:xsi="">

Eg: Sample ESB configuration.

        <source clone="true" xpath="$body/jsonObject/foo"/>
        <target type="body"/>

source :

Friday, January 22, 2016

[WSO2 ESB] Iterate and Aggregate mediators

Lets assume we have two services.

First : This returns list of market details
<soapenv:Envelope xmlns:soapenv="">
        <marketDetails xmlns="">
                    <name>New York</name>
Second: This returns the symbols of each market.
<soapenv:Envelope xmlns:soapenv="">
        <symbols xmlns="">
So we need to build a new service which returns all the symbols of all markets.

1. We need to iterate through the first response to get the market id and invoke the second service.
<property xmlns:m0="" name="MARKET_COUNT"
<iterate xmlns:soapenv="" xmlns:ns="http://org.apache.synapse/xsd"
        <payloadFactory media-type="xml">
                <soap:Envelope xmlns:soap=""
                        <getMarketSymbols xmlns="">
                <arg xmlns:m0="" 
expression="//m0:marketDetails/m0:marketDetail/m0:market/m0:id" evaluator="xml"/>
        <property name="messageType" value="application/soap+xml" scope="axis2"/>
            <endpoint xmlns="" name="SymbolEndpoint">
                <address uri="">
2. Use the aggregate mediator to collect all the symbols.
<property name="ECNCLOSING_ELEMENT" scope="default">
    <wrapper xmlns=""/>

<aggregate id="MARKET_ITERATOR">
    <messageCount min="{get-property('MARKET_COUNT')}" max="-1"/>
<onComplete xmlns:soapenv=""

Monday, January 18, 2016

[WSO2 ESB]Add new element to message body.

Sometime we need to add static content to the message response. Eg: privacy statement. So we can store the note in the registry and include to message body using the enrich mediator.

<property  expression="get-property('registry','gov:/note/PrivacyStatement_v1.0.0.xml')"
name="PrivacyStatement" scope="default" type="OM"/>

  <source xpath="$ctx:PrivacyStatement"/>
  <target action="sibling" type="body"/>