Intro to Apache Axis (1)

Embed Size (px)

Citation preview

  • 8/4/2019 Intro to Apache Axis (1)

    1/45

    Antaryami SahooSlides 45

    Duration 1 hr

  • 8/4/2019 Intro to Apache Axis (1)

    2/45

    Web Services Basics Intro to Apache Axis

  • 8/4/2019 Intro to Apache Axis (1)

    3/45

    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

  • 8/4/2019 Intro to Apache Axis (1)

    4/45

    Intro to Apache Axis What is Apache Axis?

    Features of Apache Axis

    Installing Apache Axis

    Publishing Web Service through Apache Axis

    Walkthrough of deploying and accessing a simpleweb service using Apache Axis

  • 8/4/2019 Intro to Apache Axis (1)

    5/45

    A Web Service is any service that is available over the web

    uses standardized XML messaging

    is OS and Programming language independent

  • 8/4/2019 Intro to Apache Axis (1)

    6/45

    There are two ways we can view WebServices

    architecture

    1. Web Service Roles

    2. Web Service Protocol Stack

  • 8/4/2019 Intro to Apache Axis (1)

    7/45

    There are three major roles

    Service

    Registry

    Service

    Requestor

    Service

    Provider

    2) Discover services

    3) Invoke service

    Provider of the Web ServiceConsumer of the Web Service

    Logically Centralized directory

    of services

    1) Register service

  • 8/4/2019 Intro to Apache Axis (1)

    8/45

    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

  • 8/4/2019 Intro to Apache Axis (1)

    9/45

    1. REST2. SOAP

    REST ( Representative State Transfer) : In RESTful web services, the emphasis is on simple point-to-

    point communication over HTTP using plain old XML It uses protocol methods for its operations like :

    HTTPCRUD Equivalent :-GET readPOST updatePUT createDELETE delete

  • 8/4/2019 Intro to Apache Axis (1)

    10/45

  • 8/4/2019 Intro to Apache Axis (1)

    11/45

    There are two ways of XML Messaging

    XML-RPC

    SOAP

  • 8/4/2019 Intro to Apache Axis (1)

    12/45

    is a simple protocol that uses XMLmessages to perform RPC

    Request are encoded in XML and send viaHTTP

    Response are encoded in XML andreceived via HTTP

    is a easiest way to get started with webservices

  • 8/4/2019 Intro to Apache Axis (1)

    13/45

    com.agram.sayHello

    Java

  • 8/4/2019 Intro to Apache Axis (1)

    14/45

    Hello Java

  • 8/4/2019 Intro to Apache Axis (1)

    15/45

    Simple Object Access ProtocolSOAP is slightly more complicated than

    the XML-RPCSOAP extended XML-RPC It uses XML namespaces and XML

    Schemas.

  • 8/4/2019 Intro to Apache Axis (1)

    16/45

    Envelope is like awrapper for content

    Header is a optionalelement that could contain

    control information Body element includes

    requests and responses Body element will include

    a Fault element in theevent of an error

    SOAP Message

    Envelope

    Header

    Body

  • 8/4/2019 Intro to Apache Axis (1)

    17/45

  • 8/4/2019 Intro to Apache Axis (1)

    18/45

    GET /StockPrice HTTP/1.1Host: example.orgContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

    IBM

  • 8/4/2019 Intro to Apache Axis (1)

    19/45

    HTTP/1.1 200 OKContent-Type: application/soap+xml; charset=utf-8Content-Length: nnn

    45.25

  • 8/4/2019 Intro to Apache Axis (1)

    20/45

    The is the standard element for error handling. When present, itis the only child element of the SOAP . The structure of a faultlooks like:

    env:Sender

    m:MessageTimeout

    Sender Timeout

    P5M

  • 8/4/2019 Intro to Apache Axis (1)

    21/45

    Web Services Description Language

    An XML-based language for describingWeb Services

    what the service does (description) how to use it (method signatures)

    where to find the service

    It does notdepend on the underlyingprotocol

    But: It is not much human-readable

  • 8/4/2019 Intro to Apache Axis (1)

    22/45

    Has 6 major elements1. definitions defines the name of the web service

    2. types describes all the data types that will betransmitted

    3. message defines the name of the message thatwill be transmitted

    4. portType defines the operations

    5. binding defines how the message will be

    transmitted6. service defines where the service is located

  • 8/4/2019 Intro to Apache Axis (1)

    23/45

    Universal Description, Discovery and

    Integrationhttp://www.uddi.org

    UDDI creates a platform-independent, open framework &

    registry for:

    Describing services

    Discovering businesses

    Integrating business services

    The UDDI may be less used than predicted, especially onthe Internet level

  • 8/4/2019 Intro to Apache Axis (1)

    24/45

    1) Find web service via UDDI

    2) Retrieve service description file

    3) Create XML-RPC or SOAP client

    4) Invoke remote service

  • 8/4/2019 Intro to Apache Axis (1)

    25/45

    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

  • 8/4/2019 Intro to Apache Axis (1)

    26/45

    Axis is essentially a SOAP engine aframework for constructing SOAPprocessors such as clients , servers,gateways etc

    - Axis Website

  • 8/4/2019 Intro to Apache Axis (1)

    27/45

    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

  • 8/4/2019 Intro to Apache Axis (1)

    28/45

    1) Download Axis Distribution archive fromhttp://xml.apache.org/axis/

    - Axis distribution archive containsa web application ( webapps/axis/directory) for hosting an Axis Server in a

    web container like Tomcat

    http://xml.apache.org/axis/http://xml.apache.org/axis/
  • 8/4/2019 Intro to Apache Axis (1)

    29/45

    2) Deploy Axis Server in the Tomcat 5.Xserver

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

    b) Copy jaxrpc.jar (that is provided with Axisdistribution) and xerces.jar ( or any other XMLparser) to $TOMCAT_HOME/common/lib

    jaxrpc.jar and xerces.jar includes classes with java andjavax packages and Tomcat does not authorize to load any classes

    in that package from WEB-INF/ lib directory of the web application.

  • 8/4/2019 Intro to Apache Axis (1)

    30/45

    3) Configure the environment by includingthese libraries in the CLASSPATH

    - log4j-core.jar- commons-logging.jar- wsdl4j.jar- jaxrpc.jar- tt.bytecode.jar- xerces.jar ( or any other XML Parser)

  • 8/4/2019 Intro to Apache Axis (1)

    31/45

    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 running3) Goto http://localhost:8080/axis/happyaxis.jsp

    - this test page verifies whether all the needed andoptional libraries are present.

    - Axis will not perform properly until all theneeded libraries are present.

    http://localhost:8080/axis/http://localhost:8080/axis/happyaxis.jsphttp://localhost:8080/axis/happyaxis.jsphttp://localhost:8080/axis/
  • 8/4/2019 Intro to Apache Axis (1)

    32/45

    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)

  • 8/4/2019 Intro to Apache Axis (1)

    33/45

  • 8/4/2019 Intro to Apache Axis (1)

    34/45

    1. Code code a simple HelloWorld java class that wewant to expose as web service

    2. Java2WSDL Generate the WSDL file for the givenHelloWorld Interface

    3. WSDL2Java Generate the Server side wrapperclass and stubs for easy client access

    4. Deploy deploy the service to apache axis

    5. Client code a simple client that access ourHelloWorld Web Service

  • 8/4/2019 Intro to Apache Axis (1)

    35/45

    HelloWorld.java

    package helloworld;

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

    }

  • 8/4/2019 Intro to Apache Axis (1)

    36/45

    HelloWorldImpl.java

    package helloworld;

    public class HelloWorldImpl implements HelloWorld {

    public String sayHello( String name){if(name == null)

    return Hello Everyone;else

    return Hello + name;}

    }

  • 8/4/2019 Intro to Apache Axis (1)

    37/45

    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-phelloworld" urn:helloworldhelloworld.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 namespaceFully Qualified Class Name

  • 8/4/2019 Intro to Apache Axis (1)

    38/45

    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.genhello.wsdl

    Parameters description-o = Base output Directory-d = Scope of deployment

    -s = To generate Server-side code too-p = Package to place the codeName of the WSDL

  • 8/4/2019 Intro to Apache Axis (1)

    39/45

    These are the codes that will get generated1. 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 fromthe Axis System

  • 8/4/2019 Intro to Apache Axis (1)

    40/45

    HelloWorldSoapBindingImplpackage helloworld.gen;

    public class HelloWorldSoapBindingImpl implementshelloworld.gen.HelloWorld

    {

    public String sayHello(String str0) throwsjava.rmi.RemoteException {

    }}

    import helloworld.HelloWorldImpl;

    HelloWorldImpl helloWorld = new HelloWorldImpl();

    return helloWorld.sayHello(str0);

  • 8/4/2019 Intro to Apache Axis (1)

    41/45

    1. 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 Done processing

  • 8/4/2019 Intro to Apache Axis (1)

    42/45

    package helloworld;

    Import helloworld.gen.*;public class HelloWorldTester {

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

    {// Make a service

    HelloWorldService service = newHelloWorldServiceLocator();// Now use the service to get a stub to the servicehelloworld.gen.HelloWorld hello = service.getHelloWorld();// Make the actual callSystem.out.println( hello.sayHello(Java Gurus) );

    }

    }

  • 8/4/2019 Intro to Apache Axis (1)

    43/45

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

  • 8/4/2019 Intro to Apache Axis (1)

    44/45

    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

    http://java.sun.com/j2ee/webservices/index.htmlhttp://java.sun.com/xml/docs.htmlhttp://xml.apache.org/axis/index.htmlhttp://www.w3.org/TR/SOAPhttp://www.w3.org/TR/wsdlhttp://www.w3.org/TR/wsdlhttp://www.w3.org/TR/SOAPhttp://xml.apache.org/axis/index.htmlhttp://java.sun.com/xml/docs.htmlhttp://java.sun.com/j2ee/webservices/index.html
  • 8/4/2019 Intro to Apache Axis (1)

    45/45