Monday, April 17, 2017

How to send out the header "JMS_COORELATION_ID" with the message in WSO2 ESB.

In order to send the  "JMS_COORELATION_ID" with the message from wso2 ESB you are required to configure it as a transport header in the synapse configuration.

Hence, the property you need to configure is as below:

 <property name="JMS_COORELATION_ID" value="12345" scope="transport"/>

Please find the proxy configuration below which we tested the above property:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="SMSForwardProxy"
       transports="jms"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="JMS_COORELATION_ID" value="12345" scope="axis2"/>
         <send>
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>text/xml</default>
      </rules>
   </parameter>
   <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
   <parameter name="transport.jms.DestinationType">queue</parameter>
   <parameter name="transport.jms.Destination">SMSStore</parameter>
   <description/>
</proxy>

With the above configuration we managed to send the "JMS_COORELATION_ID" with the message out from the ESB. Please find the logs below:

[2017-04-13 16:19:29,648] DEBUG - wire << "POST /services/SimpleStockQuoteService HTTP/1.1[\r][\n]"
[2017-04-13 16:19:29,648] DEBUG - wire << "JMS_DESTINATION: SMSStore[\r][\n]"
[2017-04-13 16:19:29,648] DEBUG - wire << "JMS_MESSAGE_ID: ID:45c1d2d1-4c1c-3bb7-b249-9af5f0dcf7bf[\r][\n]"
[2017-04-13 16:19:29,648] DEBUG - wire << "JMS_REPLY_TO: SMSReceiveNotificationStore[\r][\n]"
[2017-04-13 16:19:29,648] DEBUG - wire << "JMS_QPID_DESTTYPE: 1[\r][\n]"
[2017-04-13 16:19:29,648] DEBUG - wire << "JMS_PRIORITY: 4[\r][\n]"
[2017-04-13 16:19:29,648] DEBUG - wire << "JMS_TIMESTAMP: 1492080567188[\r][\n]"
[2017-04-13 16:19:29,649] DEBUG - wire << "JMS_EXPIRATION: 0[\r][\n]"
[2017-04-13 16:19:29,649] DEBUG - wire << "JMS_COORELATION_ID: 12345[\r][\n]"
[2017-04-13 16:19:29,649] DEBUG - wire << "Accept-Encoding: gzip,deflate[\r][\n]"
[2017-04-13 16:19:29,649] DEBUG - wire << "JMS_REDELIVERED: false[\r][\n]"
[2017-04-13 16:19:29,649] DEBUG - wire << "Content-Type: text/xml; charset=UTF-8[\r][\n]"   

Sunday, April 16, 2017

How to install SCIM feature to WSO2 APIM 2.1.0

By default SCIM feature is not available in APIM. You could enable the SCIM feature using the pom.xml based approach. Please find the steps below to enable SCIM feature in APIM 2.1.0 using pom.xml based approach.

  • Downloaded the p2 repo from [1] (WSO2 Carbon 4.4.x (Wilkes))
  • Download the wso2am-2.1.0.zip from [2].
  • Unzip wso2am-2.1.0.zip and p2-repo.zip into the same directory.
  • Create a pom.xml file including below configuration and copy into the same directory.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">     <modelVersion>4.0.0</modelVersion>     <groupId>org.wso2.sample</groupId>     <artifactId>sample-feature-installation</artifactId>     <version>1.0.0</version>     <packaging>pom</packaging>     <name>New feature</name>     <url>http://wso2.org</url>     <build>         <plugins>            <plugin>                 <groupId>org.wso2.maven</groupId>                 <artifactId>carbon-p2-plugin</artifactId>                 <version>1.5.4</version>                 <executions><                     <execution>                         <id>feature-install</id>                         <phase>package</phase>                         <goals>                             <goal>p2-profile-gen</goal>                         </goals>                         <configuration>                             <profile>default</profile>                             <metadataRepository>file:p2-repo</metadataRepository>                             <artifactRepository>file:p2-repo</artifactRepository>                             <destination>wso2am-2.1.0/repository/components</destination>                             <deleteOldProfileFiles>false</deleteOldProfileFiles>                             <features>                                 <feature>                                     <id>org.wso2.carbon.identity.scim.feature.group</id>                                     <version>5.2.0</version>                                 </feature> <feature>                                     <id>org.wso2.carbon.identity.provisioning.server.feature.group</id>                                     <version>5.7.5</version>                                 </feature>                             </features>                         </configuration>                     </execution>                 </executions>             </plugin>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-antrun-plugin</artifactId>                 <version>1.1</version>                 <executions>                     <execution>                         <phase>package</phase>                         <configuration>                             <tasks>                                 <replace token="false" value="true" dir="wso2am-2.1.0/repository/components/default/configuration/org.eclipse.equinox.simpleconfigurator">                                     <include name="**/bundles.info"/>                                 </replace>                             </tasks>                         </configuration>                         <goals>                             <goal>run</goal>                         </goals>                     </execution>                 </executions>             </plugin>         </plugins>     </build>     <repositories>         <repository>             <id>wso2-nexus</id>             <name>WSO2 internal Repository</name>             <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>             <releases>                 <enabled>true</enabled>                 <updatePolicy>daily</updatePolicy>                 <checksumPolicy>ignore</checksumPolicy>             </releases>         </repository>     </repositories>     <pluginRepositories>         <pluginRepository>             <id>wso2-maven-releases-repository</id>             <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>         </pluginRepository>         <pluginRepository>             <id>wso2-maven-snapshots-repository</id>             <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>         </pluginRepository>     </pluginRepositories> </project>
  • Run below command:
mvn clean install
  • Enable SCIM for the primary user store from user-mgt.xml file as follows
<Property name="SCIMEnabled">true</Property>
  • Start the server.

Thursday, April 13, 2017

How to read/write files using VFS transport in WSO2 ESB

To enable the VFS transport
Edit the <ESB_HOME>/repository/conf/axis2/axis2.xml file and uncomment the VFS listener and the VFS sender as follows:

<transportreceiver name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportListener"/>
<transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender"/>

Create a folder structure as below:
├── Pass ├── Original ├── Failures ├── output
             ├── test.xml 

Configure the below proxy in WSO2 ESB.

<proxy name="testVFS" startonload="true" trace="disable" transports="https http vfs" xmlns="http://ws.apache.org/ns/synapse">
   <description>
   <target>
      <insequence>
         <property name="transport.vfs.ReplyFileName" scope="transport" value="myfile.xml">
         <property name="OUT_ONLY" value="true">
         <send>
            <endpoint>
               <address uri="vfs:file:///home/ubuntu/output">
            </address>
</endpoint>
         </send>
      </property></property></insequence>
   </target>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/ubuntu/Pass</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/ubuntu/Original</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/ubuntu/Failures/</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
   <parameter name="transport.vfs.ContentType">application/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</description>
</proxy>

Our proxy will automatically poll for files in the given location.

  • test.xml file will be located in file:///home/ubuntu/Pass
  • myfile.xml will get created in the file:///home/ubuntu/output folder

Wednesday, April 12, 2017

Configuring WSO2 ESB 4.8.1 with File Connector Version 2 to read a text file

Please note that File connector Version 2 is not supported with WSO2 ESB 4.8.1. To make the file connector V2 to be supported with ESB 4.8.1 you are required to upgrade the commons-net orbit bundle in ESB 4.8.1.

All you need to do is to get a copy of the commons-net_3.3.0.wso2v1.jar from a ESB 4.9.0 pack which could be found on <ESB_4.9.0_HOME>/repository/components/plugins and apply it to <ESB_4.8.1_HOME>/repository/components/dropins. 

Restart the ESB 4.8.1 server after applying the commons-net_3.3.0.wso2v1.jar.

Please follow below steps in order to read a text file using file connector V2 in ESB 4.8.1. 

Upload the file connector V2 and enable it. 
Create a file and add a text value to it. Here we added below text value to the text file.
 hello Shadsha 
Create a pass-through proxy service in ESB. Please find the proxy configuration below: (As the source path specify the path to the above created text file)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="testProxy"
       transports="https http"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target>
      <inSequence>
         <fileconnector.read>
            <source>/home/ubuntu/Desktop/file/file1.txt</source>
            <contentType>text/plain</contentType>
            <encoding>utf-16le</encoding>
         </fileconnector.read>
         <log level="full"/>
         <respond/>
      </inSequence>
   </target>
</proxy>

Send a request to the proxy service and you will be able to see the logs as below:
[2017-04-11 16:30:37,677]  INFO - LogMediator To: /services/Proxy1, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:6680285b-32e6-4d23-887f-22b65f5ea002, Direction: request, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">hello Shadsha</text></soapenv:Body></soapenv:Envelope>

Friday, April 7, 2017

Configuring WSO2 ESB with File Connector Version 2 to read a text file

This blog illustrates on how to use  File Connector Version 2 with WSO2 ESB 4.9.0/5.0.0. In here we are reading a simple text file using file connector.

Download the File Connector Version 2 from here.
Download ESB from here.

In this example, we will be using WSO2 ESB 4.9.0 with file connector version 2.0.7. In order to install the file connector you are required to start the ESB instance using below command: (<ESB_HOME>/bin)
 ./wso2server.sh

To add a connector:

  • On the Main tab in the ESB Management Console, under Connectors click Add.
  • Click Browse, specify the ZIP file, and click Open.
  • Click Upload.
  • The connector will now appear in the Connectors list and is ready to be enabled in your ESB instance.

To enable a connector:

  • On the Main tab in the ESB Management Console, under Connectors click List to view the uploaded connectors.
  • Click Enable next to a connector you want to enable, and then confirm that you want to change its status. 

Create a file and add a text value to it. Here we added below text value to the text file.
 hello Shadsha 
Create a pass-through proxy service in ESB. Please find the proxy configuration below: (As the source path specify the path to the above created text file)
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="testProxy"
       transports="https http"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target>
      <inSequence>
         <fileconnector.read>
            <source>/home/ubuntu/Desktop/file/file1.txt</source>
            <contentType>text/plain</contentType>
            <encoding>utf-16le</encoding>
         </fileconnector.read>
         <log level="full"/>
         <respond/>
      </inSequence>
   </target>
</proxy>

Send a request to the proxy service and you will be able to see the logs as below:
[2017-04-07 14:26:50,898]  INFO - LogMediator To: /services/Proxy1, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:f7270bb4-5935-4bca-828b-c5ad7f8fc9bb, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">hello Shadsha
</text></soapenv:Body></soapenv:Envelope>

Thursday, April 6, 2017

How to test if the registry is mounted properly in a WSO2 ESB Worker Manager Cluster.

In this article I will elaborate the steps required to test the registry mounting in a WSO2 ESB Worker Manager Cluster.

1. Create a file named abc.txt in the registry ("/_system/governance" path) with the below configuration.

<property name="test" value="Sampletest"/>

2. Add the below proxy service to the manager node.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="testProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom">
            <property name="###########symbol#########"
                      expression="get-property('registry','gov:/abc.txt')"/>
         </log>
         <drop/>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
      <endpoint>
         <address uri="http://www.google.com"/>
      </endpoint>
   </target>
   <description/>
</proxy>


3. Send a single request to a worker and look for a log as below.

[2016-10-05 21:47:04,728]  INFO - LogMediator ###########symbol######### = <property name="test" value="Sampletest"/>

4. Change the registry saved value to "Sampletest123".

5. Send another request to the worker after changing the above resource value and look for a log as below. See whether it has logged the changed property value. If it has changed that means registry mounting works properly.

[2016-10-05 21:48:06,488]  INFO - LogMediator ###########symbol######### = <property name="test" value="Sampletest123"/>

Please refer [1] for clustering WSO2 ESB.

[1] https://docs.wso2.com/display/CLUSTER44x/Clustering+ESB+4.9.0#ClusteringESB4.9.0-Configuringtheloadbalancer

Wednesday, April 5, 2017

How to Install Oracle Java on Ubuntu Linux

As WSO2 products require to have Java installed, this article will guide you through the process of installing Java 7 on Ubuntu environment.

First, add Oracle's PPA, then update your package repository.

sudo add-apt-repository ppa:webupd8team/java

sudo apt-get update

To install JDK 7, use the following commands:

sudo apt-get install oracle-java7-installer

sudo apt-get install oracle-java7-set-default

Edit the system PATH file /etc/profile and add the following system variables to your system path. Use gedit, nano or any other text editor, as root, open up /etc/profile.

To open in gedit use below command:

sudo gedit /etc/profile

