Saturday, July 10, 2010

Sending XML content as a value in name value pair GET request using WSO2 ESB

In this blog post I am describing on how to invoke a RESTful service which required a GET request with name value pairs in the request including XML content to be there in one of the value. First I will describe on how to invoke a normal RESTful service via ESB.

If you want to send a request to a service like this

http://service.endpoint/ServiceName?name1=value1&name2=value2...

First create an address endpoint by keeping the address of http://service.endpoint and make the endpoint type as REST/GET if you are using the UI to configure ESB. So the Endpoint configuration will looks like this.

<endpoint xmlns="http://ws.apache.org/ns/synapse">
<address uri="http://service.endpoint/" format="get" >
<suspendOnFailure>
<initialDuration>10000</initialDuration>
<progressionFactor>1.0</progressionFactor>
<maximumDuration>30000</maximumDuration>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
<retryDelay>0</retryDelay>
</markForSuspension>
</address>
</endpoint>


You can simply send the content of the request like this

<ServiceName>
<name1>value1</name1>
<name2>value2</name2>
</ServiceName>

No matter what type of request you are sending because when WSO2 ESB start processing the request it sees only a soap message after getting called message builders and message formatters. So you can see that during the endpoint creation I have remove the ServiceName part from the endpoint since we are sending that in the request and when we mark the endpoint format=get Axis2 will add that part in to the HTTP GET request and append the name value pairs to the request and send the message properly.

So this scenario is very simple and now let's see a case where you need to send something more complex in a HTTP GET request. I came across a scenario where we need to send an encoded xml in the GET request including some of the normal name value pairs.

So the HTTP GET request looks like this,
Ex:
http://service.endpoint/ServiceName?name1=value1&name2=value2&name3=<encoded xml content>

In this kind of a scenario you might get confused on how do you have to send the request. First create an endpoint as if the above configuration by making the format as get. Then,if you are in a position that you can change the incoming request you can simply send the request content like this.

<ServiceName>
<name1>value1</name1>
<name2>value2</name2>
<name3><![CDATA[xmlcontent]]></name3>
</ServiceName>

When ESB send the message to the REST endpoint Axis2 will encode the content inside the CDATA and send the message properly as I have showed above. If you are not capable of sending the message with CDATA content you can simply send the required elements in the incoming request and do an XSLT transformation to create the message as above.



Friday, July 9, 2010

Keep live connection in WSO2 products with Mysql Server

When you are configuring WSO2 products with mysql there might be errors coming with normal configuration when you try to access the product console after a reasonable amount of time. So this is not an issue with the product neither Mysql server. You need to specifically configure to keep the connection live for a defined idle time. Please follow up the below steps to increase the timeout and make sure product will try to connect to the database once it timeouts.

