Friday, October 29, 2010

WSO2 Basketball finals 2010

QUALIFYING MATCHES
The 3rd annual WSO2 Basketball tournament was held over the month of October. We had 4 teams and 6 qualifying matches leading up to the finals. Wild Boars and Legions were the teams with the leading scores and they were chosen to be in the finals. When comparing with last 2 years, this time around every team had a balanced set of players. It can be seen by results of the preliminary round matches, where 3 teams had won 2 out of 3 matches they faced. Therefore, we had to choose the finalists by getting the accumulated scores of each team.

THE TEAMS
The Legions were led by our CEO, Dr. Sanjiva Weerawarna and the Wild Boars were led by our VP of Engineering, Samisa Abeysinghe.

====================================================
Legions | Wild Boars |
====================================================
Amal Rangana |Amila Suriyarachchi |
Chamara Silva |Asanka Abeysinghe (VC) |
Chanaka Jayasena |Asela Pathberiya |
Danushka Menikkumbura |Deependra Ariyadewa |
Flora Ariyapala |Dimuthu Leelarathne |
Gayani Rajanayake |Hasmin Abdul Cader |
Isuru Suriarachchi |Heshan Suriyarachchi |
Janath Sivayoganathan |Milinda Lakmal Pathirage |
Kalpani Wanigaratne |Nandika Jayawardana |
Mahesh Marcus |Rajika Kumasiri |
Sanjiva Weerawarana (C) |Samisa Abeysinghe (C) |
Srinath Perera |Sumedha Rubasinghe |
Tharindu Mathew |Udeshika Ratnavira |
Thilina Buddika |Thilanga Pitigala |
Waruna Ranasinghe |Anjana Fernando |
Miyuru Daminda |Yasith Nakandana |
Kasun Indrasiri |Lavi De Silva |
Gayani Marasinghe |Sanjaya Vithanagama |
Pavithra Madurangi |Denis Perera |
Arjuna Samaraweera |Shammi Jayasinghe |
Asiri Rathnayake |P.K.A. Thilini Ishaka |
Eshara Kalpanie Fonseka |Kathiravelu Pradeeban |
Janaka Ranabahu |Udayanga Wickramasinghe |
Sarasi Madushika |Pradeep Fernando |
Nirdesha Munasinghe |Hasini Gunasinghe |
Charith Wickramarachchi |Hasini Yatawatte |
Dinusha Dilrukshi |Sanjeewa Mallalgoda |
Manisha Ellaperuma | |
Meeyoni Fernando | |
====================================================

THE FINAL
It was a rain hit final and we played in our usual outdoor Basketball court - the car-park ;). Eventhough it was raining we could see the crowd standing around the court and cheering for their favourites.

The Legions started playing very aggressively from the word go and they were determind to not let the Championship slip away from them. Wildboars on the other hand was equal to the task and did not want to repeat the 2009 finals (in which WBs became runners up). It was an evenly contested match and The Legions were leading at half time whisle. Although they were leading, the Wild Boars were not too far behind (I can't recall the half-time score).

Then we started the second half. In the second half Wild Boars caught up to Legions score. I remember a point where the scores were levelled at 36-all. From this point onwards, non of the two teams didn't let the other take the lead for more than 2 points. It was showing the symptoms of going for an extra time ending.

FINAL WORKOUT
As the game progressed, I was getting the feeling that the game should be finished by now. So I asked Pumika who was near the stop clock, "how much time left?". She told me 30 seconds. I instantly thought of getting a timeout, but since we had the ball in our hand and we were attacking, I didnt want to take a timeout. (At that point if I took a timeout, it will inturn let the Legions know of the stop clock. Therefore, I opted not to take a timeout :) )

Asanka was controlling the ball at that time. I shouted at him "SHOOT! SHOOT!" (BTW, the scores were levelled at this point, 42-all). I don't know whether he heard my screms in the middle of the roar from the crowd. Anjana, Ude and I, was guarded by the defenders. Asanka, cleverly dribbled towards the baseline, which resulted in two defenders going towrds him to guard his move. That move, freed Samisa (the defender that should guard Samisa was now defending Asanka). Then Asanka passed the ball back to Samisa, who hit a long range 2 pointer to seal the win for the Wild Boars. That marked the end of a nail biting final. A final which I will remember for a long time. :)



Hats off to Legions for giving such a good game and in my book, both the teams were winners that night. They both fought hard to win the Championship. If you have a look back at the Legions past performances, this is a significant improvement from their side.

SCORE SHEETS

