1 / 21

Creating a Web Service Using Apache Axis2

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.

Gabriel
Download Presentation

Creating a Web Service Using Apache Axis2

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

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

  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  6. 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

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

  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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"); } Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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 kg*2.20462262;} Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  11. 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

  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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(kg*2.20462262);       return result; } Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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) Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  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 Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  17. 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

  18. A SOAP request for your service: TCPMon Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  19. 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

  20. An HTTP request for your service Service-Oriented Computing: Semantics, Processes, Agents - Munindar Singh and Michael Huhns

  21. 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

More Related