1. Open the my.conf file in mysql installed machine( it's it's a linux machine it will be in /etc/my.conf and if it's a windows machine it will be there in your mysql installed directory) and add the following entries

wait_timeout=259200
interactive_timeout=259200
(this is the keep hte idle time out value for three days in seconds and if you want to keep more just increase the value)

2. Open the CARBON_HOME/repository/conf/registry.xml and CARBON_HOME/repository/conf/user-mgt.xml change url of the mysql database configuration like this

jdbc:mysql://localhost:3306/regdb2?autoReconnect=true

appened "?autoReconnect=true" element to the url.


WSO2 ESB and Qpid setup Guide

This document explains how to do ESB + Qpid setup from the scratch which includes setting up ESB/QPID and registry instances and this Guide doesn't contains any internal message flow configurations of ESB. In this setup we are forwarding incoming messages to Qpid from ESB1 and ESB2 instance is picking messages from the Qpid instance and forward to another endpoint. For this scenario I am just explaining on how to setup the initial configuration and will be posting on how to configure message flows of ESB instances.

1. Download Qpid from here http://www.apache.org/dist/qpid/0.6/qpid-java-0.6.tar.gz and extract Qpid and and open the QPID_HOME/etc/config.xml
change enable ssl false as below.

<management>
<enabled>true</enabled>
<jmxport>8999</jmxport>
<ssl>
<enabled>false</enabled>
<!-- Update below path to your keystore location, eg ${conf}/qpid.keystore -->
<keyStorePath>${prefix}/../test-profiles/test_resources/ssl/keystore.jks</keyStorePath>
<keyStorePassword>password</keyStorePassword>
</ssl>
</management>

2. If you want to use qpid in a clustering mode and extract another qpid instance and do the step 1 and edit QPID_HOME/etc/config.xml and change the ports
configuration by editing port and sslport elements.

<port>5673</port>
<sslport>8673</sslport>

3. Start Qpid by running QPID_HOME/bin/qpid-server. If you are using a cluster start all the instances.


Configuring ESB instance which is forwarding incoming messages to Qpid instance

1. Create a server.properties file in CARBON_HOME/repository/conf/ directory and add the following entries to the properties file.

connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://10.3.24.99:5672'
destination.directQueue=direct://amq.direct//ServiceName
destination.replyQueue =direct://amq.direct//ServiceNameReply

In this configuration 10.3.24.99 is the IP address of the machine which Qpid is running and qpidConnectionfactory is a reference we are using for our reference in axis2.xml.

If you are using Qpid in a cluster please create another properties file and define the same configuration with a different file name and let's assume your slave configuration file is server1.properties.

2. Now open the CARBON_HOME/repository/conf/axis2.xml add the following entry

Adding transportRecievers

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
<parameter name="default" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">/home/wso2/WSO2_SETUP1/wso2esb-3.0.0-1/repository/conf/server.properties</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">qpidConnectionfactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
</parameter>
<parameter name="slave" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.qpid.jndi.PropertiesFileInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">/home/wso2/WSO2_SETUP1/wso2esb-3.0.0-1/repository/conf/server1.properties</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">qpidConnectionfactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
</parameter>
</transportReceiver>

Please change the java.naming.privider.url element according to your setup(colored in red).

Adding transportSenders

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

3. If you need only one Qpid instance please remove the second parameter list and keep the default configuration(parameter set with name="default") and note the name of the second parameter set is "slave" and
we need to use that configuration to be added in to synapse configuration when we configure failover endpoints.

4. Copy following jars in to CARBON_HOME/repository/components/lib directory and please download the merged jar from the given location and rest of the jars can be found in QPID_HOME/lib directory.
qpid-common-merged.jar http://people.apache.org/~lahiru/qpid-common-merged-0.6.jar
qpid-client-0.6.jar
slf4j-api-1.4.0.jar

5. Start the ESB instance by running CARBON_HOME/bin/wso2server.sh or .bat file, now it will connect to the Qpid instance running successfully.

Configuring ESB instance which picks incoming messages from Qpid and forward them to the actual service

Perform all the steps from step 1-5 in the ESB in main setup where we call the MemberVerification service directly. This ESB has to configure with Qpid to pick messages from the queues and send the request to the actual
service and once the response comes back put the reponse in to the reply queue defined in server.properties file.

But in the server.properties file you do not need to add a replyQueue in the configuration and and server.properties file looks like this.

connectionfactory.qpidConnectionfactory=amqp://guest:guest@clientid/test?brokerlist='tcp://10.3.24.99:5672'
destination.directQueue=direct://amq.direct//ServiceName

Assume 10.3.24.99 is the IP address of the machine where you run the Qpid instance.


I will be posting on how to configure two proxy services in ESB's to perform the above mentioned tasks in near future.



Monday, May 31, 2010

Configuring WSO2 ESB with Apache Qpid Java broker

Even though there are articles written on how to configure Synapse and Axis2 with Apache Qpid, with the latest releases of WSO2 ESB, those instructions are not valid anymore, so I am thinking of giving a small instructions on how to do those changes accordingly with latest ESB releases. WSO2 ESB is running on top of WSO2 Carbon framework which provides core capabilities of security,clustering logging facilities on top of OSGi environment. So obviously WSO2 ESB is running on top of OSGi environment. This concept cause some of the configurations we have to do with Qpid due to conflicting packaging of Apache Qpid artifacts. If we want to use apache Qpid as a client we need to pick few jar from Qpid distribution and copy them to CARBON_HOME/repository/components/lib directory.But two of those artifacts(qpid-commons and mina-core jars) they are using the same packaging structure calleds org.apche.mina.filter so this is become an issue in OSGi environment during the class loading time. So instead of those two artifacts please use the merged artifacts I have hosted her http://people.apache.org/~lahiru/qpid-common-merged-0.6.jar and use this article http://wso2.org/library/3663 to do the rest of the configurations to configure WSO2 ESB with Apache Qpid.
If you have any issue with Qpid configuration don't hesitate to post to carbon-dev@wso2.com

Saturday, February 20, 2010

Change the log file name dynamically using system properties

Recently I wanted the start multiple number of server instances using the same configuration so when I start nodes of the same server i should be having different log files for each instance starting in different location. So can be done very easy without writing a new appender or doing anything just configuring your log4j.properties file.

provide your log file name like this
log4j.appender.CARBON_LOGFILE.File=repository/logs/${instance.log}/wso2carbon${instance.log}.log

This is really nicely works due to few reasons. Once you set the log4j.properties file like this you can give set a system property for each instance you are starting with the name of "instance.log" and that will be picked before creating the log file and it will create the log file in the given location.

Ex: if you set the value of system property "instance.log" as "Instance1" it will create the log in location repository/logs/Instance1/wso2carbonInstance1.log.

This file name appending works very nicely and in normal scenarios you are not setting any system property and this will create the logs in the default location which is like this : repository/logs/wso2carbon.log. This appending is working very smoothly so you can append anything for the file name or to the directory name and and if you do not set the system property it will simply ignore that.

To get dynamic log files you do not have to write any code other than setting system property and change the log4j.properties files.

Tuesday, February 2, 2010

No such file or directory error when running Java

I recently had to install Ubuntu in to my machine after having some difficulty with my system files later I set up the available settings and started on working and I found this "No such file or directory" error when I run Java command or when I try to start up Intellij Idea or when I try to do a maven build. But this was totally stupid since I can see the file is there in the given path..

This happened because I have installed 64bit OS and used the JDK 32bit version and the error was totally weired to say No such file or directory.

If you get this error please change the JDK version in to 64bit or vice versa, if you have 32bit OS installed.

Sunday, January 31, 2010

First week at New place with the Family

We moved from Galle to Colombo last week and all of the family member are staying at the new place now. We have been living in Galle for years and later due to my fathers health situation we decided to move the Colombo. We rented a house near Nugegoda and relocated from Galle and I thought of writing a blog post on what I'm feeling during the first week of new place.

First I should thank Loku mama, Anoma Nanda, Yamuna Aunty and Micheal Uncle for helping us to get here and I would say that this place is awesome ... and I never expected to be a place like this. House is great and garden is pretty nice, good looking and good one to relax in the evening. My mom was working hard to unpack all the stuff and now we are almost done with the hard job.. I have been eating from cafes for more than four years during my stay at the University and last few months after I start working but now things are much better that I can have food from my mom .. :)
I felt bit boring during first couple of days because when I go out, I don't know anybody in that area nobody waves to me no one laughs and totally different feeling from what I used to have in Galle but I think I will get used to this life and important thing I'm concentrating is that i can always get to my parents within half an hour or may be within an hours from my work place.. that is what I lost last couple of years. Even though we have certain thing to be solved we are pretty good at the new place and thanks all of the relations and friends and neighbors who helped us to make things in to this stage.