Thursday, November 21, 2013

Invoking Secure Service (UT enabled) Via Non Secure Client -Part 2

Enabling policy

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="NonSecureProxyPolicy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="full">
            <property name="INNNNN" value="***********INNNN sequence proxy2***********"/>
         </log>
         <send>
            <endpoint>
               <address uri="https://localhost:8243/services/SecureService">
                  <enableSec policy="conf:/security-policy/UT-Policy1"/>
               </address>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>


Rampart policy

<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UTOverTransport">
   <wsp:ExactlyOne>
      <wsp:All>
         <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
            <wsp:Policy>
               <sp:TransportToken>
                  <wsp:Policy>
                     <sp:HttpsToken RequireClientCertificate="false"/>
                  </wsp:Policy>
               </sp:TransportToken>
               <sp:AlgorithmSuite>
                  <wsp:Policy>
                     <sp:Basic256/>
                  </wsp:Policy>
               </sp:AlgorithmSuite>
               <sp:Layout>
                  <wsp:Policy>
                     <sp:Lax/>
                  </wsp:Policy>
               </sp:Layout>
               <sp:IncludeTimestamp/>
            </wsp:Policy>
         </sp:TransportBinding>
         <sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
            <wsp:Policy>
               <sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"/>
            </wsp:Policy>
         </sp:SignedSupportingTokens>
         <rampart:RampartConfig xmlns:rampart="http://ws.apache.org/rampart/policy">
            <rampart:user>dushan</rampart:user>
            <rampart:timestampPrecisionInMilliseconds>true</rampart:timestampPrecisionInMilliseconds>
            <rampart:timestampTTL>300</rampart:timestampTTL>
            <rampart:timestampMaxSkew>300</rampart:timestampMaxSkew>
            <rampart:timestampStrict>false</rampart:timestampStrict>          <rampart:passwordCallbackClass>org.wso2.samples.pwcb.PWCBHandler</rampart:passwordCallbackClass>
                        <rampart:nonceLifeTime>300</rampart:nonceLifeTime>
         </rampart:RampartConfig>
      </wsp:All>
   </wsp:ExactlyOne>
</wsp:Policy>      
                                

Invoking Secure Service (UT enabled) Via Non Secure Client -Part 1

When client would require to invoke Secure Services via Non secure services, one possible solution is to enable encrypt the basic headers and them to the Authorization header in transport scope then to invoke the given service


<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="NonSecureProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="full">
            <property name="INNNNN" value="***********INNNN sequence proxy2***********"/>
         </log>
         <property name="Authorization"
                   expression="fn:concat('Basic ', base64Encode('dushan:dushan'))"
                   scope="transport"/>
         <send>
            <endpoint>
               <address uri="https://localhost:8243/services/SecureService/getQuote"
                        format="pox"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>


<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="SecureService"
       transports="https"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <enableSec/>
   <policy key="conf:/repository/axis2/service-groups/SecureService/services/SecureService/policies/UTOverTransport"/>
   <description/>
</proxy>



[2013-11-21 14:12:30,620] DEBUG - wire >> "[\r][\n]"
[2013-11-21 14:12:30,636] DEBUG - wire << "POST /services/SimpleStockQuoteService/getQuote HTTP/1.1[\r][\n]"
[2013-11-21 14:12:30,637] DEBUG - wire << "Authorization: Basic ZHVzaGFuOmR1c2hhbg==[\r][\n]"
[2013-11-21 14:12:30,637] DEBUG - wire << "Accept-Encoding: gzip,deflate[\r][\n]"
[2013-11-21 14:12:30,638] DEBUG - wire << "Content-Type: application/xml[\r][\n]"
[2013-11-21 14:12:30,638] DEBUG - wire << "SOAPAction: urn:getQuote[\r][\n]"
[2013-11-21 14:12:30,638] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2013-11-21 14:12:30,638] DEBUG - wire << "Host: localhost:9000[\r][\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "[\r][\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "fe[\r][\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "<ser:getQuote xmlns:ser="http://services.samples">[\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "         <!--Optional:-->[\n]"
[2013-11-21 14:12:30,639] DEBUG - wire << "         <ser:request>[\n]"
[2013-11-21 14:12:30,640] DEBUG - wire << "            <!--Optional:-->[\n]"
[2013-11-21 14:12:30,640] DEBUG - wire << "            <xsd:symbol xmlns:xsd="http://services.samples/xsd">11</xsd:symbol>[\n]"
[2013-11-21 14:12:30,640] DEBUG - wire << "         </ser:request>[\n]"
[2013-11-21 14:12:30,640] DEBUG - wire << "      </ser:getQuote>[\r][\n]"
[2013-11-21 14:12:30,640] DEBUG - wire << "0[\r][\n]"
[2013-11-21 14:12:30,640] DEBUG - wire << "[\r][\n]"
[2013-11-21 14:12:30,644] DEBUG - wire >> "HTTP/1.1 200 OK[\r][\n]"
[2013-11-21 14:12:30,644] DEBUG - wire >> "Content-Type: application/xml; charset=UTF-8[\r][\n]"
[2013-11-21 14:12:30,645] DEBUG - wire >> "Date: Thu, 21 Nov 2013 08:42:30 GMT[\r][\n]"
[2013-11-21 14:12:30,645] DEBUG - wire >> "Transfer-Encoding: chunked[\r][\n]"
[2013-11-21 14:12:30,645] DEBUG - wire >> "Connection: Keep-Alive[\r][\n]"
[2013-11-21 14:12:30,645] DEBUG - wire >> "[\r][\n]"
[2013-11-21 14:12:30,647] DEBUG - wire >> "368[\r][\n]"
[2013-11-21 14:12:30,647] DEBUG - wire >> "<ns:getQuoteResponse xmlns:ns="http://services.samples"><ns:return xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax21:GetQuoteResponse"><ax21:change>4.423747490453758</ax21:change><ax21:earnings>13.080465575691782</ax21:earnings><ax21:high>183.72455511877618</ax21:high><ax21:last>177.25933516401494</ax21:last><ax21:lastTradeTimestamp>Thu Nov 21 14:12:30 IST 2013</ax21:lastTradeTimestamp><ax21:low>-176.6775010130566</ax21:low><ax21:marketCap>1797692.482250683</ax21:marketCap><ax21:name>11 Company</ax21:name><ax21:open>183.25648908841202</ax21:open><ax21:peRatio>-17.898897366819455</ax21:peRatio><ax21:percentageChange>-2.6156190500725063</ax21:percentageChange><ax21:prevClose>-169.12812629695176</ax21:prevClose><ax21:symbol>11</ax21:symbol><ax21:volume>5447</ax21:volume></ns:return></ns:getQuoteResponse>[\r][\n]"
[2013-11-21 14:12:30,648] DEBUG - wire >> "0[\r][\n]"
[2013-11-21 14:12:30,648] DEBUG - wire >> "[\r][\n]"
[2013-11-21 14:12:30,655] DEBUG - wire << "HTTP/1.1 200 OK[\r][\n]"
[2013-11-21 14:12:30,655] DEBUG - wire << "Content-Type: application/xml[\r][\n]"
[2013-11-21 14:12:30,656] DEBUG - wire << "Date: Thu, 21 Nov 2013 08:42:30 GMT[\r][\n]"
[2013-11-21 14:12:30,656] DEBUG - wire << "Server: WSO2-PassThrough-HTTP[\r][\n]"
[2013

Wednesday, November 20, 2013

Callout Meditor to Invoke REST Services

Following configuration allows you to invoke RESTful services via CalloutMeditator

P.N you need to change axis2_client.xml Required to add JSON message formatter in ESB_470_HOME/samples/axis2Client/client_repo/conf/axis2.xml



<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="CalloutProxy"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="enableREST"
                   value="true"
                   scope="axis2-client"
                   type="BOOLEAN"/>
         <property name="messageType"
                   value="application/json"
                   scope="axis2-client"
                   type="STRING"/>
         <property name="contentType"
                   value="application/json"
                   scope="axis2-client"
                   type="STRING"/>
         <callout serviceURL="http://localhost:9001/services/SimpleStockQuoteService"
                  action="urn:getQuote"
                  initAxis2ClientOptions="false">
            <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>
         <property name="RESPONSE" value="true"/>
         <header name="To" action="remove"/>
         <send/>
         <drop/>
      </inSequence>
   </target>
   <description/>
</proxy>


Wire logs

log4j.logger.httpclient.wire.header=DEBUG
log4j.logger.httpclient.wire.content=DEBUG

logs seen in console

[2013-11-20 17:38:18,840]  INFO - CarbonUIServiceComponent Mgt Console URL  : https://10.100.1.122:9443/carbon/
[2013-11-20 17:39:39,459] DEBUG - header >> "POST /services/SimpleStockQuoteService HTTP/1.1[\r][\n]"
[2013-11-20 17:39:39,468] DEBUG - header >> "Content-Type: application/json; charset=UTF-8[\r][\n]"
[2013-11-20 17:39:39,469] DEBUG - header >> "Accept-Encoding: gzip,deflate[\r][\n]"
[2013-11-20 17:39:39,469] DEBUG - header >> "User-Agent: Axis2[\r][\n]"
[2013-11-20 17:39:39,469] DEBUG - header >> "Host: localhost:9001[\r][\n]"
[2013-11-20 17:39:39,469] DEBUG - header >> "Transfer-Encoding: chunked[\r][\n]"
[2013-11-20 17:39:39,469] DEBUG - header >> "[\r][\n]"
[2013-11-20 17:39:39,480] DEBUG - content >> "27[\r][\n]"
[2013-11-20 17:39:39,480] DEBUG - content >> "{"getQuote":{"request":{"symbol":"?"}}}"
[2013-11-20 17:39:39,480] DEBUG - content >> "[\r][\n]"
[2013-11-20 17:39:39,480] DEBUG - content >> "0"
[2013-11-20 17:39:39,480] DEBUG - content >> "[\r][\n]"
[2013-11-20 17:39:39,480] DEBUG - content >> "[\r][\n]"


                                

Thursday, September 26, 2013

Upcoming ESB features (Call Meditor and Connectors)

ESB 4.8.0 about to be released soon, in my previous blog I discussed how you can configure, iterate and aggregate ,there have been numerous changers accommodated in 4.8.0 to simplify the configuration, some of the enhancements we have done listed below.

  • Call Mediator (Non Blocking callout mediator) probably but almost retiring CalloutMediator (which is blocking)
  • Loopback Mediator
  • Response  Mediator  
                additionally more information to be followed related to the CLOUD CONNECTOR usecases within next few weeks ......


<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="CallIterator"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <iterate xmlns:m1="http://services.samples"
                  xmlns:m2="http://services.samples/xsd"
                  id="callItr"
                  expression="//m1:getQuotes/m1:getQuote">
            <target>
               <sequence>
                  <call>
                     <endpoint>
                        <address uri="http://localhost:9001/services/SimpleStockQuoteService"/>
                     </endpoint>
                  </call>
               </sequence>
            </target>
         </iterate>
         <log level="full">
            <property name="MESSAGE" value="##1"/>
         </log>
         <property name="ECNCLOSING_ELEMENT" scope="default">
            <wrapper xmlns=""/>
         </property>
         <aggregate id="callItr">
            <completeCondition>
               <messageCount min="-1" max="-1"/>
            </completeCondition>
            <onComplete xmlns:m1="http://services.samples"
                        expression="//m1:getQuoteResponse"
                        enclosingElementProperty="ECNCLOSING_ELEMENT">
               <log level="full">
                  <property name="MESSAGE" value="##2"/>
               </log>
            </onComplete>
         </aggregate>
         <loopback/>
      </inSequence>
      <outSequence>
         <respond/>
      </outSequence>
   </target>
   <description/>
</proxy>


response..

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <wrapper>
         <ns:getQuoteResponse xmlns:ns="http://services.samples">
            <ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <ax21:change>-2.282072032481502</ax21:change>
               <ax21:earnings>-8.184245817709384</ax21:earnings>
               <ax21:high>161.1255146837517</ax21:high>
               <ax21:last>153.9460060122943</ax21:last>
               <ax21:lastTradeTimestamp>Thu Sep 26 23:05:24 IST 2013</ax21:lastTradeTimestamp>
               <ax21:low>-153.68705428915268</ax21:low>
               <ax21:marketCap>3698159.0880708937</ax21:marketCap>
               <ax21:name>DLL Company</ax21:name>
               <ax21:open>-151.72501736767938</ax21:open>
               <ax21:peRatio>25.8716132214498</ax21:peRatio>
               <ax21:percentageChange>1.562593376583845</ax21:percentageChange>
               <ax21:prevClose>-146.04388234836802</ax21:prevClose>
               <ax21:symbol>DLL</ax21:symbol>
               <ax21:volume>16230</ax21:volume>
            </ns:return>
         </ns:getQuoteResponse>
         <ns:getQuoteResponse xmlns:ns="http://services.samples">
            <ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <ax21:change>-2.50201581759645</ax21:change>
               <ax21:earnings>13.910655333381875</ax21:earnings>
               <ax21:high>-173.9913159476355</ax21:high>
               <ax21:last>178.2282964042608</ax21:last>
               <ax21:lastTradeTimestamp>Thu Sep 26 23:05:24 IST 2013</ax21:lastTradeTimestamp>
               <ax21:low>184.07373157820325</ax21:low>
               <ax21:marketCap>-8690349.18328286</ax21:marketCap>
               <ax21:name>SAMSUG Company</ax21:name>
               <ax21:open>187.00563796447824</ax21:open>
               <ax21:peRatio>24.27282100627226</ax21:peRatio>
               <ax21:percentageChange>1.5129014962405416</ax21:percentageChange>
               <ax21:prevClose>-165.37863329594103</ax21:prevClose>
               <ax21:symbol>SAMSUG</ax21:symbol>
               <ax21:volume>17238</ax21:volume>
            </ns:return>
         </ns:getQuoteResponse>
         <ns:getQuoteResponse xmlns:ns="http://services.samples">
            <ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <ax21:change>3.776274828469344</ax21:change>
               <ax21:earnings>12.080383538265115</ax21:earnings>
               <ax21:high>-169.48473541292884</ax21:high>
               <ax21:last>173.1940035266614</ax21:last>
               <ax21:lastTradeTimestamp>Thu Sep 26 23:05:24 IST 2013</ax21:lastTradeTimestamp>
               <ax21:low>179.34173748130962</ax21:low>
               <ax21:marketCap>3.542581699105626E7</ax21:marketCap>
               <ax21:name>IBM Company</ax21:name>
               <ax21:open>-170.07540506338606</ax21:open>
               <ax21:peRatio>-19.16117019602173</ax21:peRatio>
               <ax21:percentageChange>2.001801348105515</ax21:percentageChange>
               <ax21:prevClose>188.64383481623557</ax21:prevClose>
               <ax21:symbol>IBM</ax21:symbol>
               <ax21:volume>8286</ax21:volume>
            </ns:return>
         </ns:getQuoteResponse>
      </wrapper>
   </soapenv:Body>
</soapenv:Envelope>

Wednesday, July 3, 2013

The WSO2 Enterprise Service Bus (ESB) 4.7.0 Released!

WSO2 ESB team is pleased to announce the release of version 4.7.0 of the Open Source Enterprise Service Bus (ESB).
WSO2 ESB is a fast, lightweight and user friendly open source Enterprise Service Bus (ESB) distributed under the Apache Software License v2.0. WSO2 ESB allows system administrators and developers to easily configure message routing, intermediation, transformation, logging, task scheduling, fail over routing and load balancing. It also supports transport switching, eventing, rule based mediation and priority based mediation for advanced integration requirements. The ESB runtime is designed to be completely asynchronous, non-blocking and streaming based on the Apache Synapse mediation engine.
WSO2 ESB 4.7.0 is developed on top of the revolutionary WSO2 Carbon platform (Middleware a' la carte), an OSGi based framework that provides seamless modularity to your SOA via componentization. This release also contains many new features and a range of optional components (add-ons) that can be installed to customize the behavior of the ESB. Further, any existing features of the ESB which are not required to your environment can be easily removed using the underlying provisioning framework of Carbon. In brief, WSO2 ESB can be fully customized and tailored to meet your exact SOA needs.
You can download this distribution from http://wso2.com/products/enterprise-service-bus/ and give it a try.

How to Run

  1. Extract the downloaded zip
  2. Go to the bin directory in the extracted folder
  3. Run the wso2server.sh or wso2server.bat as appropriate
  4. Point your browser to the URL https://localhost:9443/carbon
  5. Use "admin", "admin" as the username and password to login as an admin
  6. If you need to start the OSGi console with the server use the property -DosgiConsole when starting the server. The INSTALL.txt file found on the installation directory will give you a comprehensive set of options and properties that can be passed into the startup script
  7. Sample configurations can be started by the wso2esb-samples script passing the sample number with the -sn option (Please have a look at the samples guide for more information, on running samples)

Brand New in This Release

  • Comprehensive REST integration support with HTTP Endpoints
  • JSON support for Payload Factory Mediator
  • SSL Tunneling Support
  • SSL Profiles for inbound and outbound scenarios
  • Inbound Connection Throttling support for Pass-Thru and NHTTP transports
  • CRL/OCSP Certificate Revocation Verification

Enhancements in WSO2 ESB 4.7.0

  • Enhanced Message Stores and Processors for Guaranteed Delivery and Rate Matching Scenarios
  • High Performance Multitenant REST APIs support with Pass-Thru Transport
  • Stabilizing Registry Based Deployment Synchronizer
  • Invoking Sequences and Proxy Service from Scheduled Tasks
  • HL7 Enhancements to support Application-Acknowledgement and Auto-Acknowledgement scenarios
  • Transport Header manipulation in Header Mediator
  • Enhancement on Content Negotiation in RESTful integration(ie: POX with text/xml)
  • JMS MapMessage compatibility for JMS Transport

Key Features of WSO2 ESB

  • Proxy services - facilitating synchronous/asynchronous transport, interface (WSDL/Schema/Policy), message format (SOAP 1.1/1.2, POX/REST, Text, Binary), QoS (WS-Addressing/WS-Security/WS-RM) and optimization switching (MTOM/SwA).
  • API facilitating building REST services
  • Non-blocking HTTP/S transports based on Apache HttpCore-NIO for ultra-fast execution and support for thousands of connections at high concurrency with constant memory usage.
  • Built in Registry/Repository, facilitating dynamic updating and reloading of the configuration and associated resources (e.g. XSLTs, XSD, WSDL, Policies, JS configurations ..)
  • Easily extendable via custom Java classes (mediator and command)/Spring configurations, or BSF Scripting languages (Javascript, Ruby, Groovy, etc.)
  • Built in support for scheduling tasks using the Quartz scheduler.
  • Load-balancing (with or without sticky sessions)/Fail-over, and clustered Throttling and Caching support
  • WS-Security, WS-Reliable Messaging, Caching & Throttling configurable via (message/operation/service level) WS-Policies
  • Lightweight, XML and Web services centric messaging model
  • Support for industrial standards (Hessian binary web service protocol/ Financial Information eXchange protocol and optional Health Level-7 protocol)
  • Enhanced support for the VFS (File/FTP/SFTP), JMS, Mail transports with optional TCP/UDP transports and transport switching among any of the above transports
  • Support for message splitting & aggregation using the EIP and service callouts
  • Database lookup & store support with DBMediators with reusable database connection pools
  • WS-Eventing support
  • Rule based mediation of the messages using the Drools rule engine
  • Transactions support via the JMS transport and Transaction mediator for database mediators
  • Internationalized GUI management console with user management for configuration development
  • Integrated monitoring support with statistics, configurable logging and tracing
  • JMX monitoring support and JMX management capabilities like, Graceful/Forceful shutdown/restart

Bugs Fixed in This Release

This release of WSO2 ESB comes with a number of bug fixes, both in the base framework and the ESB specific components. All the issues which have been fixed in ESB 4.7.0 are recorded at following locations:

Known Issues

All the open issues pertaining to WSO2 ESB 4.7.0 are reported at following locations:

How You Can Contribute

Mailing Lists

Join our mailing list and correspond with the developers directly.

Reporting Issues

We encourage you to report issues, documentation faults and feature requests regarding WSO2 ESB through the public ESB JIRA. You can use the Carbon JIRA to report any issues related to the Carbon base framework or associated Carbon components.

Discussion Forums

Alternatively, questions could be raised on http://stackoverflow.com.

Support

We are committed to ensuring that your enterprise middleware deployment is completely supported from evaluation to production. Our unique approach ensures that all support leverages our open development methodology and is provided by the very same engineers who build the technology.
For more details and to take advantage of this unique opportunity please visit http://wso2.com/support.
For more information about WSO2 ESB please see http://wso2.com/products/enterprise-service-bus.
-- The WSO2 ESB Team --

Thursday, June 27, 2013

JMS Transaction with retries to the destination ( Workaround solution for ScheduleMessageProcessor without Order Delivery) ESB 4.6.0 with ActiveMQ

  Following sample will describe how you can use JMSTrasaction support and allow message to be redelivery for few time  (as how it configured in axis2.xml) then if failed move the given message to DeadLetter Queue in ActiveMQ, 

 <proxy name="StockQuoteProxy" transports="jms" startOnLoad="true">
      <target>
         <inSequence>
            <property name="OUT_ONLY" value="true"/>
            <callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService">
               <source type="envelope"/>
               <target key="placeOrder"/>
            </callout>
            <log level="custom">
               <property name="Transaction Action" value="Committed"/>
            </log>
         </inSequence>
         <faultSequence>
            <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
            <log level="custom">
               <property name="Transaction Action" value="Rollbacked"/>
            </log>
         </faultSequence>
      </target>
      <parameter name="transport.jms.ContentType">
         <rules>
            <jmsProperty>contentType</jmsProperty>
            <default>application/xml</default>
         </rules>
      </parameter>
      <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
      <parameter name="transport.jms.DestinationType">queue</parameter>
   </proxy>

 You need to add following paramters to the axis2.xml under ESB_HOME/repository/conf/axis/

  <parameter name="myQueueConnectionFactory" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<parameter name="transport.jms.ConcurrentConsumers" locked="false">50</parameter>
<parameter name="transport.jms.MaxConcurrentConsumers" locked="false">50</parameter>
                <parameter name="transport.jms.SessionTransacted">true</parameter>
                <parameter name="transport.jms.SessionAcknowledgement" locked="true">CLIENT_ACKNOWLEDGE</parameter>    
  <parameter name="redeliveryPolicy.maximumRedeliveries" locked="true">-1</parameter>
<parameter name="redeliveryPolicy.redeliveryDelay" locked="true">2000</parameter>
<parameter name="transport.jms.CacheLevel">consumer</parameter>
</parameter>


You may required to add following jar to ESB 4.6.0 as patch https://www.dropbox.com/s/3u1agai803vt2cw/axis2-transport-jms_1.1.0.wso2v7.jar

Friday, June 21, 2013

LDAP - Apache Directory Studio: A Basic Tutorial

Following Link might be quite useful if anyone would like to configure LDAP with Apache Directory Studio.

http://krams915.blogspot.com/2011/01/ldap-apache-directory-studio-basic.html

JMS message store with weblogic ESB 4.6.0


To setup the JMS message store with weblogic, please follow the steps as mentioned below.

1. Set the transport receiver configuration as below in ESB_HOME/repository/conf/axis2/axis2.xml

   <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
       <parameter name="myQueueConnectionFactory" locked="false">
               <parameter name="java.naming.factory.initial" locked="false">weblogic.jndi.WLInitialContextFactory</parameter>
               <parameter name="java.naming.provider.url" locked="false">t3://localhost:7001</parameter>
               <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">jms/myconnectionFactory</parameter>
               <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
               <parameter name="transport.jms.UserName" locked="false">weblogic</parameter>
               <parameter name="transport.jms.Password" locked="false">admin123</parameter>
       </parameter>
       <parameter name="default" locked="false">
               <parameter name="java.naming.factory.initial" locked="false">weblogic.jndi.WLInitialContextFactory</parameter>
               <parameter name="java.naming.provider.url" locked="false">t3://localhost:7001</parameter>
               <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">jms/myconnectionFactory</parameter>
               <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
               <parameter name="transport.jms.UserName" locked="false">weblogic</parameter>
               <parameter name="transport.jms.Password" locked="false">admin123</parameter>
       </parameter>
   </transportReceiver>

2. Create a queue connection factory named ‘myconnectionFactory’ with JNDI name ‘jms/myconnectionFactory’
3. Create queue named ‘wso2MessageQueue’ with JNDI name ‘jms/wso2MessageQueue’
4. Remove the following packages from the ‘wlfullclient.jar’ weblogic java clien.
  • javax.jms
  • javax.xml.namespace

5. Copy the wlfullclient.jar to repository/components/lib of the ESB
6. You need to apply a patch to the org.wso2.carbon.message.store jar. Copy the patched org.wso2.carbon.message.store_4.0.5.jar to repository/components/plugins
7. Start the server (Weblogic server should be running)
8. Create a message store using the ESB. The message-store parameters should be as follows.

<messageStore name="wso2MessageStore" class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" xmlns="http://ws.apache.org/ns/synapse">
  <parameter name="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</parameter>
  <parameter name="java.naming.provider.url">t3://localhost:7001</parameter>
  <parameter name="store.jms.destination">jms/wso2MessageQueue</parameter>
  <parameter name="store.jms.connection.factory">jms/myconnectionFactory</parameter>
  <parameter name="store.jms.username">weblogic</parameter>
  <parameter name="store.jms.password">admin123</parameter>
  <parameter name="store.jms.JMSSpecVersion">1.1</parameter>
  <parameter name="store.jms.cache.connection">false</parameter>
  <parameter name="store.jms.ConsumerReceiveTimeOut">300</parameter>
  <parameter name="vender.class.loader.enabled">false</parameter>
</messageStore>

9. Save the message store. This would query the JMS queue in weblogic for the queue size and the resulting list view would show the number of messages in the queue.
10. You can send messages to a queue using a proxy configuration similar to the following.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="weblogicJmsStore" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
  <target>
     <inSequence>
        <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
        <property name="target.endpoint" value="SimpleStockQuoteService"/>
        <log level="full"/>
        <store messageStore="wso2MessageStore"/>
     </inSequence>
  </target>
  <description></description>
</proxy>

11. Send a message using the try this service for the proxy.
12. View the sent message via the message store UI of the ESB.

https://www.dropbox.com/s/cmwhewpm6asw5j6/org.wso2.carbon.message.store-4.0.5.jar

Thursday, June 20, 2013

VFS Filtering Message based on different Error conditions


<proxy xmlns="http://ws.apache.org/ns/synapse" name="XXX" transports="vfs" statistics="enable" trace="enable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full">
            <property name="Processing file" expression="$trp:FILE_NAME"/>
         </log>
         <property name="transport.vfs.ReplyFileName" expression="$trp:FILE_NAME" scope="transport"/>
         <property name="fileName" expression="$trp:FILE_NAME" scope="default"/>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="ORGINAL_MESSAGE"/>
         </enrich>
         <send>
            <endpoint>
               <address uri="http://localhost:8089/mockSimpleStockQuoteServiceSoap11Binding" format="soap11"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <filter xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://org.apache.synapse/xsd" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xpath="s11:Body/s11:Fault | s12:Body/s12:Fault">
            <then>
               <enrich>
                  <source type="property" clone="true" property="ORGINAL_MESSAGE"/>
                  <target type="body"/>
               </enrich>
               <log level="custom">
                  <property name="ERROR FTP  ##################" value="eeeeeee"/>
               </log>
               <property name="transport.vfs.ReplyFileName" expression="$ctx:fileName" scope="transport"/>
               <property name="OUT_ONLY" value="true"/>
               <send>
                  <endpoint>
                     <address uri="vfs:file:///home/dushan/onlinesupport/session7/BEBusinessServiceError"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <drop/>
            </else>
         </filter>
      </outSequence>
      <faultSequence>
         <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>
         <enrich>
            <source type="property" clone="true" property="ORGINAL_MESSAGE"/>
            <target type="body"/>
         </enrich>
         <log level="custom">
            <property name="ERROR FTP  ##################" value="eeeeeee"/>
         </log>
         <property name="transport.vfs.ReplyFileName" expression="$ctx:fileName" scope="transport"/>
         <property name="OUT_ONLY" value="true"/>
         <send>
            <endpoint>
               <address uri="vfs:file:///home/dushan/onlinesupport/session7/BEConnectionfail"/>
            </endpoint>
         </send>
      </faultSequence>
   </target>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/dushan/onlinesupport/session7/in</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/dushan/onlinesupport/session7/out</parameter>
   <parameter name="transport.vfs.FailedRecordNextRetryDuration">1000</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/dushan/onlinesupport/session7/fail123</parameter>
   <parameter name="transport.vfs.Locking">false</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
   <parameter name="transport.vfs.ContentType">application/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <parameter name="transport.vfs.MaxRetryCount">2</parameter>
   <description>:)</description>
</proxy>
                               

Sunday, May 26, 2013

Adding Root Element for Aggregate Response (Alternative)

Following code segment shows the, possible alternative way of adding root element to the response when Iterator/Aggregate in use, there are tons of alternatives but this just works for you...


<proxy xmlns="http://ws.apache.org/ns/synapse" name="IteratorProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="ORINAL_SOAP"/>
         </enrich>
         <payloadFactory media-type="xml">
            <format>
               <test/>
            </format>
         </payloadFactory>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="RESPONSE_WRAPPER"/>
         </enrich>
         <enrich>
            <source type="property" clone="true" property="ORINAL_SOAP"/>
            <target type="body"/>
         </enrich>
         <iterate xmlns:xsd="http://services.samples/xsd" xmlns:ser="http://services.samples" id="iteratorID" expression="//ser:Requests/ser:getQuote">
            <target>
               <sequence>
                  <send>
                     <endpoint>
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                     </endpoint>
                  </send>
               </sequence>
            </target>
         </iterate>
      </inSequence>
      <outSequence>
         <enrich>
            <source type="body" clone="true"/>
            <target action="child" xpath="$ctx:RESPONSE_WRAPPER"/>
         </enrich>
         <aggregate id="iteratorID">
            <completeCondition>
               <messageCount min="-1" max="-1"/>
            </completeCondition>
            <onComplete expression="$body/child::*">
               <log level="custom">
                  <property name="MESSAGE###########################3" expression="$ctx:RESPONSE_WRAPPER"/>
               </log>
               <payloadFactory media-type="xml">
                  <format>
                     <dummy/>
                  </format>
               </payloadFactory>
               <enrich>
                  <source clone="true" xpath="$ctx:RESPONSE_WRAPPER"/>
                  <target type="body"/>
               </enrich>
               <send/>
            </onComplete>
         </aggregate>
      </outSequence>
   </target>
   <description></description>
</proxy>
                             


the ultimate response will be looked as,


<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <test xmlns="http://ws.apache.org/ns/synapse">
         <ns:getQuoteResponse xmlns:ns="http://services.samples">
            <ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <ax21:change>4.2866157514113805</ax21:change>
               <ax21:earnings>12.584682581151846</ax21:earnings>
               <ax21:high>75.5962918071053</ax21:high>
               <ax21:last>72.60406241158645</ax21:last>
               <ax21:lastTradeTimestamp>Sun May 26 21:25:05 IST 2013</ax21:lastTradeTimestamp>
               <ax21:low>75.8658711254791</ax21:low>
               <ax21:marketCap>-3467898.59685205</ax21:marketCap>
               <ax21:name>IBM Company</ax21:name>
               <ax21:open>-71.56274026362532</ax21:open>
               <ax21:peRatio>23.075895025476</ax21:peRatio>
               <ax21:percentageChange>-5.90419120121126</ax21:percentageChange>
               <ax21:prevClose>-72.60292909436893</ax21:prevClose>
               <ax21:symbol>IBM</ax21:symbol>
               <ax21:volume>15608</ax21:volume>
            </ns:return>
         </ns:getQuoteResponse>
         <ns:getQuoteResponse xmlns:ns="http://services.samples">
            <ns:return xsi:type="ax21:GetQuoteResponse" xmlns:ax21="http://services.samples/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
               <ax21:change>-2.750820910784016</ax21:change>
               <ax21:earnings>-9.787293133205745</ax21:earnings>
               <ax21:high>-75.16825065031121</ax21:high>
               <ax21:last>75.80190597722125</ax21:last>
               <ax21:lastTradeTimestamp>Sun May 26 21:25:05 IST 2013</ax21:lastTradeTimestamp>
               <ax21:low>-74.79485577495237</ax21:low>
               <ax21:marketCap>-5189872.124349184</ax21:marketCap>
               <ax21:name>DLL Company</ax21:name>
               <ax21:open>-74.65259440061676</ax21:open>
               <ax21:peRatio>24.229158211448674</ax21:peRatio>
               <ax21:percentageChange>3.6744576753831906</ax21:percentageChange>
               <ax21:prevClose>-74.86331736008216</ax21:prevClose>
               <ax21:symbol>DLL</ax21:symbol>
               <ax21:volume>16903</ax21:volume>
            </ns:return>
         </ns:getQuoteResponse>
      </test>
   </soapenv:Body>
</soapenv:Envelope>



                               

Tuesday, April 2, 2013

VFS Best way to define with fault handlers

The following describes one of the best way that VFS can be configured with proper error handlers,  the idea here is, if the messge failed to deliver to any endpoint defined, then it will be revert back to the origin user defined location.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="XXX" transports="vfs" statistics="enable" trace="enable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom">
            <property name="Processing file" expression="$trp:FILE_NAME"/>
         </log>
         <property name="transport.vfs.ReplyFileName" expression="$trp:FILE_NAME" scope="transport"/>
         <property name="OUT_ONLY" value="true"/>
         <property name="ContentType" value="application/pdf" scope="axis2"/>
         <property name="ClientApiNonBlocking" scope="axis2" action="remove"/>
         <send>
            <endpoint>
               <address uri="vfs:ftp://a:a@192.168.43.1:50001/files">
                  <markForSuspension>
                     <retriesBeforeSuspension>2</retriesBeforeSuspension>
                     <retryDelay>1</retryDelay>
                 </markForSuspension>
              </address>
            </endpoint>
         </send>
      </inSequence>
      <faultSequence>
         <log level="custom">
            <property name="ERROR FTP  ##################" value="eeeeeee"/>
         </log>
         <send>
            <endpoint>
              <address uri="vfs:file:///home/dushan/poc/server/4.0.5-pack-new/dushan/fail"/>
           </endpoint>
        </send>
      </faultSequence>
   </target>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.vfs.FailedRecordNextRetryDuration">5000</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/dushan/poc/server/4.0.5-pack-new/dushan/out</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/dushan/poc/server/4.0.5-pack-new/dushan/in</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/dushan/poc/server/4.0.5-pack-new/dushan/fail</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.pdf</parameter>
   <parameter name="transport.vfs.ContentType">application/pdf</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <parameter name="transport.vfs.MaxRetryCount">2</parameter>
   <description>Amtrust Production</description>
</proxy>