Monday, November 25, 2013

WSO2 ESB append full body to a POST parameter

When you have to invoke a back end service which can take only on parameter and you need to send your full soap envelop body as single post parameter you can use script mediator and payload factory mediator as following. I have an api which calls to "http://localhost:9000/services/SimpleStockQuoteService"  and response is received by the "second_sequence".
In the second_sequence response is processed and assign it single parameter using script mediator and payload factory.

API


<api xmlns="http://ws.apache.org/ns/synapse" name="StockQuoteAPI2" context="/stockquote_api">
   <resource methods="GET" uri-template="/view/{symbol}">
      <inSequence>
         <payloadFactory>
            <format>
               <m0:getQuote xmlns:m0="http://services.samples">
                  <m0:request>
                     <m0:symbol>$1</m0:symbol>
                  </m0:request>
               </m0:getQuote>
            </format>
            <args>
               <arg expression="get-property('uri.var.symbol')"/>
            </args>
         </payloadFactory>
         <send receive="second_sequence">
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </resource>
</api>
                     

SEQUENCE



<sequence xmlns="http://ws.apache.org/ns/synapse" name="second_sequence">
   <property name="DISABLE_CHUNKING" value="true" scope="axis2" type="STRING"/>
   <script language="js">
      <![CDATA[
                     var payload = mc.getEnvelope().getBody().getFirstElement().toString();
                     payload = encodeURI(payload);        
                     mc.setProperty("test",payload);
        ]]>
    </script>
      <payloadFactory>
         <format>
            <getSimpleQuote>
               <symbol>$1</symbol>
            </getSimpleQuote>
         </format>
         <args>
            <arg xmlns:ns="http://org.apache.synapse/xsd" expression="$ctx:test"/>
         </args>
      </payloadFactory>
      <log level="custom">
         <property xmlns:ns="http://org.apache.synapse/xsd" name="xxxxxxx....................." expression="$ctx:test"/>
      </log>
      <log level="full"/>
      <send>
         <endpoint>
            <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="get"/>
         </endpoint>
      </send>
      <log level="full" category="DEBUG"/>
   </sequence>


You will find that in the sequence it sends the request as follows

GET /services/SimpleStockQuoteService/getSimpleQuote?symbol=%253cns:getQuoteResponse%2520xmlns:ns=%2522http://services.samples%2522%253e%253cns:return%2520xmlns:ax21=%2522http://services.samples/xsd%2522%2520xmlns:xsi=%2522http://www.w3.org/2001/XMLSchema-instance%2522%2520xsi:type=%2522ax21:GetQuoteResponse%2522%253e%253cax21:change%253e-2.878332384294565%253c/ax21:change%253e%253cax21:earnings%253e13.343243692880526%253c/ax21:earnings%253e%253cax21:high%253e83.90879243287203%253c/ax21:high%253e%253cax21:last%253e80.71927384911324%253c/ax21:last%253e%253cax21:lastTradeTimestamp%253eMon%2520Nov%252025%252012:10:46%2520PST%25202013%253c/ax21:lastTradeTimestamp%253e%253cax21:low%253e84.13935291865967%253c/ax21:low%253e%253cax21:marketCap%253e4.856632338341972E7%253c/ax21:marketCap%253e%253cax21:name%253eibm%2520Company%253c/ax21:name%253e%253cax21:open%253e84.41127937872128%253c/ax21:open%253e%253cax21:peRatio%253e-17.33795236794525%253c/ax21:peRatio%253e%253cax21:percentageChange%253e3.7341845696623412%253c/ax21:percentageChange%253e%253cax21:prevClose%253e-77.08061373503116%253c/ax21:prevClose%253e%253cax21:symbol%253eibm%253c/ax21:symbol%253e%253cax21:volume%253e9235%253c/ax21:volume%253e%253c/ns:return%253e%253c/ns:getQuoteResponse%253e






Monday, November 11, 2013

SSL handshake failed: SSL error: Key usage violation in certificate has been detected

