Krishna Rajendra Alapati

IT Professional having 4+ years of experience on Java and JEE technologies. Good experience in working with Servlets, JSP, EJB2, XML, XSLT and JEE Design patterns. Good experience in working with open source frameworks like Struts, Spring, Hibernate, ANT, JUnit and JMock.

My Photo
Name:
Location: London, Ilford, United Kingdom

Saturday, December 06, 2008

I am here in Google Map.

Here is my Google Map Example:
Using is Google MAPs API is as simple as shown here. All you need to do is go to http://code.google.com/apis/maps/signup.html and get the KEY for your web site. And then add the below code. I have customized it as per my requirement, you can do customize as per your needs.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true&key=ABQIAAAAjgX3miT717zapeVW6zuHRxT1IMuN1NXMfAxi-ffadLCYQNWCfBQyHqO9wnyZnk3imlkKMth72H2WRg"
type="text/javascript"></script>
<script type="text/javascript">



function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setMapType(GMapType.G_HYBRID_MAP);
var myLocation = new GLatLng(51.55477,0.08027);
map.setCenter(myLocation, 16);
map.addControl(new GSmallMapControl());
var type = new GMenuMapTypeControl();
//var type = new GHierarchicalMapTypeControl();
map.addControl(type);
var myMarker = new GMarker(myLocation);
map.addOverlay(myMarker);
GEvent.addListener(myMarker, "click", function() {
myMarker.openInfoWindowHtml("Hi Friends! Krishna Rajendra is here.");
});
}
}


</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html>

The above code will be shown in your site like this:

Monday, July 21, 2008

Exception handling using Spring AOP

The implementation of the aspect is called as Advice and these Advice will be applied or woven at different pointcuts(i.e. before,after or around the method or class). For Exception handling no need to have these pointcuts defined as these advice should be woven upon an Exception. Exceptions can also be handled using the AOP. When you use spring AOP we have an advice called ThrowsAdvice which is a marker interface and can 'n' number of "afterThrowing( Throwable th)" methods with different kind of custom exceptions as parameter.

Here is an example of ThrowsAdvice. I have a MyThrowsAdvice which can handle NullPointerException, NumberFormatException. In this example i am using the Runtime Exceptions rather than customException, you can use them as well.


package com.janus.examples.aop.advice;

import org.springframework.aop.ThrowsAdvice;

public class MyThrowsAdvice implements ThrowsAdvice {
public void afterThrowing( NullPointerException npe ){
System.out.println("There is some NullPointer Exception is thrown");
}

public void afterThrowing( NumberFormatException nfe ){
System.out.println("There is some NumberFormat Exception is thrown");
}
}



Here is the Service Interface & Implementations class

package com.janus.examples.aop;

public interface HelloService {
String sayHello( String aName, String aNum );
String sayWelcome(String aName,String aNum);
}



package com.janus.examples.aop;
public class HelloServiceImpl implements HelloService {

public String sayHello(String aName,String aNum) {
return "Hello! "+ aName + " It's great that you are running your first AOP program. Argument Passed" + Integer.parseInt(aNum) ;
}

public String sayWelcome(String aName,String aNum) {

return "Welcome!! " + aName +" to Aspect Oriented program. Argument passed "+ aNum.toLowerCase() ;
}

}


Here is the Configuration XML


<beans>
<bean id="helloServiceImpl"
class="com.janus.examples.aop.HelloServiceImpl"/>

<bean id="myThrowsAdvice"
class="com.janus.examples.aop.advice.MyThrowsAdvice"/>


<bean id="helloService"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces">
<value>com.janus.examples.aop.HelloService</value>
</property>
<property name="interceptorNames">
<list>
<value>myThrowsAdvice</value>
</list>
</property>
<property name="target">
<ref bean="helloServiceImpl"/>
</property>
</bean>
</beans>

Here is the client and pretty simple to execute, as it's a main program. Try to send a string as second argument for sayHello it throws an NumberFormatException.
And if you send a null as second argument to sayWelcome it will throw the NullPointerException.

import java.io.FileInputStream;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import com.janus.examples.aop.HelloService;

public class helloclient

{

public static void main(String args[]) throws Exception

{
try

{

BeanFactory factory = new XmlBeanFactory(new FileInputStream(
"D:/SpringTraining/config/Mybeans.xml"));
HelloService bean1 = (HelloService) factory.getBean("helloService");
String s = bean1.sayHello("Krishna Rajendra", "123");
System.out.println(s);

String s1 = bean1.sayWelcome("Krishna Rajendra", null);
System.out.println(s1);

}

catch (Exception e1)

{
System.out.println("" + e1);
}

}

}

