YOU ARE HERE: Home > Tech > Web Services > Article

Axis Samples Step by Step Tutorials -- Echo
By John Henry Xu This article was not rated yet.
 
Printer Version Printer Friendly | Add As Favorite | Link to Article

About the Author

Dr. John Xu is a seasoned system architect. He was chief architect for large distributed portals. He also developed search engine and Java forums. He can be reached by email xixu@yahoo.com.

When you download Axis software, it includes sample services within the download. One may think these samples are easy to understand unless he saw the codes within these samples. For some reasons, some java source files are not usually included with the samples. Only instructions how to use these samples are provided.

To fully understand the process of how these samples are build, it is beneficial to provide step-by-step tutorials for new Axis users, so they can use Axis developing web service applications quickly.

Unfortunately, until the date of this article, no such detailed, step-by-step instructions are available. So I would write this article (and articles) for tutorial purposes.

Now I am going to rebuild sample echo web service.

Step 1. Define service interface

We define the echo service interface as:

List 1. InteropTestPortType.java


package samples.echo;

import java.math.BigDecimal;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Calendar;
import java.util.HashMap;
import javax.xml.rpc.holders.*;
import org.apache.axis.types.*;

// Referenced classes of package samples.echo:
// SOAPStruct, SOAPStructStruct, SOAPArrayStruct

public interface InteropTestPortType
extends Remote
{

public abstract String echoString(String s)
throws RemoteException;

public abstract String[] echoStringArray(String as[])
throws RemoteException;

public abstract int echoInteger(int i)
throws RemoteException;

public abstract int[] echoIntegerArray(int ai[])
throws RemoteException;

public abstract float echoFloat(float f)
throws RemoteException;

public abstract float[] echoFloatArray(float af[])
throws RemoteException;

public abstract SOAPStruct echoStruct(SOAPStruct soapstruct)
throws RemoteException;

public abstract SOAPStruct[] echoStructArray(SOAPStruct asoapstruct[])
throws RemoteException;

public abstract void echoVoid()
throws RemoteException;

public abstract byte[] echoBase64(byte abyte0[])
throws RemoteException;

public abstract Calendar echoDate(Calendar calendar)
throws RemoteException;

public abstract byte[] echoHexBinary(byte abyte0[])
throws RemoteException;

public abstract BigDecimal echoDecimal(BigDecimal bigdecimal)
throws RemoteException;

public abstract boolean echoBoolean(boolean flag)
throws RemoteException;

public abstract void echoStructAsSimpleTypes(SOAPStruct soapstruct, StringHolder stringholder, IntHolder intholder, FloatHolder floatholder)
throws RemoteException;

public abstract SOAPStruct echoSimpleTypesAsStruct(String s, int i, float f)
throws RemoteException;

public abstract String[][] echo2DStringArray(String as[][])
throws RemoteException;

public abstract SOAPStructStruct echoNestedStruct(SOAPStructStruct soapstructstruct)
throws RemoteException;

public abstract SOAPArrayStruct echoNestedArray(SOAPArrayStruct soaparraystruct)
throws RemoteException;

public abstract HashMap echoMap(HashMap hashmap)
throws RemoteException;

public abstract HashMap[] echoMapArray(HashMap ahashmap[])
throws RemoteException;

public abstract Token echoToken(Token token)
throws RemoteException;

public abstract NormalizedString echoNormalizedString(NormalizedString normalizedstring)
throws RemoteException;

public abstract UnsignedLong echoUnsignedLong(UnsignedLong unsignedlong)
throws RemoteException;

public abstract UnsignedInt echoUnsignedInt(UnsignedInt unsignedint)
throws RemoteException;

public abstract UnsignedShort echoUnsignedShort(UnsignedShort unsignedshort)
throws RemoteException;

public abstract UnsignedByte echoUnsignedByte(UnsignedByte unsignedbyte)
throws RemoteException;

public abstract NonNegativeInteger echoNonNegativeInteger(NonNegativeInteger nonnegativeinteger)
throws RemoteException;

public abstract PositiveInteger echoPositiveInteger(PositiveInteger positiveinteger)
throws RemoteException;

public abstract NonPositiveInteger echoNonPositiveInteger(NonPositiveInteger nonpositiveinteger)
throws RemoteException;

public abstract NegativeInteger echoNegativeInteger(NegativeInteger negativeinteger)
throws RemoteException;
}

List 1 is the interface java file and it relates SOAPStructStruct.java, SOAPStruct.java, and SOAPArrayStruct.java files.

So we need copy these files into folder samples/echo, and we copy the compile.xml in previous "Programming Java Web Service" article to C:\Exercise3 folder.

List 2. compile.xml


