Friday, December 25, 2015

IllegalArgumentException when invoking a webservice from a Camel Route

If a service exposes more than one operation then the operation name and namespace should be set in the header before invoking the call from the Route.
The IllegalArgumentException or BindingOperationInfo Exception is thrown when the framework is not able to find the matching operation to invoke.To fix this ,verify the operation name and namespace from the service class defined in the CXF EndPoint Bean.If the operation name or namespace is different,the binding would fail and IllegalArgumentException would be thrown.To fix this error,ensure that  the operation name and namespace match with the details given the SEI class.
  
<route>
     <from uri="timer:foo?period=5000" />
     <setHeader headerName="operationName">
            <constant>generateText</constant>
    </setHeader>
    <setHeader headerName="operationNamespace">
       <constant>http://com.test/generateservice</constant>
   </setHeader>             
  <to uri="cxf:bean:generateService" />
 <log message="The message contains ${body}" />
</route>

Sunday, November 8, 2015

In-Memory Components

Camel provides in-memory components like  Direct, Direct VM,SEDA and VM .These components route  messages without using external broker.They should be used when performance or speed takes precedence over reliability requirements.

Direct/Direct VM :
The Direct component allows to make direct synchronous call between a producer and a consumer. This is the simplest component as it requires no additional configuration. It is mainly used to link routes within a Camel Context  and  to expose a route as a synchronous service.
Direct VM is similar to Direct ,only difference is that it supports communication across multiple Camel Context instances within the same JVM.

SEDA :
The SEDA component  is used for asynchronous messaging and is considered as low overhead replacement for JMS .SEDA allows messaging  within a single  Camel Context. It supports concurrent users  in which the configured end points will be triggered and run in separate thread.

VM is similar to SEDA except that it supports communication across multiple Camel Context instances within the same JVM.



Component   Pros Cons
Direct/Direct VM
  • Simple to use
  • Allows to reuse route
  • Minimal Overhead

  • Used only when Producer and Consumer are up at the same time, this may not be viable for all use cases.
  • Works on Single thread only
SEDA /VM
  • Faster than JMS as it is in memory
  • Supports concurrent users

  • Message Persistence not supported so there is a risk of losing message if event of   crash.
  • Transactions are not supported as each call is invoked  on a different thread.



Saturday, July 4, 2015

Improving performance by keeping payload simple and small

XML Schema Definition (XSD) is a means to represent the input and output parameters for web service operation. This is more popular choice compared to the other models like DTD because it doesn’t need additional parsers.

The size and complexity of the payload have immense impact on the performance. If the payload is huge and complex it would affect the performance as it takes long time to parse the content.

It is often observed that the payload usually has many fields with only a few being populated. Reducing the payload to include only the fields with values would help to reduce the network traffic and increase the processing speed. This can be achieved by explicitly setting the minOccurs value to 0.By default this is set to 1 in XSD.

The following example shows the definition of Meal type schema.

 <xs:element name="mealType">
   <xs:complexType>
     <xs:sequence>
      <xs:element name="category" type="xs:string"/>
       <xs:element name="starter"  minOccurs="0" maxOccurs="1"  type="xs:int"/>
       <xs:element name="mainCourse" minOccurs="1" maxOccurs="3"   type="xs:string"/>
       <xs:element name="dessert" minOccurs="0" maxOccurs="2"   type="xs:string"/>   
 </xs:sequence>
  </xs:complexType>
 </xs:element>

The starter and dessert field are optional and may not be populated for all meal types, hence the minoccurs is set to 0 for these fields.

(i) A sample payload with all fields populated would be as follows:

<mealType>
     <category>Executive Lunch </category>
     <starter>samosa </starter>
    <mainCourse>Rice <mainCourse>
    <mainCourse>Naan <mainCourse>
    <dessert>Ice cream </dessert>
 </mealType>

(ii )A sample payload with only few fields populated would be as follows:

 <mealType>
       <category>Budget Lunch </category>
       <mainCourse>Rice <mainCourse>
 </mealType>


Saturday, May 9, 2015

Kick-start Guide for JBoss Fuse Development

Hit many roadblocks when I started off  with JBoss Fuse development.Though the framework is great had to face a lot of impediments due to incompatible jars and outdated install documents.This post is to put forward  what worked for me and hope would be helpful for those out there who are yet to start their Fuse Journey.


JBoss Fuse is an open source Enterprise Service Bus (ESB). It is a robust SOA solution designed with build-in fail-over, load balancing and delayed message redelivery. It combines several technologies like core Enterprise Service Bus capabilities (based on Apache Camel, Apache CXF, Apache ActiveMQ), Apache Karaf and Fabric8 in a single integrated distribution.

Red Hat acquired FuseSource and JBoss Fuse was built upon FuseSource’s product, FuseESB.



Ref :
http://www.jboss.org/products/fuse/overview/

Prerequisite
JBoss Fuse is based on Apache Camel so it is better to have an understanding on Camel before exploring Fuse.

Requirements
Hardware 
Ø  400 MB free disk space
Ø  2 GB RAM
Software 
Ø   Fuse runtime platforms need Java 6, JRE 1.6.0_18 or later.

JBoss Fuse provides 3 types of Installation
·           Ø    Minimal—installs Apache Karaf, Apache Camel core, and selected Apache Camel components
·          Ø     Medium—installs Apache Karaf, Apache Camel;, and Apache ActiveMQ
       Ø     Full—installs Apache Karaf, Apache Camel, Apache ActiveMQ Apache CXF, and the JBI components

I        I chose Full install for my environment but based on the components required the appropriate install can be selected.