SVN causing problems in ubuntu

When I was checking out a code in a svn repository which can only connect through https, started giving me errors as following.

SSL handshake failed: SSL error: Key usage violation in certificate has been detected.

This is caused by a bug in the version of libneon, fortunately this is fixed in version 0.29.3.  

To fix the problem, please follow the steps


  1. Uninstall the current libneon package: sudo apt-get remove libneon27
  2. Download the latest libneon package http://packages.debian.org/squeeze/libneon27
  3. Install the required libssl dependency: sudo apt-get install libssl0.9.8
  4. Install the downloaded libneon package: dpkg -i libneon27_0.29.3-3_amd64.deb
  5. Make the changes to symbolic links as described above: sudo mv /usr/lib/libneon-gnutls.so.27 /usr/lib/libneon-gnutls.so.27.old sudo ln -s /usr/lib/libneon.so.27 /usr/lib/libneon-gnutls.so.27

Monday, November 4, 2013

WSO2 ESB Stop suffix getting appended to endpoint.

When you are developing a synapse configurations, there can be some places where you do a POST request to rest end point from a proxy service. And you find that your end is get appended by some other part of the previous url end point which supposed to call the current proxy service.

You can get rid of it with this property mediator.

<property name="REST_URL_POSTFIX" scope="axis2" action="remove"/> 

WSO2 ESB Script Mediator (Remove body of an soap envelop)

When you are implementing synapse configurations in WSO2 ESB (4.6.0), sometimes you might want to remove soap body. This happens to me when I was developing complex synapse configuration, which had lot of service chaining. The last of the service chaining was to call to a rest (GET) end point using rest api. Up to final call to rest api, everything seems to work perfect. But the last rest api call fails due to a soap envelop generated from service chaining. Simple solution was to remove the soap body from the envelop. then it worked perfectly as I expected.

This is the simple solution I used to remove the body from the soap envelop using script mediator.

<script language="js">
mc.getEnvelope().getBody().getFirstElement().detach();
print(mc.getEnvelope().getBody());
</script>


WSO2 ESB Dynamic End Point Resolution

From WSO2 ESB 4.7.0 onwards, support dynamic end point resolutions.

If you have multiple deployment environments (DEV, QA, Production), then you may end up having many endpoints and will have to change them once you migrate your synapse configs to other environment. As a simple solution for this time consuming problem (for Call out mediator and send mediator only), you can initialize end points as jvm parameters at the server start up.

Ex:

  1. SEND Mediator

    <send>
                <endpoint name="MyEp"
                          template="endPointTemplete"
                          uri="http://{system.prop.bpm.stock.host}:{system.prop.bpm.stock.port}/services/SimpleStockQuoteService"/>
             </send>

    You have to create a endpoint template in order to use this feature for send mediator. When you start the ESB, you can initialize the {system.prop.bpm.stock.host} and {system.prop.bpm.stock.port} by using JVM parameters as follows. And then those end points will be initialized correctly.

    -Dbpm.stock.host=.............    - Dbpm.stock.port=..................

  2. CALLOUT Mediator
Callout mediator will be same as send mediator. you can initialize the parameters with jvm parameters

   <callout serviceURL="http://{system.prop.bpm.stock.host}:{system.prop.bpm.stock.port}/services/SimpleStockQuoteService"
                  action="urn:getQuote">
            <source xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
                    xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
                    xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
            <target xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
                    xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
                    xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
         </callout>



Wednesday, June 19, 2013

WSO2 APP SERVER WEB APPLICATION STATISTICS MONITORING


Are you in need of monitoring for your web application. Need to know more details than other analytic tools provide without a cost of performance. We have the best solution. WSO2 Application Server and WSO2 Business Activity Monitor.

In current wso2 application server (AS -5.1.0) does have capability of monitoring service statistics through wso2 business activity monitor (BAM -2.2.0). But yet it does not have the ability to monitor web applications statistics

In the next AS release (5.2.0) we have integrated the capability of monitoring web application statistics with BAM (2.3.0)