==============================================================
Date | Teams |Score
==============================================================
Wednesday 6th 4.00 pm | Cloud bots Vs. Titans |31:53
Thursday 7th 4.00 pm | Legion Vs. Wild Boars |23:34
Tuesday 12th 4.00 pm | Titans Vs. Wild Boars |33:28
Thursday 14th 4.00 pm | Cloud bots Vs. Legion |22:54
Tuesday 19th 4.00 pm | Cloud bots Vs. Wild Boars |34:61
Thursday 21st 4.00 pm | Titans Vs. Legion |29:40
Tuesday 26th 4.00 pm | Cloud bots Vs. Titans |41:72
Thursday 28th 7.00 pm | Wild Boars Vs. Legions |44:42
==============================================================

OBSERVAIONS
Piyumika was the main person responsible for organizing this year's tournament. She had given attention to detail in organizing this very successful event which everyone enjoyed very much. I take this opportunity to thank (on behalf of all the players) Piyumika and her team for making this a memorable night. Specially the idea to bring in a face painter added color to the event :).

I take the this opportunity to thank the crowd (who came to cheer for us or against us) who supported the players throughout this tournament. If it wasn't for ya'll it wont be an entertaining tournament like this.

As Isuru pointed out the other day, we did not have any serious injuries (broken bones, torn muscles, etc:) ) during this tournament. That means we are starting to play real Basketball and we have moved away from playing the Rugby+Basketball [2] hybrid, that we were used to play :D.

I am finishing off this post with an extract from a Fort Minor song.

This is ten percent luck, twenty percent skill
Fifteen percent concentrated power of will
Five percent pleasure, fifty percent pain
And a hundred percent reason to remember the name


Related Posts
[1] - http://heshans.blogspot.com/2008/10/internship-wso2.html
[2] - http://heshans.blogspot.com/2009/10/basketball-wso2-how-to-survive.html

Pictures courtesy of Chinthana Wilmuna.

Monday, October 25, 2010

Generate custom Error messages with WSO2 ESB

In this blogpost we will be looking at how to generate a soap fault using the makefault mediator. In addition to that I will show how to embed a custom message within that soap fault. Inorder to achieve this goal we will be using the makefault mediator and a script mediator.

The Synapse configuration used:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<localEntry key="detailsTransformScript" src="file:repository/samples/resources/script/detailTransform.js"/>
<sequence name="myFaultHandler">
<property name="uniqueKey" value="123" scope="default" type="STRING"/>
<property name="customErrorCode" value="8719" scope="default" type="STRING"/>
<property name="customErrorText" value="Issue has " scope="default" type="STRING"/>
<property name="customTime" expression="get-property('SYSTEM_DATE')" scope="default" type="STRING"/>
<script language="js" key="detailsTransformScript" function="transformDetail"/>
<log level="custom">
<property name="Detail" expression="get-property('customErrorDetail')"/>
</log>
<makefault version="soap11">
<code xmlns:tns="http://www.w3.org/2003/05/soap-envelope" value="tns:Receiver"/>
<reason expression="get-property('ERROR_MESSAGE')"/>
<detail expression="get-property('customErrorDetail')"/>
</makefault>
<send/>
</sequence>
<sequence name="fault">
<log level="full">
<property name="MESSAGE" value="Executing default "fault" sequence"/>
<property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
<property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
</log>
<drop/>
</sequence>
<sequence name="main" onError="myFaultHandler">
<in>
<switch xmlns:m0="http://services.samples" source="//m0:getQuote/m0:request/m0:symbol">
<case regex="MSFT">
<send>
<endpoint name="endpoint_urn_uuid_F3FC39CF93F681A11649593938524451942754528">
<address uri="http://bogus:9000/services/NonExistentStockQuoteService"/>
</endpoint>
</send>
</case>
<case regex="SUN">
<send>
<endpoint name="endpoint_urn_uuid_F3FC39CF93F681A1164959398253284-1608236576">
<address uri="http://localhost:9009/services/NonExistentStockQuoteService"/>
</endpoint>
</send>
</case>
</switch>
<drop/>
</in>
<out>
<send/>
</out>
</sequence>
</definitions>

The javascript file used in the script mediator:

function transformDetail(mc) {
var symbol = mc.getPayloadXML()..*::Code.toString();
var errorCode = mc.getProperty("customErrorCode");
var errorText = mc.getProperty("customErrorText");
var time = mc.getProperty('customTime');
mc.setProperty("customErrorDetail", <AppErrorCode><TimeStamp>{time}</TimeStamp><ErrorCode>{errorCode}</ErrorCode><ErrorText>{errorText}</ErrorText></AppErrorCode>);
}