<project name="HelloWorld" default="compile" basedir=".">
<property name="build.home" value="${basedir}"/>
<property name="src.home" value="${build.home}"/>
<target name="compile">
<javac srcdir="${src.home}" destdir="${build.home}" debug="true" deprecation="true">
<classpath>
<pathelement location="D:/j2sdk1.4.2_07/lib" />
<pathelement location="." />
<fileset dir="D:/axis-1_2/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="D:/j2sdk1.4.2_07/jre/lib/endorsed">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<target name="clean">
<delete>
<fileset dir="${basedir}" includes="**/*.class"/>
</delete>
</target>
</project>

Note: our J2SE is installed at folder D:/j2sdk1.4.2_07. Replace this with the location where you install J2SE.

We type

ant -buildfile compile.xml

And class files are generated for InteropTestPortType.java, SOAPStructStruct.java, SOAPStruct.java, and SOAPArrayStruct.java.

Step 2. Use Java2WSDL

Now we can use Java2WSDL generating WSDL file for this web service from the interface definition InteropTestPortType.class.

In a windows command console, type:

java org.apache.axis.wsdl.Java2WSDL -o myecho.wsdl
-l"http://localhost:8080/axis/services/myecho" -n http://myecho.usanalyst.com
-p"samples.echo" http://myecho.usanalyst.com samples.echo.InteropTestPortType

We can generate WSDL file myecho.wsdl

In above command

1. -o directs WSDL output location.
2. -l Intended for web service URL
3. -n is for target namespace in WSDL
4. -p is package information

Step 3. Generate stub and wrapper codes from WSDL

Using myecho.wsdl, we can generate all server classes, client classes, and wsdd files.

In a command console, we type
java org.apache.axis.wsdl.WSDL2Java -o . -s --NStoPkg http://simplemath.usanalyst.com=com.usanalyst.axis simplemath.wsdl
Above, WSDL2Java needs option parameters such as

1. -o determines classes output directory.
2. -s generates server side codes for server-side bindings
3. -S determines if server-side skeleton code should be generated. Default is false.
4. -N or -NStoPkg is for namespace and package mapping in generated classes.

Step 4. Deploy service code to web application server
Copy two files
echoHeaderStringHandler.java
echoHeaderStructHandler.java
from axis 1.2 distribution to current folder C:\Exercise3\samples\echo folder.
We use ant build file compile.xml to compile java file to class files.
Take a look at original deploy.wsdd file in the sample/echo in Axis distribution, we can see two line codes need add to deploy.wsdd.


<requestFlow>
<handler type="java:samples.echo.echoHeaderStringHandler"/>
<handler type="java:samples.echo.echoHeaderStructHandler"/>
</requestFlow>
<responseFlow>
<handler type="java:samples.echo.echoHeaderStringHandler"/>
<handler type="java:samples.echo.echoHeaderStructHandler"/>
</responseFlow>

We want all classes files in a Jar file so we can put it axis directory of Tomcat server.
Type in a command console

jar cvf myecho.jar samples/echo/*.class org/soapinterop/xsd/*.class

We then copy myecho.jar to %TOMCAT_HOME%/webapps/axis/WEB-INF/lib folder, and we restart tomcat.
We deploy this web service using Axis AdminClient utility by typing following command in a windows command console from C:\Exercise3\samples\echo:
java org.apache.axis.client.AdminClient deploy.wsdd
This should register web service myecho.

Type

http://localhost:8080/axis/servlet/AxisServlet

We can see the screenshot that this service myecho had been deployed successfully.

If you want write a client application to access this service, you may use the methods in my article
"Programming Java Web Services (II)" on http://www.usanalyst.com


Was this article helpful to you?yesno

Related Publications
 
Axis Samples Step by Step Tutorials -- Echo
Axis TCP Monitor For SOAP Messages
Programming Java Web Services (III)
Programming Java Web Services (II)
Programming Java Web Services
Programming Web Services with .Net (Part II)
Programming Web Services with .Net (Part I)

(Registered users can post questions/comments)

 
 TLINKS SEARCH
Advanced Search
Help
 Recommended Links
Red Cross
Responding to hurricane katrina relieve. Donate today. It's a Great Feeling to Help.
http://www.redcross.org
Getusjobs.com
Getusjobs.com is the job site focused on American jobs. See the results that put us on top.
http://www.getusjobs.com
Database Tool
TLinkSoft® tools empowers developers, integrators and DBAs to be more productive.
http://www.cppunit.org/download.jsp
USAnalyst.com
USAnalyst.com provide a community for database analysts, business analysts, developer analysts and managers.
http://www.cppunit.org/article

Powered by Tlinks Systems