You may  follow the steps mentioned below to activate the monitoring.

Please download AS from here and BAM from here.


CONFIGURING APP SERVER.

  1. To start the AS you have to follow the steps below.
    • Go to {AS_HOME}/repository/conf/ and open carbon.xml
    • Look for <offset>0</offset> and change it 1.
    • Go to {AS_HOME}/repository/conf/etc/ and open bam.xml.
    • Look for <WebappDataPublishing>disable</WebappDataPublishing> and enable it.
    • Then go to {AS_HOME}/bin and run wso2server.sh if you are in linux, wso2server.bat if you are in windows.
    • Then log in to AS management console and go to Configure > Webapp Data Publishing. (Note If you are on tenant, you have to configure this separately.)
    • Tick the "Enable webapp stats" and fill the relevant details.

    • Leave the Stream Name, Version, Nick Name, Description as it is. If you need to change them you will have to make some more changes in the tool box and hive script. Which will be discussed later.
      • Receiver URL - Thrift url, This is normally tcp://{host}:7611, If you need to use SSL for this you tcps://{host}:7711. (If you change the offset of BAM server to 1 both port will be incremented by 1 (7612, 7712)
      •  Username - Cassandra user name 
      • Password - Cassandra Password
Now you have successfully configured AS for Data publishing to BAM. Now we need to configure in AS which web applications needs monitoring and which does not. For that before you deploy a web application, another change has to be done to web.xml or you can enable it by web app dash board.


 Please click on the check box given to enable bam web app statisitic monitoring for relevant web application.

Or you can add the following context params to application web.xml. Please note that ui has the precedence over web.xml configurations. It means that if you disable web apps statics monitoring from ui, configurations in web.xml will not work.

      <context-param>
             <param-name>enable.statistics</param-name>
             <param-value>true</param-value>
      </context-param>

If you deploy any web application with above parameters included in the web.xml or enabled from ui, AS is ready to publish the data to BAM.


CONFIGURING BUSINESS ACTIVITY MONITOR


  1. Start the BAM server  - Go to {BAM_HOME}/bin, and run wso2server.sh if you are in linux, wso2server.bat if you are in windows. (If you need to change  databases which stores statistic data, please create database and configure it in {BAM_HOME}/repository/conf/datasources/master-datasources.xml  as  WSO2BAM_DATASOURCE, If you have changed the portoffset you have to change cassandra port in WSO2BAM_CASSANDRA_DATASOURCE.)
  2. Go to Home > Manage > BAM Toolbox > Add and look for WebApps_Stats_Monitoring tool box. and click install. Please refresh the after few seconds to see weather tool is installed.
  3. Send few request from AS (Invoke any web applications which has enabled statistics monitoring.
  4. Go to Home > Manage > Analytics > List and find webapp_statistics, execute it or schedule it running sequence.
  5. Go to Dashboard and login with admin/admin  you can view following details from ui
  • All request summary - (All / Month / Day / Now)



    1. Request count
    2. Response count
    3. Error count
    4. Average response time
    5. Minimum Response Time
    6. Maximum Response Time
    7. Number of user visits (Amount of users, web app used.)
    8. Average length time of user visits (average session time)
    9. Page visits
  • Per tenant request summary – (All / Month / Day / Now)



    1. Request count
    2. Response count
    3. Error count
    4. Average response time
    5. Minimum Response Time
    6. Maximum Response Time
    7. Number of user visits (Amount of users, web app used.)
    8. Average length time of user visits (average session time)
    9. Page visits
  • Per web app request summary – (All / Month / Day / Now)



    1. Request count
    2. Response count
    3. Error count
    4. Average response time
    5. Minimum Response Time
    6. Maximum Response Time
    7. Number of user visits (Amount of users, web app used.)
    8. Average length time of user visits (average session time)
    9. Page visits.



Request Count and Average Response Time



Average Response Time and Request/Response/Fault Count



Number of User Visits and Average Length of User Visits