Book Image

Apache Axis2 Web Services, 2nd Edition

By : Deepal Jayasinghe, Afkham Azeez
Book Image

Apache Axis2 Web Services, 2nd Edition

By: Deepal Jayasinghe, Afkham Azeez

Overview of this book

<p>Web services are gaining popularity and have become one of the major techniques for application integration. Due to the flexibility and advantages of using web services, you want to enable Web service support to your applications. This book is your gateway to learning all you need to know about the Apache Axis2 web service framework and its hands on implementation. <br /><br />Apache Axis2 Web Services, 2nd Edition is your comprehensive guide to implementing this incredibly powerful framework in practice. It gives you precisely what you need to know to develop a detailed practical understanding of this popular, modular and reliable web service framework.<br /><br />This book starts with a short and relevant introduction about the Axis2 1.5 framework and then plunges you straight into its architectural model.</p> <p>Learn to use and develop your own modules. Write a services.xml file so efficiently that you'll be creating more complex applications (rather than just POJOs) in no time.</p> <p>Learn how straightforward it really is to turn a Java class into a web service in Axis2. Experiment with different types of sessions in Axis2. Learn different patterns of Enterprise deployment. Ensure reliability in your web service - a major concern in most enterprise applications - with minimum impact on performance.<br /><br />This book will journey you through all this and more, giving you exactly what you need to learn Axis2 1.5 in the easiest way possible and create secure, reliable, and easy-to-use web services efficiently and systematically.</p>
Table of Contents (22 chapters)
Apache Axis2 Web Services
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
15
Building a Secure Reliable Web Service
Index

Downloading and installing Apache Axis2


Apache Axis2 version 1.0 was released in 2006 and after that there were a number of releases. The current stable release is 1.5. The previous version of this book, "Quickstart Apache Axis", Deepal Jayasinghe, Packt Publishing, was based on version 1.2 of Axis2. This one is based on version 1.5. From 1.2 to 1.5, Axis2 introduced a set of new features as well as API changes. One of the key changes was moving from JDK 1.4 to 1.5. The current version of Axis2 only supports JDK 1.5 and higher. Nevertheless, most of the commonly used APIs still remain the same.

There are three types of software: free software, open source software, and commercial software. The main idea of free software is that you can download the software for free; however, you do not get access to the source code or the development work. On the other hand, open source software is designed and developed by an open community; anyone can participate in the discussions and contribute to the project, and finally, once the product is released, the user can have access to both the product and the source code. The user can modify the source code, fix issues, redistribute, and so on. As Axis2 is also an open source project, you can download Axis2 and get access to both binary and source codes. However, in the proprietary software, the license agreement is very restricted, and usually the user does not get to see the source code; the user only gets the binary.

You can download the latest version (or 1.5) from the Axis2 official website or any mirror site. The download link is shown here:

http://ws.apache.org/axis2/download/1_5_1/download.cgi

Once you go the download page, you can find four different distributions (artifacts):

  • Binary distribution

  • WAR distribution

  • Source distribution

  • Document distribution

In addition, you can also download IDE plugins from Axis2's official website (IDE tools include both Eclipse and IntelliJ IDEA).

Binary distribution

Axis2 binary distribution consists of all the relevant third-party libraries, a set of samples, and Axis2 runtime. Installing binary distribution is just a matter of extracting ZIP archive files into a location where you want. Once you download and extract the binary distribution, you will be able to see a set of subdirectories inside it (bin, lib, samples, repository, webapp, and conf). A typical structure of an extracted binary distribution is shown below:

Axis2 binary distribution is a complete package where you can deploy services and expose them using SimpleAxisServer. SimpleAxisServer is a fully functional server that can be used as the backend server to expose the web service. It supports all the features that the servlet version supports, including session management, thread management, auto WSDL generation, and others.

We can also use Axis2 binary distribution to invoke remote services. For this you need to add Axis2 and other related libraries into the class path and use Axis2 Client APIs to invoke the service. One of the commonly used approaches is to add those libraries into your IDE and client applications developed from that.

