Thursday, August 17, 2017

How to share folders between Ubuntu and Windows running in Virtualbox

Step 1 : Create a directory called “vmsharedfiles”  in Ubuntu.

Step 2: Open up virtualbox instance.

Go to top menu and Click on Devices → Shared Folders → Shared Folders Settings.

If you are getting any error like “The VirtualBox Guest Additions do not appear to be available on this virtual machine, and shared folders cannot be used without them. To use shared folders inside the virtual machine, please install the Guest Additions if they are not installed, or re-install them if they are not working correctly, by selecting Insert Guest Additions CD image from the Devices menu. If they are installed but the machine is not yet fully started then shared folders will be available once it is.”, select the Devices option from VirtualBox's menu bar, and click on the Install Guest Additions CD Image option. Guest Additions installer will start automatically.
Follow the instructions to install.

Step 3 : Click on the green folder icon to Add new shared folder option in the right hand side.

Step 4 : You will prompt to the screen to select the folder you created in step 1. Select that folder and click open. And check “Make Permanent” option.

Step 5 : Go to My computer → computer → Map network drive → Map network drive.
You will see the screen below:

Step 6 : Click on Browse to select the shared folder that is created on step 1. Click OK and Finish.

Step 7 : Then this shared folder will be added to the My computer section.

Step 8 : Now you can access “vmsharedfiles” folder  in Ubuntu from Windows 10 in virtualBox.

How To Install Windows 10 In VirtualBox in Linux

Step 1: Download Windows 10 ISO

The first and foremost step is to download Windows 10 ISO. You can download Windows 10 32 bit or 64 bit, depending upon your system.

Step 2: Install Windows 10 in VirtualBox

Start VirtualBox. You should see a screen like the one below. Click on new:

Name the VM. Select the Operating System and version, in this case Windows 10 and 64 bit for me. Choose RAM size. Next is the size for the virtual machine.

You can choose where to create the virtual disk. Default location (Home directory). For hard disk file type select VDI format.

After successful creation, You should be back to start screen. Click on Settings. Go to Storage and select the Empty disk. Under Attributes section, select disk icon to select the windows 10 ISO file for Optical Drive option.

You should be back to the main screen of VirtualBox.You have everything ready now. Next step is to install Windows 10. Click on Start from the main screen. Now You should see the Windows boot screen: After that you can do normal installation of windows 10.

If you didn’t get the above screen and getting the error as below.

Go to BIOS by press F1. Under security tab select virtualization. Enable VT option.

How to Install Latest VirtualBox 5.1 on Ubuntu 16.04

VirtualBox is a free and open-source virtualization software. It can run on Linux, Mac, Windows.

If you have already installed VirtualBox from Ubuntu repository, remove it with:

sudo apt remove virtualbox

Next, open /etc/apt/sources.list file:

sudo nano /etc/apt/sources.list

Append the following line at the end of this file.

deb xenial contrib

Press Ctrl+O to save the file. Then press Ctrl+X to close the file.
Now fetch the Oracle GPG public key and import it to your Ubuntu 16.04 system with the following command so packages downloaded from Oracle repository can be verified.

wget -q -O- | sudo apt-key add -

Then update local package index and install Virtualbox.

sudo apt update
sudo apt install virtualbox

Thursday, March 9, 2017

Invoke Salesforce REST API APEX classes using synapse mediators in WSO2 ESB

Invoke through sample synapse config(API/ Sequence/ Proxy) using following steps :

  • Download the salesforce REST connector from store.
  • Here, we use salesforce REST connector to maintain the access token and get the access token from the refresh token.
  • Open the <ESB_HOME>/repository/conf/axis2/axis2.xml and add the <parameter name="HttpsProtocols">TLSv1.1,TLSv1.2</parameter> entry inside the PassThroughHttpSSLSender element as below :
