Tuesday, May 22, 2012

How to write & Configuring JSON web service for Apache Axis2


Recently I was working on one of the project where there was requirement of implementing the Axis2 Web service with JSON support. Here I have used Apache Tomcat 7.0 Web Server for configuration. During initial phase I have gone through the documentation provided on Apache site for JSON Support and thought it would be easy to implement as we can write any POJO service first and that SOAP Service can be exposed as JSON Web Service.However it was not so simple as there were issues in the library used ie. Jettison. This library requires patch to support functionality.

JSON stands for Java Script Object Notation. And it is data exchange format similar to XML. JSON is very light weight and becoming popular these days.It defines data in key value pair as we are doing in case of Properties file however here we maintain parent child relationship as well. You can find more information on this on JSON website.

As this article is written on how to configure JSON with Apache Axis2 on Tomcat 7.0. Below details cover only technical information on how to configure JSON and writing JSON Web Service.

For this article I am using Tomcat version 7.0.26 and it has been installed Red hat 5.6.Axis2 is installed and configure as explain in Apache's Axis2 Website. 

Tomcat Installation directory is : /usr/share/apache-tomcat-7.0.26/
Axis2 Installation directory : /usr/share/apache-tomcat-7.0.26/webapps


JSON Configuration changes on Tomcat 7.0

  1. Download Dynamic Response Handler and copy it to  /usr/share/apache-tomcat-7.0.26/webapps/axis2/WEB-INF/modules    
  2. \Go to /usr/share/apache-tomcat-7.0.26/webapps/axis2/WEB-INF/lib and rename jettison-1.0-RC2.jar Using below command         mv jettison-1.0-RC2.jar jettison-1.0-RC2.jar.bak  
  3.  Provide update jettison jar file. Copy patched jettison-1.2-patched.jar to /usr/share/apache-tomcat-7.0.26/webapps/axis2/WEB-INF/lib location & restart tomcat
  4. Modify axi2.xml at location /usr/share/apache-tomcat-7.0.26/webapps/axis2/WEB-INF/conf Add following Message Formatters and Message Builders.



    <messageFormatter contentType="application/json" 
    
                              class="org.apache.axis2.json.JSONMessageFormatter"/>
    
             <messageFormatter contentType="application/json/badgerfish"
    
                              class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
    
            <!--<messageFormatter contentType="text/javascript" 
    
                             class="org.apache.axis2.json.JSONMessageFormatter"/> -->
    <messageBuilder contentType="application/json"
                                     class="org.apache.axis2.json.JSONOMBuilder"/>
      <messageBuilder contentType="application/json/badgerfish"
                                     class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
      <!--<messageBuilder contentType="text/javascript"    
            class="org.apache.axis2.json.JSONOMBuilder"/>-->
    
    

    5. When we are performing conversion from XML to JSON and viceversa. There are two convention that we follow. which are mentioned above.
    - Mapped Convention
    - Badgerfish Convention

    Below is the example on how xml can be converted to JSON string for both the conventions which taken from Apache website

    XML If we use the namespace mapping as http://foo.com -> foo
    <xsl:root xmlns:xsl="http://foo.com"><data>my json string</data></xsl:root>


    Equivalent JSON (Mapped Convention)
    {"foo.root":{"data":"my json string"}}

    Equivalent JSON (Badgerfish Convention)
    {"xsl:root":{"@xmlns":{"xsl":"http://foo.com"},"data":{"$":"my json string"}}}


    Now you can simple develop your any web service application and can communicate with that service using JSON.

    6. You can simply create Hello World application to echo request message. and call that HelloWorld service as below get the response in JSON format.

    Mapped Convention : Http://localhost:8080/axis2/services/HelloWorldService/echoMethod/response=application/json

    Badgerfish Convention: Http://localhost:8080/axis2/services/HelloWorldService/echoMethod/response=application/json/
    7. And while sending a request to JSON service content-type should be set to application/json.

    I have not included the steps here to create POJO Service, this is very well documented on Apache website.

    Reference sites :
    http://jettison.codehaus.org/
    http://axis.apache.org/axis2/java/core/docs/json_support.html
    http://www.marcusschiesser.de/2009/01/building-a-json-web-service-with-java-and-axis2/


Thursday, October 6, 2011

Why Oracle Service Bus 11g ? Key Benefits and Advantages

This blog covers key benefits and advantages we can achieve with the implementation of Oracle Service Bus 11g. Actually I have been asked by Client to list down the capabilities they will get with the Oracle Service Bus 11g Implementation and this is what they got from me and lead to this blog finally.

1. Service Virtualization :

                      A core principle of SOA is to ensure that any service consumer can access any service provider - and from any platform. This has been considered as key principle in OSB and it provides robust way of Vitalizing the Service. It’s a great value add in SOA Architecture.

2. Loose Coupling

                     OSB provides loose coupling by mediating between Service provided and Consumer. Without mediation Service consumer and provider will create dependency to each other. A change in single side provider/consumer will lead to the change dependent consumer/provider respectively. OSB bridges the gap of transport, message format, security technology etc.

3. Location Transparency

                     It’s a strategy to hide physical location of actual physical location of service endpoints from the Service Consumer. All Service consumers should know only single logical machine & port name for each service. This allows for greater flexibility when managing your services. You can add, move, prioritize and remove service endpoints as needed without needing to recompile your service consumer again.

4. Seamless Connectivity

                     While newer applications may expose services over standard, easily consumable interfaces such as SOAP, an overwhelming majority of the services available in enterprises are still locked in legacy systems, from mainframes to custom applications. The first task of an OSB is to ensure that all these existing assets can be easily accessed and integrated. An OSB offers rich and comprehensive connectivity options to standard interfaces (SOAP, messaging, etc.) and also to packaged applications and legacy systems via adapters such Siebel Adapter, Peoplesoft Adapter etc.

5. Routing

                     After having a seamless connectivity next task is that data and messages need to flow reliably. OSB offers efficient, secure and reliable transport options. OSB also provides advance routing facilities to determine where the data needs to go. Such routing can be done based on headers, content or other external rules.

6. Performance

                      OSB is stateless & light weight; hence provide the excellent performance result under stress conditions as well.

7. Transformation

                       Oracle Service Bus provides run time transformation capability and support industry standard for middleware :XML, XSLT, XQuery & XPath.

8. Support for Event Driven Architecture

                       Oracle Service Bus support Oracle’s latest Event Driven Architecture.

9. Security & Policy

                        OSB provides centralized way of implementing the Security for Integration which results into highest level of standardization and control on security issues. Security is best enforced using policy driven framework because it allows to implement security details outside of the Application & easy to maintain. This makes it complete pluggable component & highly Agile which can be changed without modifying the actual application as per the organization policy’s and compliance.

10. Service Polling

                       Oracle Service Bus supports service polling. This allows to OSB to automatically detect live service and remove others from the list. This has a significant impact in performance.

11. Load balancing & Failover

                       Oracle Service Bus supports multiple load balancing algorithms to load balance between endpoints. It automatically detects a failover and removes it from Load balanced urls.

12. Service Throttling

                       Service throttling is a new feature in Oracle Service Bus which allows to restrict the load for particular service. This has great value when it comes to Service up time.

13. Monitoring

                       Oracle Service Bus provides two way monitoring.
Proactive Monitoring: Here Integrator can monitor the dashboard and check the performance of the service bus which can help to tune the server effectively. Tracking the server performance over time can help to plan capacity planning well in advance.

Reactive Monitoring: Here OSB will monitor the Server and look for specific conditions to occur and it will automatically sends the Alert to users, Admin etc. Alert can be in the form of Email, JMS, SMS etc.

14. Message Validation

                       Oracle Service Bus support normal data level value check validation as well as Schematron Validation.

15. Value Added Feature

                  a. Support for Domain Value Map

                  b. Support for Cross Reference

                  c. Support for Package application Adapters

                  d. Support for Advance message formats such as SWIFT and FIX in financial Service Domain.