Intro To Apache Axis
Intro To Apache Axis
Intro To Apache Axis
Slides 45 Duration 1 hr
Web
Web Services Basics What is Web Service? Web Services Architecture Ways to develop Web services XML Messaging XML-RPC SOAP What is WSDL? Development plan for Service Requestor Development plan for Service Provider
Intro
to Apache Axis
2) Discover services
1) Register service
Service Requestor
Consumer of the Web Service
3) Invoke service
Service Provider
Provider of the Web Service
Discovery
UDDI
Description
WSDL
XML Messaging
XML-RPC,SOAP,XML
Transport
HTTP,SMTP,FTP,BEEP
1. 2.
REST SOAP
In RESTful web services, the emphasis is on simple point-topoint communication over HTTP using plain old XML It uses protocol methods for its operations like :
HTTP CRUD Equivalent :GET read POST update PUT create DELETE delete
One example is the stock quote service as a RESTful web service . The request: GET /StockPrice/IBM HTTP/1.1 Host: example.org Accept: text/xml Accept-Charset: utf-8 The response:
HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <s:Quote xmlns:s="http://example.org/stock-service"> <s:TickerSymbol>IBM</s:TickerSymbol> <s:StockPrice>45.25</s:StockPrice> </s:Quote>
SOAP
is
a simple protocol that uses XML messages to perform RPC Request are encoded in XML and send via HTTP Response are encoded in XML and received via HTTP is a easiest way to get started with web services
<methodCall> <methodName> com.agram.sayHello </methodName> <params> <param> <value>Java</value> </param> </params> </methodCall>
<methodResponse> <params> <param> <value> <string>Hello Java</string> </value> </param> </params> </ methodResponse >
Simple
Object Access Protocol SOAP is slightly more complicated than the XML-RPC SOAP extended XML-RPC It uses XML namespaces and XML Schemas.
Envelope is like a SOAP Message wrapper for content Header is a optional Envelope element that could contain control information Header Body element includes requests and responses Body element will include Body a Fault element in the event of an error
GET /StockPrice HTTP/1.1 Host: example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:s="http://www.example.org/stock-service"> <env:Body> <s:GetStockQuote> <s:TickerSymbol>IBM</s:TickerSymbol> </s:GetStockQuote> </env:Body> </env:Envelope>
The <Fault> is the standard element for error handling. When present, it is the only child element of the SOAP <Body>. The structure of a fault looks like:
<env:Fault xmlns:m="http://www.example.org/timeouts"> <env:Code> <env:Value>env:Sender</env:Value> <env:Subcode> <env:Value>m:MessageTimeout</env:Value> </env:Subcode> </env:Code> <env:Reason> <env:Text xml:lang="en">Sender Timeout</env:Text> </env:Reason> <env:Detail> <m:MaxTime>P5M</m:MaxTime> </env:Detail> </env:Fault>
An
does not depend on the underlying protocol But: It is not much human-readable
1. 2. 3. 4. 5.
6.
4) Deploy service
Axis is essentially a SOAP engine a framework for constructing SOAP processors such as clients , servers, gateways etc - Axis Website
or as an a server that plugs into Servlet engine like Tomcat Automatic WSDL generation for deployed services Java2WSDL to generate WSDL from Java interface WSDL2Java to generate Java classes from WSDL Easy deployment
1) Download Axis Distribution archive from http://xml.apache.org/axis/ - Axis distribution archive contains a web application ( webapps/axis/ directory) for hosting an Axis Server in a web container like Tomcat
3) Configure the environment by including these libraries in the CLASSPATH - log4j-core.jar - commons-logging.jar - wsdl4j.jar - jaxrpc.jar - tt.bytecode.jar - xerces.jar ( or any other XML Parser)
1) 2)
3)
Goto http://localhost:8080/axis/happyaxis.jsp
- this test page verifies whether all the needed and optional libraries are present. - Axis will not perform properly until all the needed libraries are present.
The two ways we can publish a web service with Axis are,
1. Instant Deployment Java Web Service (JWS) 2. Custom Deployment Using Web Service Deployment Descriptor ( WSDD)
1.
Code code a simple HelloWorld java class that we want to expose as web service Java2WSDL Generate the WSDL file for the given HelloWorld Interface
2.
3.
WSDL2Java Generate the Server side wrapper class and stubs for easy client access
Deploy deploy the service to apache axis
4.
5.
Client code a simple client that access our HelloWorld Web Service
HelloWorld.java package helloworld; public interface HelloWorld { public String sayHello( String name); }
HelloWorldImpl.java
package helloworld; public class HelloWorldImpl implements HelloWorld {
public String sayHello( String name){ if(name == null) return Hello Everyone; else return Hello + name; }
}
This command will generate the WSDL that Conforms to our interface
% java org.apache.axis.wsdl.Java2WSDL -o hello.wsdl -l http://localhost:8080/axis/services/helloworld -n urn:helloworld -phelloworld" urn:helloworld helloworld.HelloWorld Parameters description -o = Name of the output -l = URL of the web Service -n = Target Namespace for the WSDL -p = Map Java package to namespace Fully Qualified Class Name
This command will generate the wrapper code for deploying the service, as well as client stubs for accessing it.
% java org.apache.axis.wsdl.WSDL2Java -o . -d Session -s -p helloworld.gen hello.wsdl Parameters description -o = Base output Directory -d = Scope of deployment -s = To generate Server-side code too -p = Package to place the code Name of the WSDL
HelloWorldSoapBindingImpl.java This is the implementation code for the Web Service HelloWorld.java This is the remote interface HelloWorldService.java This is the service interface HelloWorldServiceLocator.java Helper class to retrieve handler to service HelloWorldSoapBindingSkeleton.java Server-side skeleton code HelloWorldSoapBindingStub.java Client side stub deploy.wsdd axis deployment descriptor undeploy.wsdd deployment descriptor to undeploy the web services from the Axis System
2. 3. 4. 5. 6. 7. 8.
HelloWorldSoapBindingImpl package helloworld.gen; import helloworld.HelloWorldImpl; public class HelloWorldSoapBindingImpl implements helloworld.gen.HelloWorld { HelloWorldImpl helloWorld = new HelloWorldImpl(); public String sayHello(String str0) throws java.rmi.RemoteException {
}
}
return helloWorld.sayHello(str0);
1.
2.
3.
Web Service
Axis
Roles in Web Services Web Services Protocol Stack Different ways of XML Messaging Development plan for Service Requestor and Provider
Architecture of Axis Features of Apache Axis Installing Apache Axis Different ways of deploying Web Service with Axis Deploying and accessing a simple web service using Apache Axis
Web
Services & Java home http://java.sun.com/j2ee/webservices/index.html Java Web Services tutorial http://java.sun.com/xml/docs.html#tutorials Apache Axis http://xml.apache.org/axis/index.html SOAP 1.1 - http://www.w3.org/TR/SOAP WSDL 1.1 - http://www.w3.org/TR/wsdl