Wednesday, October 3, 2012

Compare Restful and Soap Webservice

Why SOAP?

Here are a few reasons you may want to use SOAP.

Why REST?

Here are a few reasons why REST is almost always the right answer.
Since REST uses standard HTTP it is much simpler in just about ever way. Creating clients, developing APIs, the documentation is much easier to understand and there aren’t very many things that REST doesn’t do easier/better than SOAP.
REST permits many different data formats where as SOAP only permits XML. While this may seem like it adds complexity to REST because you need to handle multiple formats, in my experience it has actually been quite beneficial. JSON usually is a better fit for data and parses much faster. REST allows better support for browser clients due to it’s support for JSON.
REST has better performance and scalability. REST reads can be cached, SOAP based reads cannot be cached.
It’s a bad argument (by authority), but it’s worth mentioning that Yahoo uses REST for all their services including Flickr and del.ici.ous. Amazon and Ebay provide both though Amazon’s internal usage is nearly all REST source. Google used to provide only SOAP for all their services, but in 2006 they deprecated in favor of REST source. It’s interesting how there has been an internal battle between rest vs soap at amazon. For the most part REST dominates their architecture for web services.

 

WS-Security

While SOAP supports SSL (just like REST) it also supports WS-Security which adds some enterprise security features. Supports identity through intermediaries, not just point to point (SSL). It also provides a standard implementation of data integrity and data privacy. Calling it “Enterprise” isn’t to say it’s more secure, it simply supports some security tools that typical internet services have no need for, in fact they are really only needed in a few “enterprise” scenarios.

WS-AtomicTransaction

Need ACID Transactions over a service, you’re going to need SOAP. While REST supports transactions, it isn’t as comprehensive and isn’t ACID compliant. Fortunately ACID transactions almost never make sense over the internet. REST is limited by HTTP itself which can’t provide two-phase commit across distributed transactional resources, but SOAP can. Internet apps generally don’t need this level of transactional reliability, enterprise apps sometimes do.

WS-ReliableMessaging

Rest doesn’t have a standard messaging system and expects clients to deal with communication failures by retrying. SOAP has successful/retry logic built in and provides end-to-end reliability even through SOAP intermediaries.

Summary

In Summary, SOAP is clearly useful, and important. For instance, if I was writing an application to interface with my bank I would definitely need to use SOAP. All three features above are required for banking transactions. For example, if I was transferring money from one account to the other, I would need to be certain that it completed. Retrying it could be catastrophic if it succeed the first time, but the response failed.

Source: http://spf13.com/post/soap-vs-rest/
 

Monday, June 11, 2012

MYSQL - Special Character persisted for hyphon - Solution

Root cause of persisting/displaying of special character is Characterset of MYSQL database.

Execute below query in DB, check the  character set values. Character set client need to be in UTF8 format.

If it is working in testing db and not working in production db, then you can compare the result by running below sql query iin both the db and compare it. Comparing result can be applied in production db from testing db.

"SHOW VARIABLES LIKE 'character_set%';"

Tuesday, June 5, 2012

Solution for Spring circular reference

In Spring injection we may come acros circular reference exception.

Example for circular reference:
 <bean id="lookupService " class="com.AddressLookupServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>  
   <bean id="xyzService" class="com.XYZServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>    


  Here bean lookupService is referring to bean xyzService. Again bean xyzServiceis referring to lookupService. This is called circular reference.

To avoid circular reference issue, instead of having reference in child to parent we can just have the reference in parent bean alone as given below    

 <bean id="lookupService " class="com.AddressLookupServiceImpl">  
     <property name="xyzService" ref="xyzService" />  
   </bean>  
   <bean id="xyzService" class="com.XYZServiceImpl">  
   </bean>    

 Error creating bean with name 'XYZ': Bean with name 'XYZ' has been injected into other beans [XYZHelper, AHelper] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.

Solution for NoSuchMethodError

Sometime we face NoSuchMethodError exception in production environment. One of the root cause of this exception is same class exist in two different jar. But particular method is not present in the loaded class.

Lets explain with an example below exception says method readWSDL is not available in WSDLReader class.
In my project  WSDLReader class was available in two different jars namely axis-wsdl4j-1.5.1.jar and wsdl4j-1.6.2.jar. WSDLReaderinside axis jar doesn't have the method readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;). So we can exclude axis jar from pom and use only wsdl4j-1.6.2.jar.

Exception:
java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition;

POM changes:

 <dependency>  
       <groupId>com.ExampleService</groupId>  
       <artifactId>service</artifactId>  
         <exclusions>  
            <exclusion>  
             <artifactId>axis-wsdl4j</artifactId>  
             <groupId>axis</groupId>  
           </exclusion>  
         </exclusions>  
   </dependency  
               
   dependency>  

Wednesday, March 28, 2012

Master/Slave database - Replication Database

What is Master/Slave database?

Syncronized data between two database is set to be maste/Slave configuration.

When to consider Master/Slave database approach?
It is helpful in Batch Reporting Application.
In usual realtime there will be two application one as portal application and another is batch reporting application. Portal application can use the Master DB and Batch process can use Slave DB. Slave DB get the replicated data from Master DB. This replication usually taken care by DBA. So dev team concentrate on business logic.

What is the advantage of Master/Slave database approach?
Performance :)
Because Portal can keep using the Master and there is no hindrance in database by huge sql activity in slave DB. Batch can continue using the slave DB as and when required.

Wednesday, March 21, 2012

JUnit Mockitto - Void Method Testing

To test the void method using Junit and Mockitto use below approach
Concider someMethod s a void method inside  SomeClass

Use the below approach:

SomeClass classObjMock = (Mock)SomeClas;
doNothing().doThrow(new RuntimeException()).when(classObjMock).someMethod ();

JUnit Code Coverage - EClemma

EClemma  works pretty well to know the JUnit code coverage from eclipse
It displays green shade for the files which is covered and red for the lines which are not code covered.

Junit class file -> Right click -> Coverege As -> Junit

http://www.eclemma.org/installation.html


Unzip the archive into dropins folder of your Eclipse installation and restart Eclipse:
/
+- dropins/
   +- eclemma-x.y.z/
      +- plugins/
      |  +- ...
      +- feature/
         +- ...