Hope This gives you a very good idea on Exception handling using AOP

--
Regards,
Krishna Rajendra A.

Monday, May 29, 2006


My Brother Engagement photos :) Posted by Picasa

Friday, May 26, 2006

SCJP5.0 mock exam links

Hi ,

Here are some SCJP5.0 mock exam links

http://www.examulator.com/phezam/login.php

http://www.javabeat.net/javabeat/scjp5/mocks/index.php

http://www.ejavaguru.com/scjp5freemockexam.php

For 1.4 and lower versions & For SCWCD
http://www.jiris.com

Tuesday, February 14, 2006

Send Arrays from the Java to a Pl/Sql procedure

Hi
Here is some interesting topic i have done in LTD.we can send the data as an array to the back end using the below java code
First of all we need to create the Array type that we are going to send from java in the back end using create type
In the below example i have created a SEARCH_PARAM a type of varchar array(100)

1) For the created type at backend we need to create the ArrayDescriptor as given in the below statement
ArrayDescriptor parameterdescriptor = ArrayDescriptor.createDescriptor( LegalConfiguration.getConfiguration().getString("db.schema")
+ ".SEARCH_PARAM", conn );


2) using the descriptor we can create a ARRAY object from any of the java Collection Object( here i used vector )
ARRAY array_valuekeys = new ARRAY( parameterdescriptor , conn , valueKeys.toArray() );
ARRAY array_valuetypes = new ARRAY( parameterdescriptor , conn , valueTypes.toArray() );
ARRAY array_values = new ARRAY( parameterdescriptor , conn , values.toArray() );


3) Create the Oracle Callable statement for the procedure where we need to send the above constructed arrays
OracleCallableStatement stmt =
(OracleCallableStatement)conn.prepareCall( "begin SP_SEARCHPARAMETERS.SAVESEARCHPARAMETERS( ? , ? ,? ,? ); end;" );


4) Set the parameters for the place holders as given below.user setARRAY method to set the array ay SEARCH_PARAMETER type placeholder
stmt.setLong( 1, id );
stmt.setARRAY( 2, array_valuekeys );
stmt.setARRAY( 3, array_valuetypes );
stmt.setARRAY( 4, array_values );


5) execute the query.This will done the job

Note : Generally this will do for Multiple insert statements to be executed at a same time with in single trip to the backend from java

Wednesday, January 25, 2006

Running the Testcases using ANT script

ANT provides the task to run the JUnit test cases

For using this task we need to have junit.jar file in classpath instead we can copy that jar file into our ANT_HOME\lib folder
below i have given a sample example to run the junit test cases

<junit printsummary="no" haltonfailure="no">
<jvmarg value="-classic"/>
<classpath>
<pathelement path="${app.classpath}" />
<pathelement path="${app.build-test}" />
<pathelement path="${app.build-classes}" />
</classpath>
<formatter type="xml" usefile="true" />
<batchtest>
<fileset dir="${app.build-test}">
<include name="**/test/beans/XML*Test.class" />
<!-- sandbox -->
</fileset>
</batchtest>
</junit>

to understan more about this junit task u can go throug the below link

More help on Junit Ant Task

we can use the junitreport task to generate the report for the junit testcases after running the junit task we can get the xml files
if we use this task after junit we can have a HTML junit task reports which looks like java doc with all the information i.e

tests runned
failures
errors
etc......

Below is a sample code for the junitreport task

<junitreport todir=".">
<fileset dir=".">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${app.build-test-report}/html"/>
</junitreport>

to understan more about this junitreport task u can go throug the below link
More help on junitreport Ant Task

to run the junitreport we need to put the xalan.jar in the classpath otherwise we can copy this in to ANT_HOME\lib
Note:if You are using xalan2.7.0 then we need to copy serializer.jar and xsltc.jar along with the xalan.jar

Wednesday, January 04, 2006

BIRT( Business Intelligence Reporting Tool )

BIRT is an Eclipse-based open source reporting platform for web applications, especially those based on Java and J2EE. BIRT has two main components: a report designer plug-in for Eclipse, and a runtime engine that you can deploy to your application.



An extended introduction to BIRT is available on this page of the BIRT section of the Eclipse web site:
http://www.eclipse.org/birt/intro
This flash movie highlights the steps for building a report using the BIRT Designer in Eclipse:
http://download.eclipse.org/birt/downloads/examples/misc/BIRT/BIRT_demo_Camv3.html


Here is a link for explaining the Usage of Eclipse BIRT Report Libraries and Templates http://www.theserverside.com/articles/article.tss?l=EclipseBRT