Thursday, 23 August 2007

Axis1 simple example

Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol")
submission to W3C.

SOAP (Simple Object Access Protocol)
WSDL (Web Service Description Langauge)
WSDD (Web Service Deployment Descriptor)

1. Apache Tomcat 4.1 Over , Full Version
Check http://localhost:8080
If you need any library , please copy it to c:\tomcat\common\lib\
* set up enviroment value
set CATALINA_HOME=c:\tomcat

2. JDK : over JDK 1.4

* Set up classpath
set CLASSPATH=.;c:\jdk15\lib\tools.jar;c:\tomcat\common\lib\servlet-api.jar;
Add libraries (ex JDBC ...)

set JAVA_HOME=c:\jdk15
set PATH=c:\jdk15\bin;

3. ANT (option) : ant (down) ant 1.6.2
* set up classpath
set ANT_HOME=c:\ant
set PATH=c:\ant\bin;
copy C:\tomcat\server\lib\catalina-ant.jar files into c:\ant\lib\
if you need any library such as junit or xml libraries, please copy it into c:\ant\lib\

4. AXIS (Version 1.1) : ,

set AXIS_HOME=c:\axis
set AXISCLASSPATH=%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery.jar;
etc :
you can download xml-apis.jar and xercesImpl.jar from

5. connect between axis and tomcat
copy axis directory from c:\axis\webapps\axis\ to c:\tomcat\webapps\axis

6. Test

Start Tomcat
* Test libraries
From this page, you can see missing jar files. Please download from web and copy it into

Check http://localhost:8080/axis/happyaxis.jsp page again

7. SOAP test


- xmlns:xsd=""
Apache Axis version: 1.1 Built on Jun 13, 2003 (09:19:43 EDT)

8. AdminClient test

Move C:\axis\samples\stock
Open dos command and type below line
java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

comfirm deploy, if you have any error , it is from classpath problem. so please check classpath again.

check deploy is ok or not
you will see below page
urn:xmltoday-delayed-quotes (wsdl)

9. Client test
Open dos command
Move C:\axis\
type below line
java samples.stock.GetQuote -lhttp://localhost:8080/axis/servlet/AxisServlet -uuser1 -wpass1 XXX
java -cp %AXISCLASSPATH% samples.stock.GetQuote -lhttp://localhost:8080/axis/servlet/AxisServlet -uuser1 -wpass1 XXX
Go to C:\axis\samples\stock
Open and delete "package samples.stock " line

goto C:\axis\
java GetQuote -lhttp://localhost:8080/axis/servlet/AxisServlet -uuser1 -wpass1 XXX

You will see XXX: 5525

10. order for programm

a. implement "Interface" and Class for Server side
b. Create WSDL from implemented class
c. create deploy.wsdd file from WSDL file
d. deploy webservice from deploy.wsdd file and update server-config.wsdd
e. create client-side class

11. program flow

12. example

java Interface, Implement
go to c:\test\
create 2 files

//begin -
package webservice.hello;
public interface HelloIF extends java.rmi.Remote {
public String hello(java.lang.String name) throws java.rmi.RemoteException;
//end -

//begin -
package webservice.hello;
public class HelloImpl implements HelloIF {
public HelloImpl() {
public String hello(String name) {
return "hi " + name;
//end -


javac -d .

If there is error.
c:\test>javac -d .
c:\test>javac -d .

HelloImpl.class and HelloIF.class under c:\test\webservice/hello
(If you can not compile , please use eclipse. because we need only 2 class files with folder)

copy (webservice)folder into C:\Tomcat\webapps\axis\WEB-INF\classes

* Create WSDL file

c:\test>java org.apache.axis.wsdl.Java2WSDL -o c:\test\webservice\hello\Hello.wsdl
-l http://localhost:8080/axis/services/Hello -n http://hello.webservice -pwebservice.hello
http://hello.webservice webservice.hello.HelloIF

Java2WSDL parameter (

-o file path and wsdl locationi to create
-l URL for connecting from URL Client
-n Namespace : WSDL target NameSpace
-p package Name space and mapping with namespace Target inerface name

[check Hello.wsdl file from c:\test\webservice\hello]


* Create deploy.wsdd file and create Client-side java class

c:\test>java org.apache.axis.wsdl.WSDL2Java -o c:\test\webservice\hello\
-d Application -s c:\test\webservice\hello\Hello.wsdl

webservice/hello directory is created under c:\test\webservice\hello
deploy.wsdd - the file to deploy in web server
undeploy.wsdd - the file to undeploy in web server

-o directory path for wsdd file and class files
-d install area of scope - Application, Request , Session
-s create wsdd file
Target wsdl file path

[deploy.wsdd - update]

wsdd file is created from wsdl file so it does not set up what is real implement class.
So you should update that part
from webservice.hello.HelloSoapBindingImpl to webservice.hello.HelloImpl

parameter name="className" value="webservice.hello.HelloImpl"/>
parameter name="allowedMethods" value="hello"/>
parameter name="scope" value="Application"/>

*deploy service
Go to C:\test\webservice\hello\webservice\hello
java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

[checking deply]
'Hello' Serviec (display)

* undeploy service

java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService undeploy.wsdd

[Checking undeploy service]
'Hello' service (disappear)

*deploy service
Go to C:\test\webservice\hello\webservice\hello
java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

[checking deply]
'Hello' Serviec (display)

* confirm WSDL from web

14. implement client

create client side to access

crate below file and copy to c:\tomcat\webapps\axis\


%@ page contentType="text/html; charset=utf-8" language="java"
org.apache.axis.client.Service" %>
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
title>test web service : Hello World!/title>
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL("http://localhost:8080/axis/services/Hello?wsdl"));
call.setOperationName(new QName("", "hello"));
String returnValue = (String)call.invoke(new Object[]{"! your name"});


hi ! your name - (if you can see this message, you are success until here.)

14. second example

There are faster way
after you crate java file and change jws files(change file extenstion from java to jws)

please refer to c:\tomcat\webapps\axis\WEB-INF\web.xml

Please create below file under c:\tomcat\webapps\axis\
[ HelloWorldService.jws]

public class HelloWorldService
public String HelloWorld(String data)
return "Hello World! You sent the string '" + data + "'.";

* Access to below address
you will see
There is a Web Service here
Click to see the WSDL
It address there are html page install,
try call HelloWorld method


you received the XML as a result for calling method

* now implement client with java

create below java file in anywhere

import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class HelloWorldClient
public static void main(String[] args) throws ServiceException, MalformedURLException, RemoteException
Service service = new Service();
Call call = (Call)service.createCall();
call.setTargetEndpointAddress(new URL("http://debianbox:8080/axis/HelloWorldService.jws"));
call.setOperationName(new QName("", "HelloWorld"));
String returnValue = (String)call.invoke(new Object[]{"My name is rrr."});

compile and run
You will see
Hello World ! you send the string My name is rrr.
from dos command

1 comment:

Anonymous said...

Genial brief and this enter helped me alot in my college assignement. Say thank you you for your information.