Friday, February 29, 2008

Status Report for 01/30/2008 -- 02/13/2008

Progress

Based on my previous post, I found that invoking/starting a web service by using Axis1.4 API is not type safe, so I turned my work to newly introduced Axis2 for the project.

1. Brief introduction

Apache Axis2 is built on Apache AXIOM a new high performance, pull-based XML object model. Axis2 comes with many new features, enhancements and industry specification implementations. Axis 2 has five primary strengths: better performance, messaging support, synchronous support, better support for WS-extensions, and better deployment support. The strength of Axis 2 lies in the flexibility and the functionality that Axis 2 provides; migration can be justified for the cases where few of those functionalities are vital. Future articles will provide examples on using Axis 2.

2. A test Web Services via Apache Axis2 in Eclipse

We create a bottom up JAVA bean Web service and Web service client using Axis2 WTP Tools. It shows how to create a simple Web service and Web service client from a JAVA class. The JAVA class in this scenario converts between the Celsius and Fahrenheit temperature scales and its the same class that used in the Axis web services tutorials.

(1) Download the latest Axis2 runtime and extract it;

(2) Point Eclipse WTP to downloaded Axis2 Runtime;

(3) Create a project with the support of Axis2 feature;

(4) Select the Axis2 Web service facet;

(5) Import the wtp/Converter.java class into Axis2WSTest/src (be sure to preserve the package);

package wtp;
public class Converter {
  public float celsiusToFarenheit ( float celsius ){
    return (celsius * 9 / 5) + 32;
  }
 
  public float farenheitToCelsius ( float farenheit ){
    return (farenheit - 32) * 5 / 9;
  }
}

(6) Create a web service based on the above java class;

(7) Generate the client for the newly created service by referring the ?wsdl generated by the Axis2 Server;

(8) The Clients stubs will be generated to above Dynamic Web project;

(9) Write Java main program to invoke the client stub. Import the ConverterClient.java file to the workspace into the wtp package in the src folder of the web service client;

package wtp;
 
import java.rmi.RemoteException;
 
import org.apache.axis2.AxisFault;
 
import wtp.ConverterConverterSOAP11Port_httpStub.CelsiusToFarenheit;
import wtp.ConverterConverterSOAP11Port_httpStub.CelsiusToFarenheitResponse;
 
public class ConverterClient {
 
  public static void main(String[] args) {
    try {
      float celsiusValue = 100;
      ConverterConverterSOAP11Port_httpStub stub = new ConverterConverterSOAP11Port_httpStub();
      CelsiusToFarenheit c2f = new CelsiusToFarenheit();
      c2f.setCelsius(celsiusValue);
      CelsiusToFarenheitResponse res = stub.celsiusToFarenheit(c2f);
      System.out.println("Celsius : "+celsiusValue+" = "+"Farenheit : "+res.get_return());
    } catch (AxisFault e) {
      e.printStackTrace();
    } catch (RemoteException e) {
      e.printStackTrace();
    }
  }
}
 

Discussion

Now I am working on how to start a web service dynamically based on the feather of the project and the existing web service. I will state it in more detail later.

Reference

·         http://ws.apache.org/axis2/
·         http://www.developer.com/services/article.php/3525481
·         http://www.eclipse.org/webtools/jst/components/ws/1.0/tutorials/WebServiceExplorer/WebServiceExplorer.html
·         http://www.eclipse.org/webtools/community/tutorials/BottomUpAxis2WebService/bu_tutorial.html
·         http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/BottomUpWebService/BottomUpWebService.html
·         http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/TopDownWebService/TopDownWebService.html
·         http://www.eclipse.org/webtools/jst/components/ws/1.5/tutorials/WebServiceClient/WebServiceClient.html
 

No comments: