Wednesday, February 12, 2014

Deploy and Enable Rampart in Axis2 ( Tomcat)


Please follow below steps to deploy rampart module and enable rampart for axis services which is deployed in Tomcat. Also you can follow same for deploying axis2 standalone or in another application server.

Step 1: Install and configure  axis2 in tomcat

Deploy axis2 in tomcat as explained here ( http://jayalalk.blogspot.com/2014/01/writing-axis2-services-and-deploying-in.html ). you can ignore this if you have already tomcat with axis2 module.

Step 2: Download the rampart module

Download the rampart latest binaries from http://axis.apache.org/axis2/java/rampart/download.html

Step 3: Extract the rampart distribution to a folder and copy modules and jar files


- Copy the  rahas-x.x.x.mar and rampart-x.x.x.mar  files from module directory to the TOMCAT_HOME/webapps/axis2/WEB-INF/modules
- Copy all the jars from lib folder to the TOMCAT_HOME/axis2/WEB-INF/lib

Step 4: Enable the rampart in axis2


- Add     <module ref="rampart"/> in  TOMCAT_HOME/webapps/axis2/WEB-INF/conf/axis2.xml to enable rampart for all services.
- If you want to enable rampart only for given service then you can edit services.xml and add <module ref="rampart"/>

Step 5: Verify the rampart enabled

- Login to adminstrative console  (http://localhost:8080/axis2/axis2-admin/ )
- Default user name password ( admin/axis2)
- Verify the modules engagement
System components --> Available Modules
System components --> Globally Engaged Modules

Sunday, January 12, 2014

Writing Axis2 Services and deploying in Tomcat

There are three different ways which we can write Axis2 services (Web service  )  and can be deployed in Axis2 Server itself or in a web container like Tomcat.

Different ways of deploying services


  1. As simple POJO class in ..\webapps\axis2\WEB-INF\pojo\HelloWorld.class
  2. As JAR bundle  in ..\webapps\axis2\WEB-INF\pojo\myservice.jar
  3. As a service archive in  ..\webapps\axis2\WEB-INF\services\myservice.aar

We will focus on deploying service as AAR archive, which is best out of 3 deployment types mentioned above.


Getting Ready:

- Download and install Java (Minimum version is JDK1.5). Set the JAVA_HOME environment .
- Install latest version of  Tomcat in your environment ( http://tomcat.apache.org), and verify working properly. ( Sample code on this blog was test with Tomcat 7 as it was the latest stable version)

Download and install Axis2 module in tomcat


1. Download Axis2 WAR Distribution from below location. ( Version 1.6.2  was the latest at this time )

2. Deploy the Axis2 War into tomcat as a web application

- Unzip the axis2-1.6.2-war.zip
- You will get axis2.war file , then unzip this again. you will get axis2 folder containing axis2 deployable web app.
- Now copy the "axis2" folder into <TOMCAT_HOME>/webapps

3. Now start the Tomcat if it is down already, and verify the axis2 default services are running.

- Check available services in axis2 module  http://localhost:8080/axis2/services/listServices
- You will notice the getVersion application is running.
- Verify the webservice is running properly by invoking http://localhost:8080/axis2/services/Version/getVersion
You will get the axis2 version details in your screen  :) , you have verify your web service with REST style

If you need to verify this as Web-Service call using SOAP UI or Java client you can get WSDL with from http://localhost:8080/axis2/services/Version?wsdl

Writing our sample service

Lets write our own sample Web-Service using simple button up method ,where we have not even required to write any WSDL rather just know the java methods/operations needs to be exposed.

1. Writing service class

We will write simple POJO class which we are going to expose as web-service through Axis2 services, and simple supportive class to help on writing our main service class.

Our main service class (CountryService.java)  will expose its public methods as axis2 web services.



package com.jk.axis2.ws;

public class CountryService {
      
       public Country getCountryDetails(String countryCode) {
             
              System.out.println("countryCode =" + countryCode);
              Country country = null;

              if (countryCode != null) {
                     if (countryCode.equalsIgnoreCase("SL")) {
                           country = new Country("Sri Lanka");
                           country.setCountryCode(countryCode);
                           country.setCity("Colombo");
                           return country;
                     } else if (countryCode.equalsIgnoreCase("FR")) {
                           country = new Country("France");
                           country.setCountryCode(countryCode);
                           country.setCity("Paris");
                           return country;
                     }
              }

              return new Country("NotDefined");
       }
            
       public String getServiceVersion(){
              return "This is initial version 1.0";
       }
      
       public String testEcho(String name){
              return "Testing echo with " + name ;
       }
}





Support Country bean  to provide services through CountryService.


package com.jk.axis2.ws;

public class Country {

       String countryCode =null;
       String city=null;
       String name =null;
      
       public Country(){
             
       }
      
       public Country(String name){
              this.name=name;
       }
      
       public String getCountryCode() {
              return countryCode;
       }
       public void setCountryCode(String countryCode) {
              this.countryCode = countryCode;
       }
       public String getCity() {
              return city;
       }
       public void setCity(String city) {
              this.city = city;
       }
       public String getName() {
              return name;
       }
       public void setName(String name) {
              this.name = name;
       }
                    
}




2. Writing  deployment configuration ( services.xml )

To deploy your service archive , you need to have deployment descriptor inside service archive  which tells deployment module to deploy your service as axis2 service.

Basically you can have one or many services inside one single archive file , and can be listed around <ServiceGroup> tag. In this sample we will have only one service inside our service archive.

Our sample services.xml file content.

<serviceGroup>
<service name="CountryService" scope="application">
<messageReceivers>
                                <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
                                                                class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
                                <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
                                                                class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
<parameter locked="false" name="ServiceClass">com.jk.axis2.ws.CountryService</parameter>
</service>
</serviceGroup>


We can define our message receivers inside services.xml  for  each operation separately or as a default for all the services inside services.xml.  We have defined message receivers for all services as .

you can overwrite this as you wish by simply adding messages receiver for specific operation in services.xml as below.

<service>
...
<operation name="testEcho">
<messageReceiver class="org.apache.axis2.receivers. RawXMLINOutMessageReceiver"/> </operation>
</service>


Deploy the sample CountryService.aar  in Axis2



1. Create your service archive file

-Create simple ZIP file and rename as "CountryService.aar"
-Content will be as below




2. Now copy the  CountryService.aar in to the <TOMCAT_HOME>/webapps/axis2/WEB-INF/services   directory

Now your WebService is ready to access.
You will see the CountryService is deployed already.

Try calling service in REST style.

If you need to access as SOAP webservice ,use the WSDL from the path.

Monday, December 2, 2013

The Check List for Documenting Software Architecture.

                       Software architecture has emerged as an important sub-discipline of software engineering,particularly in the realm of large system development. While there is no universal definition of software architecture, there is no shortage of them.

However What those definitions have in common is their emphasis on architecture as a description of a system as a sum of smaller parts, and how those parts relate to and cooperate with each other to perform the work of the system. Architecture gives us intellectual control over the very complex by allowing us to substitute the complex with a set of interacting pieces, each one of which is substantially simpler than the whole.






Why we need Software Architecture in a document ?


Professor Dijk-stra’s consideration for the reader reflects his classic manners, but it also gives us a new and useful concept of the effort associated with a document. Usually we just count how long it takes to write. Dijkstra taught us to be concerned with how long it takes to use.

  • The goal of documenting an architecture is to write it down so that others can successfully use it, maintain it, and build a system from it. The blue-print for developing a Software System.
  • Documentation exists to further architecture’s uses as a means of education, as a vehicle for communication among stakeholders, and as the basis for analysis.
  • Documenting an architecture is a matter of documenting the relevant views and then adding documentation that applies to more than one view.
  • Documentation should pay for itself by making development activities less costly.


Check List( 7 Rules)  for documenting the Software Architecture.

1.  Write documentation from the Reader's point of view.

  • Find out who your readers are, what they know, and what they expect from the  document. The best way to get to know your stakeholder is to have a informal chat and make sure not doing any wrong assumptions on them.
  • Don't write the content as  it easy for you or as it come to your mind, make sure you get the big picture of the overall document. You can break down the document into the sections and make sure relevant sections provide answers to some of architectural concerns.

  • Avoid specialized terms and jargon, since reader may not be sharing same terms as you do, so add a glossary to define your terms.

  • Avoid overuse of acronyms , if your phrase is not used many times in the doc or short in length then better to use as it is.

2. Avoid Unnecessary repetition.

  • Need to make sure same content is not repeated on different places , which will put reader into trouble when when you had updated the content in one place and forgot to change at all other places. So the best way to handle this, keep common content referenced by a reference number  or using hyper link ( in a soft copy ).

3. Avoid Ambiguity
Ambiguity occurs when documentation can be interpreted in more than one way and at least one of those ways is incorrect.


  • Avoid needless repetition ( as in rule 2 above ) 
  • Use well defined notations and precise semantics as much as possible.
  • The ubiquitous box-and-line diagrams that people always draw on whiteboards are one of the greatest sources of ambiguity in architecture documentation , if you use such make sure you have notation to explain what it means for. Simple arrow can represent many things like, calling the other module , data flow  etc.

4. Use standard Organisation/Template.
  • It helps the reader navigate the document and find specific information quickly
  • The template already provides an outline of the important topics to cover and  helps the document writer plan and organize the contents.

  • It reveals what work remains to be done by the number of sections labeled “TBD”

5. Record rationale
  • You should record why you made them the way you did. You should also record the important or most likely alternatives you rejected and state why
  • You will find yourself revisiting the same arguments and wondering why you didn’t take another path.

6. Keep Documentation Current but Not too Current.


  • Documentation that is somehow inadequate to answer the current question needs to be fixed.
  • Updating it and then referring the questioner to it will deliver a strong message that the documentation is the final, authoritative source for information.
  • No need to keep updating the document on every decision made instantly, rather give it a proper time to go through final review /approval and then add it as the final update to the document.

7. Review Documentation for the Fitness of  purpose.


  • Before a document is released, have it reviewed by representatives of the community or communities for which it was written.Only the intended users of a document will be able to tell you whether it contains the right information.

Saturday, June 29, 2013

Java EE7 and Its Evaluatioon


After more than three years with JEE 6 , The latest iteration of java enterprise edition has landed, this version includes improvements and tweaks in different areas of Java EE, specially this version includes introduction of HTML 5. As java developers , we will able to more focus on writing our business logic than writing boilerplate code, have better support for the latest Web applications and frameworks, and gain access to enhanced scalability and richer, simpler functionality. New Java EE 7 will
benefit from new features that enable portable batch processing and improved scalability.

Evolution of Java Enterprise Platform
Over 15 years, Java enterprise platform has changed the world on enterprise  solution implementation and developers around the world  has committed to keep the momentum going.



1998 - 2004
Java EE evolved as enterprise application development platform , and main focus was on robustness and ease of development which extended to facilitate multitier server centric applications development, deployments and maintenance.


Features 
  •   Servlet and JSP
  •  EJB , CMP , RMI/IIOP
  •  Java Connector Architecture
  •  Web Services


2005 - 2012

The focus  shifted to increase developer efficiency and introduction of light weight frameworks like Web Profile as subset of  Java EE specification.

Features 
  •    Introduction of annotation.
  •    EJB 3 business component development model
  •    Persistence API
  •    RESTFull Web Services
  •    Web Profile and Managed beans


2013 - Future       
                                  
With increase demand of enterprise solution to be simplified and reusable , next level of Java EE will be moved into cloud (PaaS)support. Java EE8 will be mainly focus on cloud support  and etc.

Features 
  •    HTML 5 support
  •    Java API for Web Socket
  •            Batch Processing support for Java
  •            Concurrency utilities
  •     Native Jason support


Theme of JEE 7
There are 3 major themes of Java EE 7 as shown below.





Delivering HTML5 dynamic, scalable applications
  •    Reduce response time with low latency data exchange using WebSockets
  •    Simplify data parsing for portable applications with standard JSON support
  •    Deliver asynchronous, scalable, high performance RESTful Services and Async Servlets


Increasing developer productivity through simplification and new container services
  •    Simplify application architecture with a cohesive integrated platform
  •    Increase efficiency with reduced boiler-plate code and broader use of annotations
  •    Enhance application portability with standard RESTful web service client support


And meeting the additional demands of the enterprise by adding new enterprise technologies.
  •    Break down batch jobs into manageable chunks for uninterrupted OLTP performance
  •           Easily define multithreaded concurrent tasks for improved scalability
  •    Deliver transactional applications with choice and flexibility

Major 4 features in Java EE 7

1. HTML5 , Web Socket and Client/Server endpoints


  • Java EE7 is mainly focused on HTML5 and its improvements to the spec,  which allows to develop multimedia enriched web applications , support will be via Web Socket and JSON.
  •  Web Socket is a way of two way communication with web app and the remote server in HTTP fashion with bidirectional full-duplex TCP connection.
  •  Annotation makes everything simple
                                @ServerEndpoint  - convert your POJO class to be web socket server
                  @ClientEndpoint  -  convert your POJO  class to be client socket end point.