Creating a web service using apache axis2
Download
1 / 21

Creating a Web Service Using Apache Axis2 - PowerPoint PPT Presentation


  • 302 Views
  • Updated On :

Creating a Web Service Using Apache Axis2. CSCE 526: Service-Oriented Computing. 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. Creating Services and Clients.

Related searches for Creating a Web Service Using Apache Axis2

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Creating a Web Service Using Apache Axis2' - Gabriel


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Creating a web service using apache axis2 l.jpg

Creating a Web Service Using Apache Axis2

CSCE 526: Service-Oriented Computing


Axis2 l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Creating services and clients l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Get your environment ready for working with axis2 l.jpg
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.htmland 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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Creating services l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Generating a wsdl file from a java class l.jpg
Generating a WSDL file from a Java class

public class WeightConverter {    public double kgtopounds (double kg){        return kg*2.20462262;    }    public double poundstokg (double pounds){        return pounds/2.20462262;    }}

classpath

schema target namespace

java -cp . WeightConverter.java

java2wsdl -cp . -tn weightconverter -stn weightconverter -cn WeightConverter

target namespace

class name

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Generating the service skeletal code from the wsdl file l.jpg
Generating the service skeletal code from the WSDL file

service descriptor

  • 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

wsdl2java -ss -sd -uri WeightConverter.wsdl

server side

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Filling the server skeletal code l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Filling the server skeletal code9 l.jpg
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"); }

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Filling the server skeletal code10 l.jpg
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 kg*2.20462262;}

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Filling the server skeletal code11 l.jpg
Filling the server skeletal code

  • But as you can see, the input and output parameters are different than in our original WeightConverterclass

  public double kgtopounds (double kg){        return kg*2.20462262;}

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"); }

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Filling the server skeletal code12 l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Filling the server skeletal code13 l.jpg
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(kg*2.20462262);       return result; }

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Compiling the code l.jpg
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)

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Deploying and running the service l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Running your service l.jpg
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

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


A soap request for your service l.jpg
A SOAP request for your service

<?xml version="1.0" encoding="UTF-8" ?>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

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

<soapenv:Body>

<kgtopounds xmlns="weightconverter">

<param0>50</param0>

</kgtopounds>

</soapenv:Body>

</soapenv:Envelope>

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


A soap request for your service tcpmon l.jpg
A SOAP request for your service: TCPMon

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


An http request for your service l.jpg
An HTTP request for your service

http://localhost:8080/axis2/services/WeightConverter/kgtopounds?param0=50

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


An http request for your service20 l.jpg
An HTTP request for your service

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns


Code and archive generator plug ins for eclipse l.jpg
Code and Archive Generator Plug-Ins for Eclipse

http://ws.apache.org/axis2/tools/index.html

Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns