Intro to Apache Axis Siva Jagadeesan [email protected].

42
Intro to Apache Axis Intro to Apache Axis Siva Jagadeesan [email protected]

Transcript of Intro to Apache Axis Siva Jagadeesan [email protected].

Page 1: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Intro to Apache AxisIntro to Apache Axis

Siva Jagadeesan [email protected]

Page 2: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

About MeAbout Me

I am a Java Consultant working in a project for Deloitte Consulting

My fields of Expertise– J2EE Technologies

– Java tools for Extreme Programming (Ant, JUnit etc) My fields of Interest

– Web Services

– J2ME

– Aspect Oriented Programming

Page 3: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

AgendaAgenda

Web Services BasicsIntro to Apache Axis

Page 4: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

OutlineOutline

Web Services Basics– What is Web Service?– Web Services Architecture– XML Messaging

XML-RPCSOAP

– What is WSDL?– Development plan for Service Requestor– Development plan for Service Provider

Page 5: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

OutlineOutline

Intro to Apache Axis– What is Apache Axis?– Architecture of Apache Axis– Features of Apache Axis– Installing Apache Axis– Publishing Web Service through Apache Axis– Walkthrough of deploying and accessing a

simple web service using Apache Axis

Page 6: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

What is Web Service?What is Web Service?

A Web Service is any service that – is available over the web– uses standardized XML messaging– is OS and Programming language

independent

Page 7: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Web Services ArchitectureWeb Services Architecture

There are two ways we can view Web Servicesarchitecture

1. Web Service Roles

2. Web Service Protocol Stack

Page 8: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Web Service RolesWeb Service Roles

There are three major roles

Service Registry

Service Requestor

ServiceProvider

2) Discover services

3) Invoke service

Provider of the Web Service Consumer of the Web Service

Logically Centralized directory of services

1) Register service

Page 9: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Web Service Protocol StackWeb Service Protocol Stack

Discovery UDDI

Description WSDL

XML Messaging XML-RPC,SOAP,XML

Transport HTTP,SMTP,FTP,BEEP

Responsible for centralizing services

Responsible for transporting messages

Responsible for describing the public interface to a specific web service

Responsible for encoding messages in common XML format

Page 10: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

XML MessagingXML Messaging

There are two ways of XML Messaging

• XML-RPC

• SOAP

Page 11: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

What is XML-RPC ?What is XML-RPC ?

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

Page 12: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Sample XML-RPC RequestSample XML-RPC Request

<methodCall><methodName>

com.agram.sayHello</methodName>

<params><param>

<value>Java</value></param>

</params></methodCall>

Page 13: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Sample XML-RPC ResponseSample XML-RPC Response

<methodResponse> <params>

<param><value>

<string>Hello Java</string></value>

</param> </params></ methodResponse >

Page 14: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

What is SOAP?What is SOAP?

Simple Object Access ProtocolSOAP is slightly more complicated than

the XML-RPCSOAP extended XML-RPCIt uses XML namespaces and XML

Schemas.

Page 15: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

SOAP MessageSOAP Message

Envelope is like a wrapper for content

Header is a optional element that could contain control information

Body element includes requests and responses

Body element will include a Fault element in the event of an error

SOAP Message

Envelope

Header

Body

Page 16: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Sample SOAP RequestSample SOAP Request

<SOAP-ENV:Envelopexmlns:xsd="http://www.w3.org/2001/XMLSchema"

      xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/

     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<SOAP-ENV:Body>     <ns1:sayHello xmlns:ns1="http://agram.com/">       <name xsi:type="xsd:string">Java</name></ns1:sayHello>

  </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Page 17: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Sample SOAP ResponseSample SOAP Response

<SOAP-ENV:Envelopexmlns:xsd="http://www.w3.org/2001/XMLSchema"

      xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<SOAP-ENV:Body>     <ns1:sayHelloReponse xmlns:ns1="http://agram.com/"> <result xsi:type="xsd:string">Hello Java</result>

</ns1:sayHelloResponse>   </SOAP-ENV:Body>

</SOAP-ENV:Envelope>

Page 18: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

What is WSDL?What is WSDL?

Web Services Description Language Has 6 major elements

1. definitions – defines the name of the web service2. types – describes all the data types that will be

transmitted3. message – defines the name of the message that will

be transmitted4. portType – defines the operations 5. binding – defines how the message will be

transmitted6. service – defines where the service is located

Page 19: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Development plan for Service RequestorDevelopment plan for Service Requestor

1) Find web service via UDDI

2) Retrieve service description file

3) Create XML-RPC or SOAP client

4) Invoke remote service

Page 20: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Development plan for Service ProviderDevelopment plan for Service Provider

1) Create the core functionality

2) Create XML-RPC or SOAP service wrapper

3) Create service description file

4) Deploy service

5) Register new service via UDDI

Page 21: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

What is Apache Axis?What is Apache Axis?

“Axis is essentially a SOAP engine – a framework for constructing SOAP processors such as clients , servers, gateways etc”

- Axis Website

Page 22: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Architecture of Apache AxisArchitecture of Apache Axis

Page 23: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Architecture of Apache AxisArchitecture of Apache Axis

1. Admin Sub-systemhandles administration and configuration of the server

2. Service Sub-systemimplements the RPC exchange protocol

3. Provider Sub-systemis the interface between Axis server and the external component methods that are to be exposed as webservice

4. Transport Sub-systemreceives and delivers the message from the service sub system

5. Encoding Sub-systemmanages encoding/decoding and serilization/deserilization between XML data types and Java Classes

