Pages

Wednesday, April 4, 2012

NumberFormatException : hibernrate fingByNamedQuery

HIBERNATE : Unable to Iterate through a list and leading to NumberFormatException in JSTL.
oops was struggling for an hour....finally got resolved
Debug Steps
1.Checked the DAOImpl ..
batchList = this.hibernateTemplate.findByNamedQuery("getMspBatchMstrList");
it was getting the object,but the was not the type of what I need."i.e com.chase.mortgage.pojo.MspBatchMstr"
2. Tried to iterate in DAOImpl this time got the exception."ClassCastException."
Realized it is somthing to do in the mapping file.
3.Added

it did the trick...





SELECT client as CLIENT,lk.msp_transaction as TRANS_ID,msp.msp_batch_number as MSP_BATCH_NUMBER, msp.batch_seq_num as BATCH_SEQ_NUM, msp.status as STATUS
FROM TRACKER.msp_batch_mstr msp, TRACKER.transaction_lkup lk
WHERE msp.trans_id=lk.trans_id
]]>

Wednesday, February 8, 2012

Internationalization support using Spring MVC application

To make Spring MVC application supports the internationalization, register two beans :
1.SessionLocaleResolver
If you don't register the localeResolver the default AcceptHeaderLocaleResolver will be used
to resolve locale by checking the "accept-language" header from the incomming HTTP request.
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">


Note :
If there is a repated need of locale resolution add the above code else we may
get the below exception.
java.lang.UnsupportedOperationException: Cannot change HTTP accept header - use a different locale resolution strategy

2.LocaleChangeInterceptor
Register this to support multiple languages.Property paramName is used to set the locale.

class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">









Friday, September 9, 2011

Cobertura -- Code Coverage Tool

public interface Instrumentation:
This class provides services needed to instrument Java programming language code. Instrumentation is the addition of byte-codes to methods for the purpose of gathering data to be utilized by tools. Since the changes are purely additive, these tools do not modify application state or behavior. Examples of such benign tools include monitoring agents, profilers, coverage analyzers, and event loggers.

coverage analysers fall into three categories:
Insert instrumentation into the source code
Add instrumentation to the Java byte-code
Run the code in a modified JVM.

"Cobertura" add instrumentation to the java byte code.
using Maven 2:


YET TO ADD

Friday, August 19, 2011

Unit Testing

http://docs.jboss.org/arquillian/reference/1.0.0.Alpha1/en-US/html_single/#d0e34

http://publib.boulder.ibm.com/infocenter/rtnlhelp/v6r0m0/index.jsp?topic=%2Fcom.ibm.rational.test.ct.doc%2Ftopics%2Ft_cre_java_stub.html

How to mock JNDI(SimpleNamingContextBuilder)

Simple implementation of a JNDI naming context builder.

Mocking the JNDI naming context with "SimpleNamingContextBuilder" class.

Mainly targeted at test environments, where each test case can configure JNDI appropriately, so that new InitialContext() will expose the required objects. Also usable for standalone applications, e.g. for binding a JDBC DataSource to a well-known JNDI location, to be able to use traditional J2EE data access code outside of a J2EE container.

import javax.naming.NamingException;
import javax.sql.DataSource;

import junit.framework.TestCase;

import org.apache.commons.dbcp.BasicDataSource;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.mock.jndi.SimpleNamingContextBuilder;

import com.code.rfs.common.db.JndiDatasource;
import com.code.ejb.search.util.ApplicationConstants;
import com.code.ejb.search.util.PropertiesUtil;

public class JNDIControllerTest extends TestCase {
private JndiDatasource bean1;
private DataSource ds;

/* protected String[] getConfigLocations() {

return new String[] { "ApplicationContextTest.xml" };
}
*/


public void JNDIControllerTest() throws IllegalStateException, NamingException {
//setDependencyCheck(false);

SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
org.apache.commons.dbcp.BasicDataSource dataSource = new BasicDataSource();
dataSource.setDriverClassName("oracle.jdbc.driver.OracleDriver");
dataSource.setUsername("XXXX");
dataSource.setPassword("XXXXXXXX");
dataSource.setUrl("jdbc:oracle:thin:@XYZ.XY.Z.XYZ.net:1111:ABCD");
builder.bind("java:comp/env/jdbc/Keely_DS",dataSource);
builder.bind("url/HLFSAppConfigFolder","file:///c:/ModifWorkspace/keely/fs-ejb/ejbModule");
builder.activate();
// setAutowireMode(AUTOWIRE_BY_TYPE);

}

public void testJNDI() throws Exception {
JNDIControllerTest();
ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContextTest.xml");
bean1 = (JndiDatasource)context.getBean("datacon");
System.out.println(bean1);
PropertiesUtil pUtil = new PropertiesUtil();

}