Friday, February 29, 2008

Status Report for 02/13/2008 -- 02/27/2008

Progress

Implementation of one user registering and monitoring one sensor is done.

1. User interface

Now user can register and monitor any one of IUMSC sensors via application “CIMA Sensor Monitor” .

(1) Choose a sensor name, which is a CIMA service data source name, e.g “Bay1 Temperature”, from one of twelve IUMSC sensors;

(2) Type a data interval, which is CIMA service data reporting interval in seconds;

(3) Click button “Register”;

(4) After getting response from server “Successfully registered some sensor”, type a Monitor Rate, which is the frequency in seconds the user wants to send the polling requests to the server, and then click button “Monitor”, the most recent data will be shown on the screen continuously.

2. Implementation

(1) Client side[3]

Prototype provides a number of easy ways to make asynchronous requests via Ajax. We are using Ajax.Request class to register a sensor and Ajax.PeriodicalUpdater class to poll a periodical request to get the new real time data.

new Ajax.Request(

"httpcimagateway.jsp?type="+encodeURI(type)+"&"+"source="+encodeURI(source)+"&"+"dataInterval="+encodeURI(dataInterval),

{

method:"get",

onComplete:function(xhr){

document.getElementById('fileUrl').value=xhr.responseText;

}

onFailure: function(xhr){

throw new Error('Registration failed: ' + xhr.statusText);

}

}

);

The asynchronous request itself is triggered by constructing a new instance of Ajax.Request, passing two parameters: the URL for the request, and a hash object containing properties that specify the options of the request. The URL specifies a JSP file that we will start CIMA service and register a sensor, and it passed the value of parcel type, CIMA service data source and CIMA service data reporting interval. In the options parameters object, we specify the HTTP method as a GET with the method property, and provide function reference for completion and failure handlers with onComplete and onFailure, respectively.

The completion handler is just to get the URL of the file which stores the data of the registed sensor. The failure handler, which is passed a reference to the XHR instance, throws an error depicting the failure status.

new Ajax.PeriodicalUpdater({success: 'details'}, fileUrl,

{

method: 'get',

frequency: monitorRate,

decay: 2,

onSuccess:function(xhr) {

eval(xhr.responseText);

}

}

);

This class can satisfy our needs to obtain and display data from the server at periodic intervals. First, we create an instance of Ajax.PeriodicalUpdater that refers to a new JSP page in the request URL(Note: for simplicity, currently this URL is just a file containing sensor data and this will be improved in next step). Second, frequency property in the parameters object controls the number of seconds between updates, and decay property controls the rate at which the request interval grows when the response is unchanged.

(2) Server side

  • httpcimagateway.jsp

a. Handle HTTP request from the client;

b. If the parameter check passes, then do the service in the request, e.g. Register/Unregister/……

c. Return the URL of the file which contains the data

  • do_Register
    • Set up the embedded axis server and client listener;
    • Set up the call to the CIMA service;
    • Invoke the service
  • do_Unregister

The procedure is similar with do_Register.

Discussion & Future work

  1. Change the storage of the data from file to queue;
  2. One user can register and monitor multiple sensors;

According to the requirement, users are allowed to

(a) register the different sensors, and/or

(b) register the same sensor with different data interval.

For one user, all registered sensors’ data will come to the same port, so

for (a), we only need to filter different data to different requests based on different sensors’ name, and this can be done easily; But

for (b), the current web service just outputs the “pure” data without any extra information to web service client. So the client cannot tell which data (parcel) belongs to which registration request.

  1. The problem with the interface of unregistering a sensor

Reference

[1] JSP : the complete reference. Hanna, Phil.

[2] Core servlets and JavaServer pages. Hall, Marty; Brown, Larry

[3] Ajax in practice Crane, Dave.

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