Scroll down to the end of the file using your arrow keys and add the following lines below to the end of your /etc/profile file:

If you are installing the JDK use below configuration (note: you are required to change the $JAVA_HOME as per the jdk location on your computer):

JAVA_HOME=/usr/local/java/jdk1.7.0_45
JRE_HOME=$JAVA_HOME/jre
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

Or if you are installing the JRE use below:

JRE_HOME=/usr/local/java/jre1.7.0_45
PATH=$PATH:$JRE_HOME/bin
export JRE_HOME
export PATH

Save the /etc/profile file and exit.

Tuesday, April 4, 2017

How to enable Hazelcast Debug logs in WSO2 ESB 4.9.0

In order to enable Hazelcast Debug logs browse to <ESB_HOME>/repository/conf/etc/logging-bridge.properties file.

Configure the below in logging-bridge.properties file.

com.hazelcast.level = DEBUG

In order to get the effects restart is required and you could see similar logs as below which are related to Hazelcast:

[2017-02-17 11:07:49,325]  INFO - ClusterGroupCommunicator Task [ESB_TASK] member departed [Member [172.22.217.136]:4200], rescheduling missing tasks...
[2017-02-17 11:07:49,699]  WARN - BasicMapContextQuerySupport [172.22.217.136]:4300 [wso2.esb.domain] [3.5.3] Could not get results
java.util.concurrent.ExecutionException: com.hazelcast.spi.exception.TargetNotMemberException: Not Member! target:Address[172.22.217.136]:4200, partitionId: -1, operation: com.hazelcast.map.impl.operation.QueryOperation, service: hz:impl:mapService

Monday, April 3, 2017

How to cluster ActiveMq with WSO2 ESB

This tutorial will illustrate how to configure Activemq(5.8.0) cluster with WSO2 ESB 5.0.0.

Download ActiveMQ


Download WSO2 ESB 5.0.0


Clustering ActiveMQ

There is no special configuration required for ActiveMQ clustering you only need to extract two ActiveMQ instances and host them in two different IP host or change the port if the ActiveMQ instances are in same IP host.

Start ActiveMQ

cd [activemq_install_directory]
bin/activemq start


Copy Jars to WSO2 ESB

If you are using ActiveMQ version 5.8.0 or later, copy following jars  to <ESB_HOME>/repository/components/lib directory.

  • activemq-broker-5.8.0.jar
  • activemq-client-5.8.0.jar
  • activemq-kahadb-store-5.8.0.jar 
  • geronimo-jms_1.1_spec-1.1.1.jar
  • geronimo-j2ee-management_1.1_spec-1.0.1.jar
  • geronimo-jta_1.0.1B_spec-1.0.1.jar
  • hawtbuf-1.9.jar
  • Slf4j-api-1.6.6.jar
  • activeio-core-3.1.4.jar (available in <AMQ_HOME>/lib/optional folder)

Enable JMS receiver for ESB

To enable the JMS transport listener, configure the following listener configuration related to ActiveMQ in <ESB_HOME>/repository/conf/axis2/axis2.xml file. Please note that we have configured the provider url as failover scenario here.

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
       <parameter name="myTopicConnectionFactory" locked="false">
           <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
           <parameter name="java.naming.provider.url" locked="false">failover:(tcp://xx.xx.xx:61616,tcp://xx.xx.xy:61616)</parameter>
           <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">TopicConnectionFactory</parameter>
            <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter>
       </parameter>
  
       <parameter name="myQueueConnectionFactory" locked="false">
           <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
           <parameter name="java.naming.provider.url" locked="false">failover:(tcp://xx.xx.xx:61616,tcp://xx.xx.xy:61616)</parameter>
           <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
            <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
       </parameter>
  
       <parameter name="default" locked="false">
           <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
           <parameter name="java.naming.provider.url" locked="false">failover:(tcp://xx.xx.xx:61616,tcp://xx.xx.xy:61616)</parameter>
           <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
            <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
       </parameter>
</transportReceiver>


Enable JMS sender for ESB

To enable the JMS transport sender, un-comment the following configuration in <ESB_HOME>/repository/conf/axis2/axis2.xml file.

<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>



For more information on activemq clustering refer [1].


[1] http://activemq.apache.org/clustering.html