Instructions to run the sample.
1) Copy the attached javascript file to ESB_HOME/repository/samples/resources/script/ directory.

2) Startup the ESB instance. Copy the attached synapse configuration to source view of the Management UI and hit update.

3) Start the Axis2 server and deploy the SimpleStockQuoteService if not already done.

4) Execute the client using following command.

ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT

5) Monitor the response message with TCPMon.

HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset=UTF-8
Host: 127.0.0.1:8281
SOAPAction: "urn:getQuote"
Date: Thu, 21 Oct 2010 09:52:23 GMT
Transfer-Encoding: chunked

338
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:MessageID>urn:uuid:952C448142FB1B1FE925278283667424-1166645935</wsa:MessageID>
<wsa:Action>urn:getQuote</wsa:Action>
<wsa:RelatesTo>urn:uuid:6DDD0BCE4CDCFB5AFD1287654743750</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
<soapenv:Fault>
<faultcode xmlns:tns="http://www.w3.org/2003/05/soap-envelope">tns:Receiver</faultcode>
<faultstring>Connection refused or failed for : bogus:9000, IO Exception occured : bogus</faultstring>
<detail>
<AppErrorCode>
<TimeStamp>10/21/10 3:22 PM</TimeStamp>
<ErrorCode>8719</ErrorCode>
<ErrorText>A custom issue has occured</ErrorText>
</AppErrorCode></detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>0

As you can see we have added a custom details element which is containing some information that you would like to generate.

Further Reading

[1] - Refer transport ERROR codes in https://svn.apache.org/repos/asf/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java

[2] - Property Mediator section of the WSO2 ESB Configuration language
http://wso2.org/project/esb/java/3.0.1/docs/configuration_language.html#property

[3] - WSO2 ESB error handling samples.
http://wso2.org/project/esb/java/3.0.1/docs/samples/message_mediation_samples.html#Sample4
http://wso2.org/project/esb/java/3.0.1/docs/samples/message_mediation_samples.html#Sample5

[4] - We are having built in Error Codes for transport related errors. Say for instance that you need to handle an error related to an XML format error. That kind of issues can be resolved by using fault handlers.
eg: If a sequence fail in an XSLT transformation phase due to to an XML format error, you can register a fault handler for a sequence to handle it. For more information read Error Handling with Sequences and Proxy Services .

Tuesday, October 19, 2010

Send HTML format email from WSO2 ESB

1. Enable mail transport sender and transport listener in the axis2.xml.

<transportSender name="mailto" <transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
<parameter name="mail.smtp.host">smtp.gmail.com</parameter>
<parameter name="mail.smtp.port">587</parameter>
<parameter name="mail.smtp.starttls.enable">true</parameter>
<parameter name="mail.smtp.auth">true</parameter>
<parameter name="mail.smtp.user">synapse.demo.0</parameter>
<parameter name="mail.smtp.password">mailpassword</parameter>
<parameter name="mail.smtp.from">synapse.demo.0@gmail.com</parameter>
</transportSender>

<transportReceiver name="mailto" class="org.apache.axis2.transport.mail.MailTransportListener"/>

2. Register the ApplicationXMLFormatter as the formatter for text/html content type in the axis2.xml

&lt:messageFormatter contentType="text/html" class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>

3. In the mediation sequence, set the messageType property as well as the ContentType property to text/html (Setting both parameters is crucial to get this working. The messageType parameter is looked up by the mail transport to select the correct formatter. The other property is used by the formatter to set the right content type on the outgoing message.)

The sample proxy configuration is attached for your reference.

<proxy name="StockQuoteProxy" transports="http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<property name="Subject" value="Custom Subject for Response" scope="transport"/>
<property name="messageType" value="text/html" scope="axis2"/>
<property name="ContentType" value="text/html" scope="axis2"/>
<property name="OUT_ONLY" value="true"/>
<script language="js"><![CDATA[
mc.setPayloadXML(<h1>WSO2 ESB Rocks!</h1>);
]]></script>
<log level="full"/>
<send>
<endpoint>
<address uri="mailto:test@test.com"/>
</endpoint>
</send>
</inSequence>
</target>
</proxy>

4. To test the sample, simply send a request to the sample proxy service using the sample Axis2 client. That will send an e-mail with in-line HTML content to the target endpoint.

eg.

wso2esb-3.0.0/samples/axis2Client$ ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy

Friday, October 8, 2010