<transportSender name="https" class="org.apache.synapse.transport.passthru.PassThroughHttpSSLSender">
 <parameter name="HttpsProtocols">TLSv1.1,TLSv1.2</parameter>
  • Start the WSO2 ESB Server.
  • Navigate to the management console and deploy the downloaded connector.
  • Click the Main tab on the Management Console, go to Manage -> Services and then click Proxy Service -> Custom Proxy. Click on switch to source view. Then add following and click on Save.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns=""
         <property expression="json-eval($.accessToken)" name="accessToken"/>
         <property expression="json-eval($.apiVersion)" name="apiVersion"/>
         <property expression="json-eval($.hostName)" name="hostName"/>
         <property expression="json-eval($.refreshToken)" name="refreshToken"/>
         <property expression="json-eval($.clientSecret)" name="clientSecret"/>
         <property expression="json-eval($.clientId)" name="clientId"/>
         <property expression="json-eval($.registryPath)" name="registryPath"/>
         <property expression="json-eval($.intervalTime)" name="intervalTime"/>
         <property expression="json-eval($.inputPayload)" name="inputPayload"/>
         <property expression="json-eval($.httpMethod)" name="httpMethod"/>
         <property expression="json-eval($.apexInstanceUrl)" name="apexInstanceUrl"/>
         <property expression="json-eval($.namespacePrefix)" name="namespacePrefix"/>
         <property expression="json-eval($.apexclassName)" name="apexclassName"/>
         <property expression="json-eval($.urlParameters)" name="urlParameters"/>
         <payloadFactory media-type="json">
               <arg evaluator="xml" expression="get-property('inputPayload')"/>
         <script language="js">//url param variables
                var namespacePrefix = mc.getProperty("namespacePrefix");
                var urlParameters = mc.getProperty("urlParameters");
                //url param processing start
                var urlParamString = '';
                if (namespacePrefix != "" &amp;&amp; namespacePrefix != null) {
                namespacePrefix = namespacePrefix + '/';
                if (urlParameters != null &amp;&amp; urlParameters != "" &amp;&amp; urlParameters != {}) {
                var txt = '{"fieldValuesList":' + urlParameters + '}';
                var obj = eval ("(" + txt + ")");
                for(var key in obj.fieldValuesList){
                var fieldValue = obj.fieldValuesList[key];
                var field = key;
                urlParamString += field + "=" + fieldValue + "&amp;";
                if(urlParamString != '') {
                urlParamString = '?' + urlParamString.toString().substring(0, urlParamString.toString().lastIndexOf("&amp;"));
                mc.setProperty('uri.var.namespacePrefix', namespacePrefix);
                mc.setProperty('uri.var.urlParamString', urlParamString);
                //url param processing end</script>
         <property action="remove" name="Accept-Encoding" scope="transport"/>
         <property expression="$ctx:apexInstanceUrl" name="uri.var.apexInstanceUrl"/>
         <property expression="$ctx:apexclassName" name="uri.var.apexclassName"/>
         <filter xpath="($ctx:httpMethod = 'post' or $ctx:httpMethod = 'POST')">
                     <http method="POST"                           uri-template="{uri.var.apexInstanceUrl}/services/apexrest/{+uri.var.namespacePrefix}{uri.var.apexclassName}{+uri.var.urlParamString}"/>
         <filter xpath="($ctx:httpMethod = 'get' or $ctx:httpMethod = 'GET')">
                     <http method="GET"                           uri-template="{uri.var.apexInstanceUrl}/services/apexrest/{+uri.var.namespacePrefix}{uri.var.apexclassName}{+uri.var.urlParamString}"/>
         <filter xpath="($ctx:httpMethod = 'put' or $ctx:httpMethod = 'PUT')">
                     <http method="PUT"                           uri-template="{uri.var.apexInstanceUrl}/services/apexrest/{+uri.var.namespacePrefix}{uri.var.apexclassName}{+uri.var.urlParamString}"/>
         <filter xpath="($ctx:httpMethod = 'patch' or $ctx:httpMethod = 'PATCH')">
                     <http method="PATCH"                           uri-template="{uri.var.apexInstanceUrl}/services/apexrest/{+uri.var.namespacePrefix}{uri.var.apexclassName}{+uri.var.urlParamString}"/>
         <filter xpath="($ctx:httpMethod = 'delete' or $ctx:httpMethod = 'DELETE')">
                     <http method="DELETE"                           uri-template="{uri.var.apexInstanceUrl}/services/apexrest/{+uri.var.namespacePrefix}{uri.var.apexclassName}{+uri.var.urlParamString}"/>
         <filter xpath="($ctx:httpMethod = 'head' or $ctx:httpMethod = 'HEAD')">
                     <http method="HEAD"                           uri-template="{uri.var.apexInstanceUrl}/services/apexrest/{+uri.var.namespacePrefix}{uri.var.apexclassName}{+uri.var.urlParamString}"/>

  • Click the Main tab on the Management Console, go to Manage -> Services and then click List. Then click on “salesforceApex”. Under the Endpoints, you can find the http endpoint. With this http endpoint and the following request following payload, you can get the output. Here in this proxy service, we reuse the salesforce REST connector for refreshing the access token.
  "apiVersion": "v37.0",
  "clientId": "3MVG9YDQS5WtC11r7PwwtXgMbc11ddO8.v5fACou6XbISTmj5sWLnAFkgpXcjIxCJFtqfDsZL4.yunUQJaohk",
  "refreshToken": "5Aep861..zRMyCurAXnOWvxvIMAnUFVITuyCGAN6mPVNRczzrev5q9h0YI4m45COJYgeLgEorlUMZxm.YAeEE80",
  "clientSecret": "8631600822489897349",
  "hostName": "",
  "intervalTime" : "100000",
  "registryPath": "connectors/SalesforceRest",
  "namespacePrefix": "TestOrgNew",
  "urlParameters" : {
  "inputPayload" : {

Creating REST APIs using Apex REST

The Salesforce REST API allow you to integration with Salesforce applications using standard HTTP methods such as GET, POST, PUT, PATCH, DELETE, and HEAD. This API provides a way to expose the data you have within your Salesforce application to external applications.

Follow steps to create the Apex REST API. Under App Setup expand Developer and click Apex Classes. Click New to create a new class.

Paste the following code into Apex Class Editor:

global class WidgetController {

    global static List<Widget__c> getWidgets() {
        List<Widget__c> widgets = [SELECT Name from Widget__c];
        return widgets;

    global static String createNewWidget(String Name) {
        Widget__c w = new Widget__c();
        w.Name = Name;
        insert w;

        return '{"Status":"Done"}';

    global static String deleteWidgetById() {
        String Id = RestContext.request.params.get('Id');
        String status = RestContext.request.params.get('status');
        List<Widget__c> w = [ Select ID from Widget__c where Id= :Id];

        delete w;

        return '{"Status":"Deleted Widget"}' + status;

    global static String updateWidget(String Id, String NewName) {
        Widget__c w = [ Select ID, Name from Widget__c where Id= :Id];

        w.Name = NewName;
        update w;

        return '{"Status":"Widget Updated"}';

Tuesday, February 14, 2017

Sample ESB sequence and Inbound to receive the message from the queue using the ESB Amazon SQS streaming connector and then send that message into another queue using the ESB Amazon SQS connector

Sample ESB Sequence

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="request" onError="fault" xmlns="">
    <log level="custom">
        <property expression="$body/*" name="------------" xmlns:ns="http://org.apache.synapse/xsd"/>
    <property name="POST_TO_URI" scope="axis2" value="true"/>
    <call blocking="true">
            <http method="GET" uri-template=""/>
    <property expression="$body/*" name="messageBody" xmlns:ns="http://org.apache.synapse/xsd"/>

Sample ESB Inbound

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns=""
      <parameter name="inbound.behavior">polling</parameter>
      <parameter name="interval">2000</parameter>
      <parameter name="sequential">true</parameter>
      <parameter name="coordination">true</parameter>
      <parameter name="attributeNames">attributeName1,contentType</parameter>
      <parameter name="accessKey">xxxxxxxxxxxxxxxxxxxxxxxxxx</parameter>
      <parameter name="waitTime">19</parameter>
      <parameter name="maxNoOfMessage">10</parameter>
      <parameter name="secretKey">xxxxxxxxxxxxxxxxxxxxxxxxxxxx</parameter>
      <parameter name="contentType">text/plain</parameter>
      <parameter name="destination"></parameter>