Have you ever worked on a project that has been successfully deployed for some time only to have the topic of integration creep into the picture late in the game? Lucky for us there is an easy and efficient way to deploy Web Services for integration literally within minutes! If you've been faced with such a situation or are simply curious, please read on!
I recently ran into this scenario and can tell you the documentation will take you longer to produce than the actual implementation! We'll be using Apache's Axis project to implement our Web Service.
Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol") submission to W3C.
For this blog entry, we'll assume you have a pre-existing web application with certain functionality you would like to expose. We'll also assume we only need to get a string representation of the current time on the server (yes, very simple... but how many times do you want to see "Hello World!"?)
Let's get started, download the latest version of Apache's Axis project located here (get version 1.3.) Unzip the file you downloaded and copy the jar files from axis-1_3/lib to your application's WEB-INF/lib directory (don't need to copy any libraries you already have of course.) Put the following entries in your application's web.xml file:
<listener>
<listener-class>
org.apache.axis.transport.http.AxisHTTPSessionListener
</listener-class>
</listener><servlet>
<servlet-name>AxisServlet</servlet-name>
<display-name>
Apache-Axis Servlet
</display-name>
<servlet-class>
org.apache.axis.transport.http.AxisServlet
</servlet-class>
</servlet><servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping><mime-mapping>
<extension>wsdl</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xsd</extension>
<mime-type>text/xml</mime-type>
</mime-mapping>
Create a file named MyWebService.jws in the root dir of your web application (along side index.jsp or index.html) The contents of this file should be:
import java.util.Date;
public class MyWebService {
public String getTime() {
return new Date().toString();
}
}
OK, take a deep breath... your done. Now you obviously want to test this, there is plenty of documentation for Axis to help you write your own unit tests. But in my case, the primary integrating system was written using PHP 5 and planned to use PHP's new soap extension. (Be careful here, PHP 5's soap extension is not compatible with Axis 1.2 only 1.3!)
PHP can integrate with this service VERY easily as well, to test I got the latest for PHP 5 and wrote the following:
<?php
$serviceWsdl = "http://localhost:8888/" .
"test/MyWebService.jws?wsdl";try {
$client = new SoapClient($serviceWsdl);
echo "The time returned by the server was: " .
$client->getTime();
} catch(SoapFault $fault) {
echo "there was an issue : \n" .
" faultcode: $fault->faultcode\n" .
" faultstring: $fault->faultstring\n";
}
?>
That was it... my PHP script printed the time in "toString" format from my server.
Now for the disclaimer, each application will have it's own requirements for integration. Although Axis is a great tool for Web Services, it should not be viewed as the magic hammer for all jobs. There may not even be a need for Web Services written using SOAP as mentioned in a blog entry by Luis Perez.
That being said, I believe Apache's Axis project is a great way to get your application out there with Web Services quickly and efficiently.
What experiences have you had with Axis or Web Services in general?
Comments
I’ve used Apache Axis (and its predecessor Apache SOAP) on a
few projects, and I’ve had nothing but good experiences with it. In my experience, it “just worked” when I needed to integrate with Active X and .NET applications.
One trick I learned, if you don’t want to hand code a bunch of XML Schema, was to first code the java interface, along with all the
supporting beans that you intend to pass back and forth, and run the whole thing through the Java2WSDL tool. This will produce a WSDL file which defines your service, and includes Schema for the beans you use.
Then run that WSDL file through the WSDL2Java tool. This will create “stubs” and “skeletons” for your service, along with deployment descriptors.
Post new comment