6. Message Sub-systemdefines the structure of the different elements of a SOAP message and provides functionality for binding and parsing the different elements of these messages

Page 24: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Features of Apache AxisFeatures of Apache Axis

Successor to Apache SOAP It can run as a standalone server 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 Uses JAX-RPC API

Page 25: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Installing Apache AxisInstalling Apache Axis

1) Download Axis Distribution archive fromhttp://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

Page 26: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Installing Apache Axis (Cont)Installing Apache Axis (Cont)

2) Deploy Axis Server in the Tomcat 4.X server

a) Copy Axis Web application (webapps/axis directory) to $TOMCAT_HOME/webapps

b) Copy jaxrpc.jar (that is provided with Axis distribution) and xerces.jar ( or any other XML parser) to $TOMCAT_HOME/common/lib

jaxrpc.jar and xerces.jar includes classes with “java” and “javax” packages and Tomcat does not authorize to load any classes in that package from WEB-INF/ lib directory of the web application.

Page 27: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Installing Apache Axis (Cont)Installing Apache Axis (Cont)

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)

Page 28: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Validating the InstallationValidating the Installation

1) Start the Tomcat Web Server2) Goto http://localhost:8080/axis/

- you should be able to see Apache-Axis start page- if you did not , then the axis is not correctly installed or the web server is not running

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.

Page 29: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Publishing Web Service through Apache Publishing Web Service through Apache AxisAxis

The two ways we can publish a web servicewith Axis are,

1. Instant Deployment – Java Web Service (JWS)

2. Custom Deployment – Using Web Service Deployment Descriptor ( WSDD)

Page 30: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Walkthrough of deploying and accessing a Walkthrough of deploying and accessing a simple web service using Apache Axissimple web service using Apache Axis

Page 31: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

The steps we will walkthroughThe steps we will walkthrough

1. Code – code a simple HelloWorld java class that we want to expose as web service

2. Java2WSDL – Generate the WSDL file for the given HelloWorld Interface

3. WSDL2Java – Generate the Server side wrapper class and stubs for easy client access

4. Deploy – deploy the service to apache axis

5. Client – code a simple client that access our HelloWorld Web Service

Page 32: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 1: CodeStep 1: Code

HelloWorld.java

package helloworld;

public interface HelloWorld { public String sayHello( String name); }

Page 33: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 1: Code (Cont)Step 1: Code (Cont)

HelloWorldImpl.java

package helloworld;

public class HelloWorldImpl implements HelloWorld {

public String sayHello( String name){if(name == null)return “Hello Everyone”;elsereturn “Hello “ + name;

}

}

Page 34: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 2: Java2WSDLStep 2: Java2WSDL

This command will generate the WSDL thatConforms to our interface% java org.apache.axis.wsdl.Java2WSDL

-o hello.wsdl -l http://localhost:8080/axis/services/helloworld

-n urn:helloworld -p“helloworld" urn:helloworld helloworld.HelloWorldParameters 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

Page 35: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 3: WSDL2JavaStep 3: WSDL2Java

This command will generate the wrapper code fordeploying the service, as well as client stubs foraccessing it.% java org.apache.axis.wsdl.WSDL2Java

-o . -d Session

-s -p helloworld.gen hello.wsdlParameters 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

Page 36: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 3: WSDL2JavaStep 3: WSDL2Java

These are the codes that will get generated

1. HelloWorldSoapBindingImpl.java – This is the implementation code for the Web Service

2. HelloWorld.java – This is the remote interface

3. HelloWorldService.java – This is the service interface

4. HelloWorldServiceLocator.java – Helper class to retrieve handler to service

5. HelloWorldSoapBindingSkeleton.java – Server-side skeleton code

6. HelloWorldSoapBindingStub.java – Client side stub

7. deploy.wsdd – axis deployment descriptor

8. undeploy.wsdd – deployment descriptor to undeploy the web services from the Axis System

Page 37: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 3: WSDL2JavaStep 3: WSDL2JavaHelloWorldSoapBindingImplpackage helloworld.gen;

public class HelloWorldSoapBindingImpl implements helloworld.gen.HelloWorld

{

public String sayHello(String str0) throws java.rmi.RemoteException {

}}

import helloworld.HelloWorldImpl;

HelloWorldImpl helloWorld = new HelloWorldImpl();

return helloWorld.sayHello(str0);

Page 38: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 4: DeployStep 4: Deploy1. Compile the Service Code

% javac helloworld\gen\*.java

2. Package the code for Axis% jar cvf hello.jar helloworld/*.class helloworld/gen/*.class% mv hello.jar $TOMCAT_HOME/webapps/axis/WEB-

INF/lib

3. Deploy the Service using WSDD% java org.apache.axis.client.AdminClient deploy.wsdd<admin> Done processing </Done>

Page 39: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Step 5: ClientStep 5: Clientpackage helloworld;

Import helloworld.gen.*;

public class HelloWorldTester {

public static void main(String [] args) throws Exception

{ // Make a service HelloWorldService service = new

HelloWorldServiceLocator();

// Now use the service to get a stub to the service helloworld.gen.HelloWorld hello = service.getHelloWorld();

// Make the actual call System.out.println( hello.sayHello(“Java Gurus”) );

} }

Page 40: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

SummarySummary

Web Service – Roles in Web Services– Web Services Protocol Stack– Different ways of XML Messaging– Development plan for Service Requestor and Provider

Axis– 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

Page 42: Intro to Apache Axis Siva Jagadeesan sivajag@hotmail.com.

Questions/Feedbacks?Questions/Feedbacks?

Contact me [email protected]