Tuesday, June 26, 2018

Dockerizing Spring Boot App using Maven

This post details the steps required to dockerize an existing Spring Boot App
  1. Create a Spring Boot App
  2. Run  and verify the working of the App
  3. Include the following  build plugin details  in  POM file to create the docker image

Monday, June 25, 2018

JSON API

JSON API is a specification that defines the standards for exposing and consuming API from Server and Client perspective.This brings in a common convention that provides a mutual understanding of interaction patterns between the client and server.JSON API formulates 3Rs - Resources,Relationship and Repository

There are a number of open source library available in different languages to support  JSON API . In Java, the following are a few
  • katharsis
  • crnk
  • Elide
Adhering to JSON API increases the efficiency and performance of API consumption model by reducing the number of requests and amount of data transmitted .

Friday, February 26, 2016

JAXB UnmarshalException when converting Payload in Camel

Camel provides camel-jaxb jar  for converting XML to POJO data and vice versa using JAXB data format.
The samples provided in the documentation states that the contextPath should be set to the Java Package of the POJO class for the marshaling and unmarshaling purposes.
But when trying to set the contextPath to a required class package  it throws the exception “javax.xml.bind.UnmarshalException: unexpected element Expected elements are (none)
This is raised because meta-data information is missing and the registryFormat element is not found in the context. This can be fixed by creating the Context with the Object Factory class and using this reference to unmarshal the data. 
JAXBContext jaxbContext = JAXBContext
                           .newInstance(new Class[] { com.test.ObjectFactory.class });
              DataFormat registryFormat = new JaxbDataFormat(jaxbContext);
              from("file:in?noop=true").convertBodyTo(org.w3c.dom.Document.class)
                           .unmarshal(registryFormat)
                           .log("The message after conversion" + "${body}");      

Saturday, January 23, 2016

Unresolved constraint error when installing bundles in Fuse

When installing a bundle in Fuse, it quite common  to encounter the Unresolved constraint error: missing requirement: osgi.wiring.package error.
This error is thrown when the packages imported using Felix plugin are in conflict or if the dependent bundles are not installed. 
The article in this link provides a detailed explanation on the cause and fixes for this error 
But for those looking for quick fix ,the following steps would be handy.
  • Use osgi:headers <> to list the manifest details of the bundle.
  • In the manifest details,check for packages are marked in Red in Import-Package Listing. These are the  candidates which potentially cause this error.
  • Verify if the bundle corresponding to the erroneous package is installed and started 
These  steps should help to resolve most of the unresolved constraint exception when installing a bundle.

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>