Developing Java Web Services with AXIS
Apache Axis has made developing Java Web services a breeze. In this article, I will discuss some guidelines that prove to be very helpful when developing Java Web services using Axis. This article discusses the customization of Axis and the deployment of Web services; it does not discuss the theory of Web services, XML, Java, and so forth.
What Is Apache Axis?
For me, the more suitable definition is: "Axis turns Java code into Web services."
Downloading Axis (Java)
Download the latest version of Axis (Java) from their Web site, http://ws.apache.org/axis. At the time of this writing, 1.1 is the stable release and 1.2 is in the alpha release. These guidelines are based in Axis 1.1. I will refer to this download as the Axis archive from this point onwards.
The following steps discuss how to customize Axis for your Web applications.
Step 1: Customizing web application
You can start with a new or existing standard Java-based Web application, also known as Web Application Archive or WAR. I assume that you know how to build a WAR file and what its contents are.
To enable a Web application to expose Web services, you need to customize the Web application so that it can use Axis engine. You need to perform three steps:
- Customize WEB-INF/web.xml.
- Add the Axis libraries into the WEB-INF/lib folder.
- Create a server-config.wsdd file.
If you are developing a new Web application, the quickest way to customize is to copy the axis folder from the Axis archive's webapps folder and rename it to your own Web application. You can safely delete the samples folder inside the classes folder of your new Web application. You may rename the index.html to your liking, say testaxis.html. It can help you later on to test the axis engine.
If you already have a Web application, you need to copy all the servlet mappings from the axis/WEB-INF/web.xml of the Axis archive into your Web application's web.xml file. You also need to copy all jar files from the axis/WEB-INF/lib folder to your Web application's lib folder. If you want to test your Web application later on, at least copy index.html and happyaxis.jsp from the axis folder to the root of your Web application. You can rename index.html to your liking, say testaxis.html.
Now that you have completed Steps 1 and 2 of customization, the third important step is to create the WEB-INF/server-config.wsdd file. The wsdd stands for Web service description file. It is an XML file used by the Axis engine. It contains definitions of the Web services that Axis deploys from your Web application.
The minimal contents of server-config.wsdd file are as follows:
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <globalConfiguration> <parameter name="adminPassword" value="admin"/> <parameter name="attachments.Directory" value="./attachments"/> <parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl"/> <parameter name="sendXsiTypes" value="true"/> <parameter name="sendMultiRefs" value="true"/> <parameter name="sendXMLDeclaration" value="true"/> <parameter name="axis.sendMinimizedElements" value="true"/> <requestFlow> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="session"/> </handler> <handler type="java:org.apache.axis.handlers.JWSHandler"> <parameter name="scope" value="request"/> <parameter name="extension" value=".jwr"/> </handler> </requestFlow> </globalConfiguration> <handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder"/> <handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper"/> <handler name="Authenticate" type="java:org.apache.axis.handlers.SimpleAuthenticationHandler"/> <service name="AdminService" provider="java:MSG"> <parameter name="allowedMethods" value="AdminService"/> <parameter name="enableRemoteAdmin" value="false"/> <parameter name="className" value="org.apache.axis.utils.Admin"/> <namespace>http://xml.apache.org/axis/wsdd/</namespace> </service> <service name="Version" provider="java:RPC"> <parameter name="allowedMethods" value="getVersion"/> <parameter name="className" value="org.apache.axis.Version"/> </service> <transport name="http"> <requestFlow> <handler type="URLMapper"/> <handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler"/> </requestFlow> </transport> <transport name="local"> <responseFlow> <handler type="LocalResponder"/> </responseFlow> </transport> </deployment>
Step 2: Test the Axis engine
If you have copied the index.html and happyaxis.jsp files and axis folder to your Web application, you can use index.html (or whatever you have renamed it) to test the Axis engine. Deploy your Web application in your favorite application server and access the above-mentioned test file. Click Validate to validate the Axis and View to view the deployed Web services. Everything should go fine by now!
Page 1 of 2