Thursday, November 24, 2011

Retriving clientIP/Host within the sequence in Synapse

<property name="client-host" expression="get-property('axis2', 'REMOTE_HOST')"/>         
<property name="client-add" expression="get-property('axis2', 'REMOTE_ADDR')"/>
<log level="custom">    
    <property name="REMOTE_ADDR :" expression="get-property('client-add')"/>

    <property name="REMOTE_HOST:" expression="get-property('client-host')"/>
</log>

Tuesday, November 22, 2011

Overcoming : "AxisFault: Timeout waiting for connection" issue

This issue[1] you might face when you run your axis2client code in a loop  against a service..

To overcome above issue, set the "MULTITHREAD_HTTP_CONNECTION_MANAGER" property in the axis2 ConfigurationContext.

ConfigurationContext configContext =   ConfigurationContextFactory.  createConfigurationContextFromFileSystem("CARBON_HOME\\repository\\deployment\\client", "CARBON_HOME\\repository\\conf\\axis2_client.xml");

MultiThreadedHttpConnectionManager httpConnectionManager =  new MultiThreadedHttpConnectionManager();       

configContext.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER,  httpConnectionManager);

[1]
Caused by: org.apache.axis2.AxisFault: Timeout waiting for connection
       at org.apache.axis2.AxisFault.
makeFault(AxisFault.java:430)
       at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
       at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
Caused by: org.apache.commons.httpclient.
ConnectionPoolTimeoutException:
Timeout waiting for connection
       at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:490)
       at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:394)

Friday, November 18, 2011

Getting system time within the mediation flow in synapse

There are two default system properties available synapse, which can be used to retrieve the system time/date in a mediation flow..There are usecases, when an user needs to append the system time at the message arrival point to the synapse engine.
Use the property mediator to hold the system time..

<property name="sysDate" expression="get-property('SYSTEM_DATE')" scope="default"
type="STRING"/>
<property name="sysTime" expression="get-property('SYSTEM_TIME')" scope="default" type="STRING"/>

sample sequence would be;

<sequence name="get">
<property name="sysDate" expression="get-property('SYSTEM_DATE')" scope="default" type="STRING"/>
<property name="sysTime" expression="get-property('SYSTEM_TIME')" scope="default" type="STRING"/>
<log>
<property name="SYSTEM TIME IS*******" expression="get-property('sysTime')"/>
</log>
<log>
<property name="SYSTEM DATE IS*******" expression="get-property('sysDate')"/>
</log>
</sequence>



Thursday, November 17, 2011

Invoking a RESTful service via WSO2ESB

In the ESB, when we define a proxy, it is not a must to provide the service wsdl, unless if you want to hide/add a new elements in your service contract.
Lets check a  very simple basic proxy to process a HTTP GET request
  • Get wso2esb binary distribution.
  • Deploy the simplestockquote service and start the sample axis2server.
  • Start ESB.
Create the following proxy;
<proxy name="RestProxy" transports="https http" startOnLoad="true" trace="disable">
        <target>  
            <endpoint>
              <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>             
            <outSequence>
                <send/>
            </outSequence>
        </target>
    </proxy>

Execute the following GETrequest url in your browser;
http://localhost:8280/services/RestProxy/getSimpleQuote?symbol=IBM

Now you will see the response in your browser. If you place the tcpmon between client and ESB, you can check your http 'get' request,

GET /services/RestProxy/getSimpleQuote?symbol=IBM HTTP/1.1
Host: 127.0.0.1:5555
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.24) Gecko/20111103 Firefox/3.6.24
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Cookie: region1_configure_menu=; region3_registry_menu=visible; region4_monitor_menu=;

In the above sample client sends the 'symbol=IBM' as the parameter for the operation "getSimpleQuote"..Say in the mediation logic user may need to change the parameter as 'SUN'.(ie:symbol=SUN)..For that he/she can use "REST_URL_POSTFIX" property ..Which basically adds the suffix for the REST service endpoint.
eg:
   <property name="REST_URL_POSTFIX" value="/getSimpleQuote?symbol=SUN" scope="axis2"/>

So, the insequence would be;
    <inSequence>
                <property name="REST_URL_POSTFIX" value="/getSimpleQuote?symbol=SUN" scope="axis2"/>
                <send>
                    <endpoint>
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                    </endpoint>
                </send>
    </inSequence>


User could add your own mediation logic with whatever the mediators within the sequence..

Related post;
REST support in WSO2ESB - Introduction
REST Support in WSO2ESB - Handling JSON messages

Monday, November 14, 2011

Programmatically enabling log4j appenders

The standard way to enable 'appenders' in log4j is using log4j.properties file..Here lets check out how an user can enable the 'appenders' programmaticly..This is useful , when user wants a logging mechanism separately, which differs from his/her global logging setting..
This is a sample code i have written to grab proxy service level logging information separately..

    private void setLogger(ProxyService proxy) throws IOException {

        String filename = "logs/" + proxy.getName() + ".log";
        String datePattern = "yyyy-MM-dd";
        String SYSTEM_LOG_PATTERN = "[%d] %5p - %x %m {%c}%n";

        PatternLayout layout = new PatternLayout(SYSTEM_LOG_PATTERN);

        DailyRollingFileAppender appender = null;

        appender = new DailyRollingFileAppender(layout, filename, datePattern);

        Logger proxyLogger = Logger.getLogger("SERVICE_LOGGER." + proxy.getName());

        proxyLogger.setLevel((Level) Level.DEBUG);

        proxyLogger.setAdditivity(false);
        proxyLogger.addAppender(appender);

    }   

Thursday, November 3, 2011

Configuring WSO2 ESB with Oracle™AQ as Messaging Media

"OracleAQ provides database integrated messaging functionality. Its' underlying system works with oracle database. OracleJMS (OJMS) is the JMS interface to the Advanced Queuing (AQ) feature in the Oracle database. OJMS has JNDI support, which could be used to get 'ConnectionFactory' at run time and the connections returned from it will be able to transparently connect to the JMS server."

I have written a detail tutorial about the configurations needed to connect AQ , which is published [1] at wso2 site..Thanks Edwin  for the great help on AQ and LDAP configurations..
[1]http://wso2.org/library/tutorials/2011/11/configuring-wso2-esb-with-oracle-as-messaging-media