Creating a Web Service Using Apache Axis2 - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Creating a Web Service Using Apache Axis2

Description:

Title: Chapter 2: Basic Standards for Web Services Subject: Service-Oriented Computing Author: Dr. Munindar P. Singh & Prof. Michael N. Huhns Last modified by – PowerPoint PPT presentation

Number of Views:303
Avg rating:3.0/5.0
Slides: 22
Provided by: DrMuni91
Category:

less

Transcript and Presenter's Notes

Title: Creating a Web Service Using Apache Axis2


1
Creating a Web Service Using Apache Axis2
  • CSCE 526 Service-Oriented Computing

2
Axis2
  • Is an engine for Web services
  • Is an implementation of the SOAP ("Simple Object
    Access Protocol") submission to W3C
  • Supports not only SOAP 1.1 and SOAP 1.2, but also
    REST

3
Creating Services and Clients
  • Axis2 makes these tasks very easy, as it comes
    with code generator tools that simplify the work
    for you
  • Basically, you can use the code generator to
  • Generate code to access an existing service as a
    client
  • Generate a WSDL file from java source code
  • Generate the skeletal code to implement a service
    from a WSDL file describing the service
    functionality

4
Get your environment ready for working with Axis2
  • Download and install a Java Development Kit (JDK)
    release (version 1.4 or  later)
  • Set an environment variable JAVA_HOME to the
    pathname of the directory into which you
    installed the JDK release
  • Download Apache Axis2 (currently at
    http//ws.apache.org/axis2/download/1_4_1/download
    .html and extract it to a target directory
  • Set the AXIS2_HOME environment variable to point
    to the target directory in the previous step
  • Add the AXIS2_HOME\bin directory to your PATH
    environment variable
  • Download Apache Ant and extract it to a target
    directory
  • Set the ANT_HOME environment variable to point to
    the target directory in the previous step
  • Add the ANT_HOME\bin directory to your PATH
    environment variable

5
Creating Services
JAVA class containing the functionality (public
methods) you want to expose in a service
Skeletal code to implement the service on the
server side
java2wsdl
wsdl2java
WSDL file describing the service functionality
6
Generating a WSDL file from a Java class
public class WeightConverter         public
double kgtopounds (double kg)        return
kg2.20462262        public double poundstokg
(double pounds)        return
pounds/2.20462262   
schema target namespace
classpath
java -cp . WeightConverter.java
java2wsdl -cp . -tn weightconverter -stn
weightconverter -cn WeightConverter
target namespace
class name
7
Generating the service skeletal code from the
WSDL file
service descriptor
wsdl2java -ss -sd -uri WeightConverter.wsdl
server side
  • A src directory is created with the source code
    for the server side files
  • A resources directory is created with the WSDL
    file for the service and a service descriptor
    (services.xml) file
  • A build.xml file is created in the current
    directory, which will be used to create the ws
    deployment file

8
Filling the server skeletal code
  • Now you need to fill WeightConverterSkeleton.java 
    with the necessary business logic. You can copy
    the functionality from your original java file,
    though you need to change it a little to match
    the new data types

9
Filling the server skeletal code
  • public weightconverter.KgtopoundsResponse
    kgtopounds (weightconverter.Kgtopounds
    param0)  //Todo fill this with the necessary
    business logic   throw new 
  • java.lang.UnsupportedOperationException("Please
    implement " this.getClass().getName()
    "kgtopounds") 

10
Filling the server skeletal code
  • You need to replace the  throw instruction (which
    is the default functionality for the case in
    which not implementation is provided before
    deploying the service) by your original
    functionality, which was
  •     public double kgtopounds (double kg)       
    return kg2.20462262

11
Filling the server skeletal code
  • But as you can see, the input and output
    parameters are different than in our original
    WeightConverter class

public weightconverter.KgtopoundsResponse
kgtopounds (weightconverter.Kgtopounds
param0)  //Todo fill this with the necessary
business logic   throw new  java.lang.Unsupport
edOperationException("Please implement "
this.getClass().getName() "kgtopounds") 
  •   public double kgtopounds (double kg)       
    return kg2.20462262

12
Filling the server skeletal code
  • The original kgtopounds method takes a double and
    returns a double. The new kgtopounds method takes
    a weightconverter.Kgtopounds object and returns a
    weightconverter.KgtopoundsResponse object
  • If you dive into the generated Kgtopounds and
    KgtopoundsResponse data type files you will find
    the methods public double getParam0() and public
    void set_return(double param) in them

13
Filling the server skeletal code
  • You can use those methods to get the double value
    of the input parameter, then perform your
    original operations, and finally set the double
    value of the output. The result is as follows
  •  public weightconverter.KgtopoundsResponse
    kgtopounds (weightconverter.Kgtopounds
    param0)       double kg param0.getParam0() 
         weightconverter.KgtopoundsResponse result
  • new weightconverter.KgtopoundsResponse()   
       result.set_return(kg2.20462262)     
     return result 

14
Compiling the Code
  • Download the compile.bat script
  • http//www.cse.sc.edu/huhns/csce526/compile.bat
  • into the src directory and use it to compile
    the source code files
  • compile weightService\.java
  • This script calls the "javac" command after
    adding the classpath for Axis2 dependent
    libraries (.jar files present in your
    AXIS2_HOME/lib)

15
Deploying and Running the Service
  • Once you have compiled the server files, use the
    ant command (run it where the build.xml file is)
    to generate the deployment files for the service
  • ant jar.server
  • A build directory will be created
  • Copy the build\lib\WeightConverter.aar file to
    the AXIS2_HOME/repository/services directory

16
Running your Service
  • Run the Axis2 server with 
  • axis2server
  • This will start a standalone Axis2 server using
    the AXIS2_HOME/repository directory as the Axis2
    repository and the AXIS2_HOME/conf/axis2.xml as
    the Axis2 configuration file

17
A SOAP request for your service
lt?xml version"1.0" encoding"UTF-8"
?gt ltsoapenvEnvelope xmlnssoapenv"http//sch
emas.xmlsoap.org/soap/envelope/"
xmlnsxsd"http//www.w3.org/2001/XMLSchema"
xmlnsxsi"http//www.w3.org/2001/XMLSchema-instan
ce"gt ltsoapenvBodygt ltkgtopounds
xmlns"weightconverter"gt ltparam0gt50lt/param0gt lt
/kgtopoundsgt lt/soapenvBodygt lt/soapenvEnvelopegt
18
A SOAP request for your service TCPMon
19
An HTTP request for your service
http//localhost8080/axis2/services/WeightConvert
er/kgtopounds?param050
20
An HTTP request for your service
21
Code and Archive Generator Plug-Ins for Eclipse
http//ws.apache.org/axis2/tools/index.html
Write a Comment
User Comments (0)
About PowerShow.com