Category Archives: Software Technologies

DEFINITION OF A BUSINESS OBJECT.

WHAT IS A BUSINESS OBJECT (BO)?

Having both state & behavior is an important criterion for a class to be considered as business object.

It may represent a person, place, thing or concept from business domain.

It should be re-usable.

Generally business objects are classified into:
Entity BO: Nouns from business.
Process BO: Work flow or business process.
Event BO: Causes / caused by action in system. Represents an event.

BOs provide common terminology & ideas that can be shared across organization by technical & non-technical people alike.

They are very intuitive & should make sense to entire organization.

Have ability to evolve with organizational changes through modification / specialization.

BOs should have well defined interfaces so as to hide low-level implementation.

Should have clear & cohesive set of functionality.

References:
Programming Jakarta Struts
By – Chuck Cavaness
O’reilly

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: www.linkedin.com/in/anupjani
My Blog: www.anupjani.wordpress.com

SIMPLE XML/XSD/XSLT EXAMPLE FOR BEGINNER THAT WORKS!!!

CSS is Style Sheet for HTML
HTML uses predefined tags, and the meaning of each tag is well understood.
The <table> tag in HTML defines a table – and a browser knows how to display it.
Adding styles to HTML elements are simple.
Telling a browser to display an element in a special font or color, is easy with CSS.

XSL is Style Sheet for XML
On the other other hand,
XML does not use predefined tags (we can use any tag-names we like), and therefore the meaning of each tag is not well understood.
A <table> tag could mean an HTML table, a piece of furniture, or something else – and a browser does not know how to display it.

XSL describes how the XML document should be displayed!

You will need:
A good XML editor (even a notepad can do). I used XML Copy Editor 1.2.0.2
A browser. (I used Mozilla Fire Fox 3.0.8).

Create c:\country.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<?xml-stylesheet type=”text/xsl” href=”country.xsl”?>
<country xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xsi:noNamespaceSchemaLocation=”country.xsd”>

<countryName>Australia</countryName>
<capital>Canberra</capital>
<nationalLanguage>English</nationalLanguage>
<population>21000000</population>
<currency>Australian Dollar</currency>
<nationalIdentities>
<nationalAnthem>Advance Australia Fair</nationalAnthem>
<nationalDay>Australia Day (26 January)</nationalDay>
<nationalColour>Green and Gold</nationalColour>
<nationalGemstone>Opal</nationalGemstone>
<nationalFlower>Wattle (Acacia pycnantha)</nationalFlower>
</nationalIdentities>
<publicHolidays>
<newYearDay>1 January</newYearDay>
<australiaDay>26 January</australiaDay>
<anzacDay>25 April</anzacDay>
<christmasDay>25 December</christmasDay>
<boxingDay>26 December</boxingDay>
<laborDay>Variable Date</laborDay>
<easter>Variable Date</easter>
<queenBirthDay>21 April (Variable Date)</queenBirthDay>
</publicHolidays>
<states>
<stateName>NSW – New South Wales</stateName>
<stateName>VIC – Victoria</stateName>
<stateName>QLD – Queensland</stateName>
<stateName>SA – South Australia</stateName>
<stateName>WA – Western Australia</stateName>
<stateName>TAS – Tasmania</stateName>
</states>
<territories>
<territoryName>ACT – Australian Capital Territory</territoryName>
<territoryName>NT – Northern Territory</territoryName>
</territories>
</country>

Create c:\country.xsd
<?xml version=”1.0″ encoding=”UTF-8″?>
<xs:schema xmlns:xs=”http://www.w3.org/2001/XMLSchema”&gt;