Installation Steps:
  1. Download JBoss Fuse 6.1.0.GA Full Zip (latest as of Apr/2015).
  2. Need to be a registered user of JBoss Developer to have access to download the file.
  3. Extract the downloaded file into a local folder. It is preferable to extract the file into a folder which does not have space in its path
  4. The Fuse server can be started using the <>/bin/fuse.bat. The following screen shows up if the server is successfully up.


Note:The loading should be 100%,if not check for the logs in <>/data/log folder for details

   The Fuse server is set up,now we need to set up the IDE.The IDE used here is JBoss developer Studio 8.1.0 GA

Prerequisite
Ø  Maven 3.3.1
Ø  JDK 1.6 or 1.7

Development Tools

JBoss Developer Studio  is an Eclipse based IDE which makes setting up and debugging of the Fuse application easier.
JBoss Developer Studio Integration Stack   is a plugin which provides tooling for developing, configuring and deploying Fuse applications.

Installation Steps
The Developer studio needs to be installed first and the Integration Stack can be added  later on.

  1. If maven is already installed in your system, then take a backup of the repository and settings.xml and delete these files. The fuse download has issues with the incompatible jars  which are in the repository.
  2. In the settings.xml, configure the JBoss EAP Maven repository,JBoss Community Maven repository and  make the repositories active by default.
  3. Download the stable jar from http://www.jboss.org/products/devstudio/download/ The stable jar as of  Apr/2015 is Red Hat JBoss Developer Studio 8.1.0.GA jar file (jboss-devstudio-8.1.0.GA-installer-eap) 
  4. Install the jar  (java -jar <> <>).
  5. Follow the instructions in the wizard. The installation may take 10 to 15 minutes.
  6. After this step Integration Stack can be updated.
  7. Select Software/Update from the JBoss Splash screen and choose the options as shown in the snapshot below.
  8. For the IDE version 8.1.0,the updates are available on Early access basis, so ensure to select the Enable Early access Check box.

   
   Once the Development Studio is set up, the Fuse project can be created using the Fuse Project Wizard.   Refer to this  tutorial for creating fuse project.
     

Sunday, March 24, 2013

Identifying Classes using modelling

Identifying the right classes for a System is an Art rather than a skill.Modelling too many classes results in too complex code which is difficult to maintain and may also result in poor performance.On the other hand if there are too few classes then it may result in tight coupling.Striking a balance between these provides the basis for a good design.
When designing a system,always believe that the best design is yet to come.Revisiting and Refining the proposed design will always aid to carve out the best design.The domain knowledge is essential key factor to come up with a good design.
Since it may not be feasible for a Designer to be a domain expert right from the begining ,there are some design guidelines to identify the classes.The most commonly used approaches are
1.Noun/Noun Pharses approach:
In this approach ,all the noun and noun phrases are identified from the requirements.
2. CRC card approach:
Using the Class Responsibility Collaborator approach,address a single requirement ,identify the similar objects and group them into a class .Add the responsibility and collaborations for this class.Extending the same to each requirement will render a list of Candidate classes.
Using these approaches,the list of candidate classes can be identified.From the list remove the classes which are duplicate and those which are not related to the system.On analysing the classes,if you find that the class does have significant purpose then define it as an attibute instead of a class .At the end of this analysis a number of candidate classes would be eliminated and the design classes would be derived from this list.
As the design progresses its very common to find that a few of the classes which were identified as the core classes may not be actually required .Having said that it is also possible to come up with totally new classes which were missed in the initial candidate class.
The right set of classes would eventually emerge after a number of interative and incremental cycles.

Saturday, January 19, 2013

Apache Hadoop

Apache Hadoop is an open source Java framework for processing large amount of distributed data.Hadoop is a Yahoo! initiated project to enable processing of very large data sets in a cost effective way.
It is based on Google's MapReduce algorithm which is a parallel and distributed solution approach for processing large datasets. MapReduce is utilized by Google and Yahoo for their websearch.Using MapReduce,data is transformed into a set of Key/Value pairs and later these are aggregated to provide the search results.
Data in Hadoop is broken down into smaller blocks and distributed throughout the cluster.This aids to execute the MapReduce functions on smaller subsets of the large data set.Apart from Java,Hadoop also provides linker for  C++ ,Perl,etc.
Hadoop is ideal for storing large amounts of data, like terabytes and petabytes.The Hadoop Distributed File System(HDFS) is employed as the storage system which is highly fault-tolerant and is designed to be deployed on low-cost hardware.It manages storage on the cluster by breaking incoming data into pieces, called “blocks,” and storing each of the blocks redundantly across the pool of servers. By default,
HDFS stores three complete copies of each file by copying each piece to three different servers but the number of copies is configurable.
Hadoop is very flexible,scalable  and can process large amount of data in parallel .This can be deployed on large clusters of commodity hardware,hence it is very cost effective.
Its ideal to use Hadoop  when there is a need to analyze enormous amount of information to understand the usage pattern and to predict demand.

Sunday, November 11, 2012

Nailing the Root Cause in Java Exceptions

Java provides chained exception facility which enables to nest an exception within another .But to get the deepest level exception,there are no direct methods available as of now.
Packages like  Apache's common lang provides convenience method to  get the root cause.
(http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/exception/ExceptionUtils.html)
The root cause can also be retrieved by manually iterating down the stack trace using getCause().
The following snippet is a recursive method that is used to retrieve the Root Cause.

public Throwable getMostSpecificException( Throwable exp ) { 
        Throwable t = exp;
        logger.debug( "exp.getMessage()-->" + exp.getMessage(  ) );
        if ( exp.getCause(  ) != null ) {
            t = exp.getCause(  );
            // recursive call
            getMostSpecificException( t );
        }
        return t;
    }