Introduction Axis is a web service engine. It is the third generation of apache soap. This artical will gives you the brief introduction on SOAP. Then it will introduce you to Apache Axis 1.4. Then we will also tell about the diffrent styles of webservices in brief. The article will conclude by giving a sample application, explaining how to deploy webservice in axis? How to call the deployed webservice? Pre-Requesties
Other servlet engines are supported, provided they implement version 2.2 or greater of the servlet API.
Things to know before diving into Web Service
server. Should also have knowledge on servlets.
Software used in this artical
SOAP SOAP is an XML-based communication protocol and encoding format for inter-application communication. The current spec is version, SOAP 1.2, though version1.1 is more widespread. SOAP is the backbone of Web Services. Below shown is the sample SOAP request message.
Web Service Web service is a new generation cross-platform, cross-language distributed computing applications. Apache AxisAxis is a SOAP engine. It is a SOAP processer framework. The current version of Axis if written fully in Java. Axis has full support for the Web Service Description Language(WSDL). It has tools to generate java code (Client stubs) from WSDL as well as generate WSDL automatically from java code. Axis also has a simple stand alone server. It also has a server which plugs in to other servlet engins, like Tomcat. Axis also has a monitoring tool to monitor TCP/IP packets. Please note that this is an open-source effort. And in case you're wondering what Axis stands for, it's Apache EXtensible Interaction System - a fancy way of implying it's a very configurable SOAP engine. Axis is compiled in the JAR file axis.jar; it implements the JAX-RPC API declared in the JAR files jaxrpc.jar and saaj.jar. It needs various helper libraries, for logging, WSDL processing and introspection. All these files can be packaged into a web application, axis.war, that can be dropped into a servlet container. Diffrent Style of Web Services in AxisThere are four style of web services axis supports. They are:
we will take about these services after we see how to write deployment descriptor's to deploy a service Installing Axis
run on 8080 if you are using some other application servers please see the reference document on deploying web application in the server you are using)
if appropriate.
axis/WEB-INF/lib.
axis/WEB-INF/lib to CATALINA_HOME/common/lib and restart Tomcat.
Validating the Installation
page. If you are not able to see the page then probably your web application is not deployed properly.
and this is causing version confusion. Eliminate the extra parsers, restart the app server and try again.
which will list all the deployed web services. On this page, You should be able to click on (wsdl) for each deployed Web service to make sure that your web service is up and running. Deploying new Web ServicesNew Web services installation process
run the Axis SOAP client to talk to the Axis adminstration service, which is a SOAP service in its own right. It's also a special SOAP service. Implementing the process Prepare a batch file which will set all the axis related jar files to the classpath.
First we will write a simple java code like below
Compile the code and make a jar file. Here we created the jar file by name myApp.jar which contains the above code. Once myApp.jar is created, drop the jar inside axisWEB-INFlib folder in inside your application server. Now it is time to write a deployment descriptor file to deploy our service in axis. Web Service Deployment descriptor is nothing but a xml file with .wsdd extention. You can find a sample deployment descriptor below, which is used to deploy our example service HappyAxis packed into myApp.jar library.
The service element has a name attribute which will contain the service name you want to expose. provider attribute will contain the provider used for the service. here we are using the java:RPC provider. Insted of provider attribute we can also use style attribute where we can define the style of webservice like document or messaging style. Our service name we defined here is "MyService". service element has two child element named parameter. The first parameter element's name attribute will hold the value className and the value attribute will contain the exact class name including the package. Here our value is "myapp.HappyAxis". In the next parameter tag you can specify all the methods you like to expose in that class. If you want to expose all the methods in the class specify * in the value attribute. If you want to specify only one method or couple of methods, then specify the method name seperated by space. Save the above deployment descriptor as deploy.wsdd. Run the bath file which we prepared earlier to set classpath. Execute the following command from the directory where you have saved the deploy.wsdd. If you are not in this directory you will get a "java.io.FileNotFoundException: deploy.wsdd (The system cannot find the file specified)" exception
If you get some java client error (like ClassNotFoundException), then you haven't set up your CLASSPATH variable right, mistyped the classname, or did some other standard error. Tracking down such problems are foundational Java development skills--if you don't know how to do these things, learn them now! If you don't get any error then that means you have successfully deployed your web service. Now visit the Apache-Axis start page and navigate to the web service listing page. Here you can see your service getting displayed. Just click on the WSDL link, Axis will automaticly generate WSDL for your deployed service. Now we will see the styles of webservices possible in Axis As we have already seen there are four types of webservices supported in Axis. They are RPC(1), Document(2), Wrapped(3) and Message(4) RPC services RPC services are the default in Axis. They are what you get when you deploy services with <service ... provider="java:RPC"> or <service ... style="RPC">. RPC services follow the SOAP RPC and encoding rules. Axis will deserialize XML into Java objects which can be fed to your service, and will serialize the returned Java object(s) from your service back into XML. Since RPC services default to the soap section 5 encoding rules, objects will be encoded via "multi-ref" serialization, which allows object graphs to be encoded. Document / Wrapped service Document and Wrapped services are similar, both use SOAP encoding for data.(means its plain xml schema). Axis binds java objects for the xml schema here. so in the end you will end up using java objects. You will not use the xml directly here. The document or wrapped style is indicated in WSDD as follows: Message service Message service should be used when you want Axis to step back and let your code at the actual XML instead of turning it into Java objects. There are four valid signatures for your message-style service methods: Consuming the deployed Web ServicesBasic simple way to consume a Web ServiceFirst we will see the basic way of calling a web service with out generating stubs from WSDL The code below is used to call our deployed web service "MyService"
The program can be run as follows
Consume a Web Service by creating stubs from WSDLBefore getting into creating stubs, we will have a quick look at what is WSDL? The Web Service Description Language is a specification authored by IBM and Microsoft, and supported by many other organizations. WSDL serves to describe Web Services in a structured way. A WSDL description of a service tells us, in a machine-understandable way, the interface to the service, the data types it uses, and where the service is located. Axis supports WSDL in three ways:
With this information, Now we will see how to build stubs from WSDL to call our deployed web service Client-side binding Axis provides WSDL-to-Java tool in org.apache.axis.wsdl.WSDL2Java. The basic invocation looks like this:
This command will generate the java stubs with those bindings necessary for the client. Axis follows JAX-RPC specification when generating the client binding from WSDL description. For our client stub generation, First we will save the wsdl to a perticular location. Then we will invoke the following command as this: Once this invocation happens, then we can see the stubs getting generated in the same directory from where we invocked the command. Now we are ready to go. Just compile the stubs and write a CLI (Command Line Interface) which will make use of the generated stub and calls the web service. ConclusionSo we came across Axis webservices by touching on some of the features of axis. We do came across a sample webservice wich uses RPC style. We also saw how to generate the stubs and call the web service. Here I whould say we just had a dip in to the sea of webservice by just going through a sample application deployment in axis. There are lot to learn about it. Please dive deep in to the sea called webservice for the treasure of knowledge about it. Happy Axis.. :) |
javawaveblogs-20
Friday, September 21, 2007
Happy Axis
Subscribe to:
Post Comments (Atom)
1 comment:
good work muthu.
Instead posting such a lengthy article in single post, split into many posts.
Post a Comment