<xs:element name=”country”>
<xs:complexType>
<xs:sequence>
<xs:element name=”countryName” type=”xs:string”/>
<xs:element name=”capital” type=”xs:string”/>
<xs:element name=”nationalLanguage” type=”xs:string”/>
<xs:element name=”population” type=”xs:double”/>
<xs:element name=”currency” type=”xs:string”/>
<xs:element name=”nationalIdentities”>
<xs:complexType>
<xs:sequence>
<xs:element name=”nationalAnthem” type=”xs:string”/>
<xs:element name=”nationalDay” type=”xs:string”/>
<xs:element name=”nationalColour” type=”xs:string”/>
<xs:element name=”nationalGemstone” type=”xs:string”/>
<xs:element name=”nationalFlower” type=”xs:string”/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”publicHolidays”>
<xs:complexType>
<xs:sequence>
<xs:element name=”newYearDay” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”australiaDay” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”anzacDay” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”christmasDay” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”boxingDay” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”laborDay” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”easter” maxOccurs=”1″ type=”xs:string”/>
<xs:element name=”queenBirthDay” maxOccurs=”1″ type=”xs:string”/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”states”>
<xs:complexType>
<xs:sequence>
<xs:element name=”stateName” type=”xs:string” minOccurs=”1″ maxOccurs=”unbounded”/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=”territories”>
<xs:complexType>
<xs:sequence>
<xs:element name=”territoryName” maxOccurs=”unbounded”/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Create c:\country.xsl
<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221; version=”1.0″>
<xsl:template match=”/”>
<html>
<body>
<xsl:for-each select=”country”>
<xsl:value-of select=”countryName”/><br/>
<xsl:value-of select=”capital”/><br/>
<xsl:value-of select=”nationalLanguage”/><br/>
<xsl:value-of select=”population”/><br/>
<xsl:value-of select=”currency”/><br/>
<xsl:for-each select=”nationalIdentities”>
<xsl:value-of select=”nationalAnthem”/><br/>
<xsl:value-of select=”nationalDay”/><br/>
<xsl:value-of select=”nationalColour”/><br/>
<xsl:value-of select=”nationalGemstone”/><br/>
<xsl:value-of select=”nationalFlower”/><br/>
</xsl:for-each>
<xsl:for-each select=”publicHolidays”>
<xsl:value-of select=”newYearDay”/><br/>
<xsl:value-of select=”australiaDay”/><br/>
<xsl:value-of select=”anzacDay”/><br/>
<xsl:value-of select=”christmasDay”/><br/>
<xsl:value-of select=”boxingDay”/><br/>
<xsl:value-of select=”laborDay”/><br/>
<xsl:value-of select=”easter”/><br/>
<xsl:value-of select=”queenBirthDay”/><br/>
</xsl:for-each>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Execute the program
Just open the country.xml in your browser.

Moreover
Above is a very simple output.
You can further beautify your output by modifying your country.xsl
Just create another c:\beautifiedcountry.xsl
And replace the name from “country.xsl” to “beautifiedcountry.xsl” in your country.xml
And open the XML to see the difference.

Copy this c:\beautifiedcountry.xsl
<?xml version=”1.0″ encoding=”UTF-8″?>
<xsl:stylesheet xmlns:xsl=”http://www.w3.org/1999/XSL/Transform&#8221; version=”1.0″>
<xsl:template match=”/”>
<html>
<body>
<table border=”2″ bgcolor=”lightgray”>
<tr><u><b>GENERAL INFORMATION</b></u></tr>
<tr>
<xsl:for-each select=”country”>
<tr>
<table border=”1″ bgcolor=”lightblue”>
<tr><td>Country Name</td><td><xsl:value-of select=”countryName”/></td></tr>
<tr><td>Capital</td><td><xsl:value-of select=”capital”/></td></tr>
<tr><td>National Language</td><td><xsl:value-of select=”nationalLanguage”/></td></tr>
<tr><td>Population</td><td><xsl:value-of select=”population”/></td></tr>
<tr><td>Currency</td><td><xsl:value-of select=”currency”/></td></tr>
</table>
</tr>
<tr><br></br></tr>
<tr><u><b>NATIONAL IDENTITIES</b></u></tr>
<tr>
<xsl:for-each select=”nationalIdentities”>
<table border=”1″ bgcolor=”lightyellow”>
<tr>
<td>National Anthem</td><td><xsl:value-of select=”nationalAnthem”/></td>
</tr>
<tr>
<td>National Day</td><td><xsl:value-of select=”nationalDay”/></td>
</tr>
<tr>
<td>National Colour</td><td><xsl:value-of select=”nationalColour”/></td>
</tr>
<tr>
<td>National Gem Stone</td><td><xsl:value-of select=”nationalGemstone”/></td>
</tr>
<tr>
<td>National Flower</td><td><xsl:value-of select=”nationalFlower”/></td>
</tr>
</table>
</xsl:for-each>
</tr>
<tr><br></br></tr>
<tr><u><b>PUBLIC HOLIDAYS</b></u></tr>
<tr>
<xsl:for-each select=”publicHolidays”>
<table border=”1″ bgcolor=”LightGreen”>
<tr>
<td>New Year’s Day</td><td><xsl:value-of select=”newYearDay”/></td>
</tr>
<tr>
<td>Australia Day</td><td><xsl:value-of select=”australiaDay”/></td>
</tr>
<tr>
<td>ANZAC Day</td><td><xsl:value-of select=”anzacDay”/></td>
</tr>
<tr>
<td>Christmas Day</td><td><xsl:value-of select=”christmasDay”/></td>
</tr>
<tr>
<td>Boxing Day</td><td><xsl:value-of select=”boxingDay”/></td>
</tr>
<tr>
<td>Labor Day</td><td><xsl:value-of select=”laborDay”/></td>
</tr>
<tr>
<td>Easter</td><td><xsl:value-of select=”easter”/></td>
</tr>
<tr>
<td>Queen’s Birthday</td><td><xsl:value-of select=”queenBirthDay”/></td>
</tr>
</table>
</xsl:for-each>
</tr>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Recommended Reference:
http://www.w3schools.com/xsl/xsl_languages.asp

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com

SIMPLE JUNIT EXAMPLE FOR BEGINNER THAT WORKS!!!

This Hello World program demonstrates basic features of JUnit.

All you need is:
1. Eclipse
2. JDK1.5
3. junit.jar (Download from http://www.junit.org)

In this program, usage of JUnit is demonstrated in order to test 2 components, namely:
1. Dice.java
2. DiceFactory.java

Test requirement for every new Dice created:
1. Playing a dice every time should get any number between (including) 1 to 6
2. A dice has 6 sides & no two sides should hold the same number.
3. Dice should be unbiased. In an unbiased dice, the sum of 2 opposite side numbers is always 7.
e.g. If back side is 6 then front side has to be 1.

Create Java project in eclipse.
NOTE: Make sure junit.jar is set in your classpath.

Folder structure
C\MyWorkspace\HelloJUnit:
│ .classpath
│ .project

├───bin
│ │ DiceTest.class
│ │
│ └───com
│ ├───mymodel
│ │ Dice.class
│ │
│ └───myservice
│ DiceFactory.class

├───src
│ └───com
│ ├───mymodel
│ │ Dice.java
│ │
│ └───myservice
│ DiceFactory.java

└───test
DiceTest.java

Create Dice.java
package com.mymodel;

import java.util.Random;

/**
* @author Anup
* A dice that has 6 sides, namely:<br>
* top, bottom, left, right, front & back.<br>
*/
public class Dice {

//Dice has six sides, each one carrying a number.
private int topSide = 0;
private int bottomSide = 0;
private int leftSide = 0;
private int rightSide = 0;
private int frontSide = 0;
private int backSide = 0;

/**
* Parameterised constructor.
* @param topSide
* @param bottomSide
* @param leftSide
* @param rightSide
* @param frontSide
* @param backSide
*/
public Dice(int topSide,
int bottomSide,
int leftSide,
int rightSide,
int frontSide,
int backSide) {
this.topSide = topSide;
this.bottomSide = bottomSide;
this.leftSide = leftSide;
this.rightSide = rightSide;
this.frontSide = frontSide;
this.backSide = backSide;
}

/**
* This method plays the dice to get a number.
* @return
*/
public int throwDice() {
return getRandomNumber();
}

public int getTopSide() {
return topSide;
}

public int getBottomSide() {
return bottomSide;
}

public int getLeftSide() {
return leftSide;
}

public int getRightSide() {
return rightSide;
}

public int getFrontSide() {
return frontSide;
}

public int getBackSide() {
return backSide;
}

/**
* Private method to get a random number.
* @return
*/
private int getRandomNumber() {
Random r = new Random();
int n = 0;
while (true) {
n = Math.abs(r.nextInt()) % 7;
if(n <7 && n >0)
return n;
}
}

}
Create DiceFactory.java

package com.myservice;

import com.mymodel.Dice;

/**
* @author Anup
* A factory class that deals with Dice object creation.
*/
public class DiceFactory {

/**
* Creates a dice object.
* @param top
* @param bottom
* @param left
* @param right
* @param front
* @param back
* @return
*/
public Dice getDice(
int top,
int bottom,
int left,
int right,
int front,
int back) {
return new Dice(top, bottom, left, right, front, back);
}

}
Create DiceTest.java
import java.util.HashSet;
import java.util.Set;

import junit.framework.TestCase;

import com.mymodel.Dice;
import com.myservice.DiceFactory;

/**
* @author Anup
* A test case to unit test the Dice Program.
*/
public class DiceTest extends TestCase {

int top = 1;
int bottom = 6;
int left = 4;
int right = 3;
int front = 2;
int back = 5;
DiceFactory diceFactory = null;
Dice dice = null;

//Constructor
public DiceTest(String testMethodName) {
super(testMethodName);
}

//Initialise
public void setUp() {
diceFactory = new DiceFactory();
}

//Dice should not be null.
public void testGetDice() {
dice = diceFactory.getDice(top, bottom, left, right, front, back);
assertNotNull(dice);
System.out.println(“Dice created.”);
this.dice = dice;
}

//When dice thrown, should get any number between (including) 1 to 6
public void testThrowDice() {
dice = diceFactory.getDice(top, bottom, left, right, front, back);
int n = dice.throwDice();
assertTrue(n<7 && n>0);
System.out.println(“Dice number is between (including)1 & 6 = ” + n);
}

//Making sure NO two sides are same.
public void testUniquenessOfSides() {
dice = diceFactory.getDice(top, bottom, left, right, front, back);
Set set = new HashSet();//Set holds unique values.
String args[] = {
dice.getTopSide()+””,
dice.getBottomSide()+””,
dice.getLeftSide()+””,
dice.getRightSide()+””,
dice.getFrontSide()+””,
dice.getBackSide()+””
};
for(String i : args) {
assertTrue(set.add(i));
}
System.out.println(“No duplicates detected!”);
}

//Dice should be unbiased.
//In an unbiased dice, the sum of 2 opposite side numbers is always 7.
//e.g. If back side is 6 then front side has to be 1.
public void testUnbiased() {
dice = diceFactory.getDice(top, bottom, left, right, front, back);
assertEquals(dice.getFrontSide() + dice.getBackSide(), 7);
assertEquals(dice.getLeftSide() + dice.getRightSide(), 7);
assertEquals(dice.getTopSide() + dice.getBottomSide(), 7);
System.out.println(“Dice is unbiased.”);
}

//De-initialise
public void tearDown() {
diceFactory = null;
dice = null;
System.out.println(“Tear down <<<<“);
}

}

Execute the program
Wen you are done building project, right click on project.
Project –> Run As –> JUnitTest
There is no main method here.
That’s the whole idea. We have JUnit test methods instead.

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com

SIMPLE SPRING IOC EXAMPLE FOR BEGINNER THAT WORKS!!!

This Hello World program demonstrates basic features of Spring IoC.
This program shows:
1. How to load configurations from a XML resource file that is residing in the file system.
2. How to load configurations from many XML resource files that are residing in the file system.
3. How to load configurations from a XML resource file sitting in the class path.

If you already know how to create a Java Project in Eclipse then here’s the project structure.
Make sure following JAR files fall into your Build Path.

Project Structure
C:\workspace\HelloSpringIOC
|   .classpath
|   .project
|
+—bin
|       HelloSpringIoC.class
|       MyBeansInClassPathHere.xml
|       OtherPojo.class
|       SpecialPojo.class
|
+—lib
|       commons-logging-api-1.1.jar
|       spring-beans-2.0-m1.jar
|       spring-context-2.0-m1.jar
|       spring-core-2.0-m1.jar
|
\—src
HelloSpringIoC.java
MyBeansInClassPathHere.xml
OtherPojo.java
SpecialPojo.java

Make sure following two files exist in your C:\> drive.
1. C:\config\MyOtherBeansHere.xml
2. C:\config\MySpecialBeansHere.xml

Notice MyBeansInClassPathHere.xml highlighted in yellow.
It’s into the class path being in “src” folder.
You will need ClassPathXmlApplicationContext for loading this configuration file.
See method: public void usingClassPathXmlApplicationContext(String myBeanResource)

Run HelloSpringIoc as Java Application once you have created following files.

SpecialPojo.java
public class SpecialPojo {

private String name;

public SpecialPojo() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

OtherPojo.java
public class OtherPojo {

private String name;

public OtherPojo() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

C:\config\MySpecialBeansHere.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD// BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;
<beans>
<bean id=”specialPojo” class=”SpecialPojo”/>
</beans>

C:\config\MyOtherBeansHere.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD// BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;
<beans>
<bean id=”otherPojo” class=”OtherPojo”/>
</beans>

MyBeansInClassPathHere.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE beans PUBLIC “-//SPRING//DTD// BEAN//EN” “http://www.springframework.org/dtd/spring-beans.dtd”&gt;
<beans>
<bean id=”otherPojo” class=”OtherPojo”/>
</beans>

HelloSpringIoc.java
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
* @author Anup Jani
* This Hello World program demonstrates basic features of Spring IoC.<br>
* This program shows:<br>
* 1. How to load configurations from a XML resource file that is residing in the file system.<br>
* 2. How to load configurations from many XML resource files that are residing in the file system.<br>
* 3. How to load configurations from a XML resource file sitting in the class path.<br>
*/
public class HelloSpringIoC {

/**
* Application Context pointing to the resource file in the file system location.
* @param myBeanResource
*/
public void usingFileSystemXmlApplicationContext(String myBeanResource) {
//Create an application context.
ApplicationContext ctx = new FileSystemXmlApplicationContext(myBeanResource);
SpecialPojo pojo = (SpecialPojo)ctx.getBean(“specialPojo”);

//Start using your bean.
pojo.setName(“This is my special bean, obtained via FileSystemXmlApplicationContext.”);
System.out.println(pojo.getName());
}

/**
* Application Context pointing to the multiple resource files in the file system location.
* @param myBeanResources
*/
public void usingFileSystemXmlApplicationContext(String[] myBeanResources) {
//Create an application context.
ApplicationContext ctx = new FileSystemXmlApplicationContext(myBeanResources);

//Get beans from multiple configurations.
String[] beanNames = ctx.getBeanDefinitionNames();
SpecialPojo specialPojo = (SpecialPojo)ctx.getBean(beanNames[0]);
OtherPojo otherPojo = (OtherPojo)ctx.getBean(beanNames[1]);

//Start using your beans.
specialPojo.setName(“Special bean obtained  from one configuration.”);
otherPojo.setName(“Other bean obtained from other configuration.”);
System.out.println(specialPojo.getName() + “\n” + otherPojo.getName());
}

/**
* Application Context pointing to the resource file in the class path.
* @param myBeanResource
*/
public void usingClassPathXmlApplicationContext(String myBeanResource) {
//Create an application context.
ApplicationContext ctx = new ClassPathXmlApplicationContext(myBeanResource);

//Get bean from application context.
OtherPojo pojo = (OtherPojo)ctx.getBean(“otherPojo”);

//Start using your bean.
pojo.setName(“This is my bean that was configured in class path, \n\t ” +
“obtained via ClassPathXmlApplicationContext.”);
System.out.println(pojo.getName());
}

/**
* Main method to test each method.
* @param args
*/
public static void main(String[] args) {
//Single file in file system.
String file = “C:\\config\\MySpecialBeansHere.xml”;

//Multiple files in file system.
String files[] = new String[]{“C:\\config\\MySpecialBeansHere.xml”, “C:\\config\\MyOtherBeansHere.xml”};

//Single file in class path.
String fileInClassPath = “MyBeansInClassPathHere.xml”;

HelloSpringIoC hello = new HelloSpringIoC();

hello.usingFileSystemXmlApplicationContext(file);
hello.usingFileSystemXmlApplicationContext(files);
hello.usingClassPathXmlApplicationContext(fileInClassPath);
}

}

Recommended source:
Java Development with the Spring Framework
– Rod Johnson, Juergen Hoeller, Alef Arendsen, Thomas Risberg, Colin Sampaleanu
Professional Seires – Wrox publication.

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com

SIMPLE JAVA WEB-SERVICE ON TOMCAT5.5 EXAMPLE FOR BEGINNER THAT WORKS!!!

This article takes reader step by step to build her/his own simplest program of Java Web Service.
If all steps are followed properly, then the  program should work.

SETUP YOUR ENVIRONMENT FIRST.

Assuming that you have:

C:\axis-1_4
C:\Program Files\Apache Software Foundation\Tomcat 5.5
C:\jdk5\lib;

Make sure your AXIS has following JAR files:
C:\axis-1_4\webapps\axis\WEB-INF\lib>dir /b
activation.jar
axis-ant.jar
axis.jar
commons-discovery-0.2.jar
commons-logging-1.0.4.jar
jaxrpc.jar
log4j-1.2.8.jar
mail.jar
saaj.jar
wsdl4j-1.5.1.jar

If above highlighted files are missing, then download them separately.
And copy them in C:\axis-1_4\webapps\axis\WEB-INF\lib
NOTE: mail.jar or mailapi.jar should be fine.

set TOMCAT_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.5

AXIS enable your Tomcat:
Copy “C:\axis-1_4\webapps\axis” folder in %TOMCAT_HOME%\webapps
AXIS itself is an Apache application.
By copying this folder you deploy the AXIS application on Tomcat.
Doing this makes your Tomcat behave like a “Java Web Service” Server.

Verify AXIS Server on Tomcat
Start your Tomcat Server & hit following URL on browser.
http://localhost:8080/axis

You should get Hello! Welcome to Apache-Axis web page.
Click on List to see the list of web services deployed currently.

Set classpath
You need to bring those JAR files in your classpath too.
If not, then will give compilation errors on your command prompt when you try to compile/generate code.
Hence copy all these JAR files to C:\axis-1_4\lib
And set the classpath
C:\>set classpath
classpath=.;c:\jdk5\lib;C:\axis-1_4\lib\axis.jar;C:\axis-1_4\lib\axis-ant.jar;C:
\axis-1_4\lib\commons-discovery-0.2.jar;c:\axis-1_4\lib

YOUR ENVIRONMENT IS NOW SET.
BRACE UP TO WRITE, DEPLOY & EXECUTE THE WEB-SERVICE.

Write your Java Interface
package myapp;

public interface Hello {

public String sayHello(String name);

}

Write your Java Interface Implementation
package myapp;

public class HelloImpl {

public String sayHello(String name) {
return “Hello ” + name;
}

}

So that:
C:\practice\myapp\Hello.java
C:\practice\myapp\HelloImpl.java

Compile interfaces & implementation code before generating WSDL
C:\practice>javac myapp\Hello.java -d .
C:\practice>javac myapp\HelloImpl.java -d .

Generate WSDL
C:\practice>java org.apache.axis.wsdl.Java2WSDL -o hello.wsdl -l”http://localhost:8080/axis/services/hello&#8221; -n urn:hello -p”hello” urn:hello myapp.Hello
Notice that hello.wsdl got generated.

Generate glue code
C:\practice>java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p myapp.ws hello.wsdl
So that:
C:\practice\myapp\ws>dir /b
deploy.wsdd
Hello.java
HelloService.java
HelloServiceLocator.java
HelloSoapBindingImpl.java
HelloSoapBindingStub.java
undeploy.wsdd

Time to modify the glue code a bit
Notice “HelloSoapBindingImpl.java“.
It is the implementation that is automatically generated.
But you already have written your own implementation which is: HelloImpl.java
So, call your Impl method in generated Impl method,
Don’t forget to copy your HelloImpl.java in location C:\practice\myapp\ws\
And change its package form myapp to myapp.ws because now it’s been moved there.

/**
* HelloSoapBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/

package myapp.ws;

public class HelloSoapBindingImpl implements myapp.ws.Hello{
public java.lang.String sayHello(java.lang.String in0) throws java.rmi.RemoteException {
System.out.println(“remote service invoked!”);
HelloImpl h = new HelloImpl();
return h.sayHello(in0);
}

}

Compile the glue code
C:\practice>javac myapp\ws\*.java
May show some warnings but that should be fine.

Package into JAR
C:\practice>jar cvf hello.jar myapp/*.class myapp/ws/*.class
Move hello.jar
C:\practice>move hello.jar “c:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib
Start Tomcat server before deploying

Deploy the service
C:\practice>java org.apache.axis.client.AdminClient myapp\ws\deploy.wsdd

Verify deployed service
Re-Start your Tomcat Server & hit following URL on browser.
http://localhost:8080/axis

You should get Hello! Welcome to Apache-Axis web page.
Click on List to see the list of web services deployed currently containing your hello service.

Write the Client
package myapp.client;

public class HelloServiceClient {
public static void main(String[] args){
try {
//Get the service.
myapp.ws.HelloService service = new myapp.ws.HelloServiceLocator();

// Get the stub.
myapp.ws.Hello hello = service.gethello();

// Make the call.
System.out.println(hello.sayHello(“some name”));
}
catch(Exception e) {
e.printStackTrace();
}
}
}

Compile the client
javac myapp\*.java -d .

Execute the client
C:\practice>java myapp.client.HelloServiceClient

Output should be:
Hello some name

Recommended references:
http://www.onjava.com/lpt/a/1578
http://www.ociweb.com/mark/JavaUserGroup/Axis.pdf
http://jaitechwriteups.blogspot.com/2006/12/simple-webservice-on-jboss-using-axis.html

Anup Jani
(Bsc, MCP, GNIIT, SCJP, SCWCD, IBM OOAD/UML JCert.)
My profile: http://www.linkedin.com/in/anupjani
My Blog: http://www.anupjani.wordpress.com