Showing posts with label WSO2. Show all posts
Showing posts with label WSO2. Show all posts

Tuesday, March 3, 2015

String concatenation in WSO2 ESB

There may some incidents where we want to concatenate two strings and create new string (value of a property ) in WSO2 ESB. Here I am using two property values and join them in to a new property.

1. Property #1

 <property name="myFirstProperty" value="WSO2"/>  

2. Property #2

<property name="mySecondProperty" value="ESB"/>

3. Concatenating above two properties

 <property name="ConcatenatedProperty" expression="fn:concat(get-property('myFirstProperty'),get-property('mySecondProperty')"/>

Note: You can provide any number of values to be concatenated in to the fn:concat() function.

Value of "ConcatenatedProperty" property is "WSO2ESB"


Thursday, January 22, 2015

How to send string content as the response from WSO2 ESB Proxy/API

We can send XML content or JSON content as the response out from our WSO2 ESB proxy/REST API. But there may be a scenario where we want to send string content (which is not in XML format) as the response of our service. Following synapse code snippet shows you how to do it

As an example think you have to send following string content to your client service

<result1>malintha</result1>+<result2>adikari</result2>

Note :
  • Above is not in XML format. So we cannot generate this directly through payload factory mediator.
  • We have to send <,> symbols inside the response, but WSO2 ESB doesn't allow to keep those inside your synapse configuration.
1. First you have to encode above expected response. You can use this tool to encode your xml. We get following xml after encoding in our example

&lt;result1&gt;malintha&lt;/result1&gt;+&lt;result2&gt;adikari&lt;/result2&gt;

Note : If you want to encode dynamic payload content you can use script mediator or class mediator for that task

2. Now we can attach the require string content to our payload as follows

 <outSequence>  
       <payloadFactory media-type="xml">  
         <format>  
          <ms11:text xmlns:ms11="http://ws.apache.org/commons/ns/payload">$1</ms11:text>  
         </format>  
         <args>  
          <arg value="&lt;result1&gt;malintha&lt;/result1&gt;+&lt;result2&gt;adikari&lt;/result2&gt;"/>  
         </args>  
       </payloadFactory>  
       <property name="messageType" value="text/plain" scope="axis2"/>  
       <send/>  
    </outSequence>  

Here we are using payload factory mediator to create our payload. You can see still our media-type is XML. Then load our string content as argument value and finally we change the message type to "text/plain". So this would return string content as it's response.

Monday, December 8, 2014

How to setup WSO2 p2 repo in your local machine

You can point wso2 p2 repository online through  http://dist.wso2.org/p2/carbon/releases/turing/ url (you can use any release replacing turing). But if you cannot fetch features from internet , better solution is set up whole p2 repo locally and then point to your local installation. Follow these steps to install and use it

1. Go to your prefferred folder to install p2_repo in.

mine is "/home/malintha/my_p2"

2. open terminal there and execute below command.

wget -r  -l inf -p -e robots=off http://dist.wso2.org/p2/carbon/releases/turing/

Note: Here "http://dist.wso2.org/p2/carbon/releases/turing/" is the URL of the p2 repo. Change it according to the release.

3. Now everything in p2 repo will be downloaded in to your local location.

4. After completion of the download you can use local path as

"/home/malintha/my_p2/dist.wso2.org/p2/carbon/releases/turing/" to point p2_repo local installed location when you need it