Binary distribution can also be used to generate Stubs and Skeleton from a given WSDL or to generate WSDL from a given Java class. In the later chapters, we will discuss how to use these tools to generate code.

Starting Axis2 as a standalone server is just a matter of running either .bat or a script file in the bin directory. Once we run the axis2server.sh (or .bat) and type http://localhost:8080/axis2 , we can see the list of available services in the system, and these indicate the server is up and running.

WAR distribution

One of the easiest ways to expose a web service is to integrate it with an existing application or enable the web service through an available application server. In such scenarios, it is very useful to have a separate WAR (Web Archive) distribution, which helps the users to download, deploy, and access very easily. Assume that you have already downloaded Axis2 WAR distribution, and further assume you have Apache Tomcat running. To deploy Axis2, you need to copy the axis2.war file into the webapps directory. Next, if Tomcat is running on port 8080, you can access Axis2 by going to the following URL:

http://localhost:8080/axis2

If everything has gone well, you will get the following page:

Next, we can try to invoke the version service (a default service comes with Axis2 distribution) using the following URL:

http://localhost:8080/axis2/services/Version/getVersion

After this, it should display the version string of Axis2 you have downloaded. Once you see the version number, we have successfully deployed Axis2 into Tomcat. Next, you can upload or deploy a new service into Axis2.

Note

In Axis2, to add a new web service, we need to add corresponding resources (service archive file) into the extracted location of the WAR file. However, most of the application servers do not unpack the WAR file. In those cases, you need to follow additional steps to configure your WAR file. For that, you need to extract the WAR file and do the required modifications to the web.xml file and recreate the WAR file and deploy. If your application server unpacks the WAR file, we can drop our new web service into the unpack location. This method is only used for quick testing—real development and production use. It is recommended to use Ant (or Maven) to produce WAR files for specific deployments, that is, not manually adjusting the contents of WAR files. We will learn about Axis2 Web Service in detail later in this book. There, we will be able to understand the meaning of adding a new web service.

Installing WAR distribution consists of the following few steps:

  1. Install application server: If you do not have any application server in your machine, then you need to download and install the application server. Among the available application servers Apache Tomcat can be considered as one of the best application servers (does not support all the features of J2EE). So let's download Tomcat (5.x or above) and install.

  2. Depending on the application server, you can find the location where you need to deploy the WAR files. If you take Tomcat as an example, you need to put the WAR file into the webapps directory. So let's drop Axis2 WAR distribution into the webapps directory of the application server.

  3. As the final step, open a browser and type http://localhost:8080/axis2. We can see Axis2 web application (as shown in the previous figure) home page (here the URL may differ, depending on the application server).

Source distribution

As the name implies, source distribution consist of the source code that is used to build binary distribution. As Apache Axis2 is released under Apache license, we can do anything with the source code. The idea is that the user can use Axis2 and modify to suit their requirements. Additionally, if they think that a modification is useful for other people, they can submit a patch and ask the project community to merge the changes to the main source repository.

When we develop a real application, it is always useful to have the source code around in addition to the documentation that helps to debug the application as well. In the meantime, source distribution consists of Maven scripts (http://maven.apache.org) and we can use them to create either binary distribution, WAR distribution, or even JAR distribution.

Document distribution

The document distribution provides all the necessary resources to understand the different features and functionality in the project. It provides Java documentation and tutorials, explaining how to use different features,

JAR distribution

One of the key steps of a web service is developing the Services and Clients. In that stage, we need to have access to the web service framework and their libraries. To access the APIs and other relevant resources, it is a common practice to add the required libraries into the Integrated Development Environment (IDE). Axis2 JAR distribution provides a convenient way to download and embed Axis2 runtime into the IDE. You can download Axis2 library files separately from the following links, or you can get those from Axis2 binary or WAR distribution:

http://people.apache.org/repo/m2-ibiblio-archived/org/apache/axis2/