Wednesday, July 31, 2013

WSO2 ESB - Reading query parametres from a GET request

If you need to read query parameters from a GET request which received by a proxy service / REST API, you can use following xpath expression to read values of those parameters.

$url:<param_name>

example requesst :
GET http://localhost:8280/foo?a=1&b=2

and to log values of a and b

<log level="custom">
    <property name="VAL_a" expression="$url:a"/>
    <property name="VAL_b" expression="$url:b"/>
</log>

This xpath expression will be handy when working with REST integrations.

Wednesday, August 1, 2012

How to create simple mock services using WSO2 ESB

When you develop SOA systems, often you need to create mock services to simulate backend systems. Here is a easy way to create mock services using WSO2 ESB.

Create a proxy service in following format. Response of mock service will be content of payload factory mediator's format element.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="MyMockProxy" transports="http https"
       startOnLoad="true" trace="disable">
    <target>
        <inSequence>
            <payloadFactory>
                <format>
                    <Response xmlns="">
                        <status>OK</status>
                        <code>1</code>
                    </Response>
                </format>
            </payloadFactory>
            <header name="To" action="remove"/>
            <property name="RESPONSE" value="true" scope="default" type="STRING"/>
            <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
            <send/>
        </inSequence>
    </target>
</proxy>


Send a request to http://[your-ip]:8280/services/MyMockProxy and you will get

                    <Response xmlns="">
                        <status>OK</status>
                        <code>1</code>
                    </Response>

as the response!

Wednesday, June 20, 2012

java.lang.OutOfMemoryError: unable to create new native thread

You might encounter stack trace like:

java.lang.OutOfMemoryError: unable to create new native thread
        at java.lang.Thread.start0(Native Method)
        at java.lang.Thread.start(Thread.java:640)

 when your java code tries to spawn a new thread. It says OOM but probably it's not.

In Linux OS, there is a max allowed processes per user called "nproc" and if it's set to too low, JVM will fail to spawn a new thread and throw a OOM exception. 

You can check nproc by running following command

ulimit -u

and to change it

sudo vim /etc/security/limits.conf

and add following line with appropriate values.

{user_name} hard nproc {value}

Monday, March 5, 2012

Tracing message exchange in WSO2 ESB / Synapse

There might be situations where you need to trace the message on wire when working with WSO2 ESB/Synapse. You can use TCPMon to do is as I explained early[1], but it might be too complex and you might not able to trace messages if ESBs runs on remote servers (ESB is in your office, you are in home and connect to office via VPN).

Here is a simple solution:

Open lib/log4j.properties of WSO2 ESB / Synapse instance and add

log4j.category.org.apache.synapse.transport.nhttp.wire=DEBUG
and you will be able to see wire level messages in log file.


[1] http://miyuru-daminda.blogspot.com/2010/11/how-to-monitor-wso2-esb-traffic-using.html

Monday, February 20, 2012

Disable suspension of WSO2 ESB / Synapse Endpoint

The default behavior upon faulting a request of Synapse endpoint is, endpoint will suspend for 30000ms. During suspended time, synapse will not try to send further messages to suspended endpoint. However some deployment might need to turn off this behavior.

Here is a sample endpoint configuration which will never suspend for any error.


   <endpoint name="NoSuspendEndpoint">
       <address uri="http://localhost:9000/services/SimpleStockQuoteService">
           <timeout>
               <duration>30000</duration>
               <responseAction>fault</responseAction>
           </timeout>
           <suspendOnFailure>
               <errorCodes>-1</errorCodes>
               <initialDuration>0</initialDuration>
               <progressionFactor>1.0</progressionFactor>
               <maximumDuration>0</maximumDuration>
           </suspendOnFailure>
           <markForSuspension>
               <errorCodes>-1</errorCodes>
           </markForSuspension>
       </address>
   </endpoint>



Tuesday, September 27, 2011

Date Time addition using XSLT

I was searching in many places for a easy way to add dates using XSLT. Here is a sample that worked for me.
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
         xmlns:xs="http://www.w3.org/2001/XMLSchema"  
         xmlns:fn="http://www.w3.org/2005/xpath-functions"  
         version="2.0">  
   <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>  
   <xsl:template match="/">  
     <expiryDate xmlns="">  
       <xsl:value-of select="fn:current-date()+xs:dayTimeDuration('P1D')"/>  
     </expiryDate>  
   </xsl:template>  
 </xsl:stylesheet>  

Sunday, November 21, 2010

How to monitor WSO2 ESB traffic using TCPMon

Here I will explain how to use TCPmon with WSO2 ESB to monitor incoming and outgoing traffic between Client,WSO2 ESB Proxy Service and WSO2 ESB Proxy Service,Backend service.

TCPmon is bundled with WSO2 ESB installation. So you do not need to download it. You can find TCPmon executable in <WSO2_ESB_Installation>/bin/tcpmon.sh for Linux and <WSO2_ESB_Installation>/bin/tcpmon.bin for Windows.

You can find detailed TCPmon tutorial at [1].

I assume that you didn't changed default HTTP and HTTPS ports of WSO2 ESB which is 8280 for HTTP and 8243 for HTTPS.

To monitor HTTP traffic between client and WSO2 ESB.
  • Start TCPMon on machine runs WSO2 ESB
  • Goto Admin tab
  • Set Listen Port # as 8281 ( Assume that port 8281 is free on your system )
  • Leave Target Hostname as 127.0.0.1
  • Set Target Port # as 8280
  • Click Add
  • Goto Port 8281 tab

Now TCPmon is ready to capture traffic between client and WSO2 ESB.

When sending request to WSO2 ESB using client, use 8281 as the server port ( NOT 8280 ). So client will send request to 8281 which TCPmon runs and TCPmon will pass that request to WSO2 ESB which runs on 8280. You will able to monitor request/response transmitted between client and WSO2 ESB in TCPmon window.

To monitor HTTP traffic between WSO2 ESB and back-end service
  • Start TCPMon on machine runs WSO2 ESB
  • Goto Admin tab
  • Set Listen Port # as 8282 ( Assume that port 8282 is free on your system )
  • Set Target Hostname as hostname of machine that runs back-end service
  • Set Target Port # as port number that back-end service runs
  • Click Add
  • Goto Port 8282 tab

Then you have to edit WSO2 ESB Proxy service configuration to send messages to TCPmon port 8282 runs on localhost.

To do that replace the hostname and port of endpoint url with localhost and 8282.
Eg: If back-end service url is http://myhost:8000/services/myservice , set endpoint url as http://localhost:8282/services/myservice

When WSO2 ESB sends a message to back-end service, WSO2 ESB will send message to TCPmon runs on localhost:8282 and TCPmon sends that message to actual back-end service (http://myhost:8000/services/myservice). You can monitor request/response transmitted between WSO2 ESB and back-end service in TCPmon window.

By following mentioned steps you can obtain wire level messages transmitted between Client,WSO2 ESB and WSO2 ESB,back-end service.

[1] http://ws.apache.org/commons/tcpmon/tcpmontutorial.html