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/
         +- ...

Tuesday, February 28, 2012

Google App Engine - Supported Framework

Google App Engine Supports Spring Framework. List of frameworks supported by GAE is listed below.

http://code.google.com/p/googleappengine/wiki/WillItPlayInJava

Google App Engine - Sample code - Java/Phyton
http://code.google.com/p/pgae-examples/downloads/list