Developer Forums | About Us | Site Map
Search  
HOME > TUTORIALS > SERVER SIDE CODING > ADMINISTRATION TUTORIALS > UNDERSTANDING QUALITY OF SERVICE FOR WEB SERVICES


Sponsors





Useful Lists

Web Host
site hosted by netplex

Online Manuals

Understanding quality of service for Web services
By Anbazhagan Mani & Arun Nagarajan - 2003-12-26 Page:  1 2 3 4 5 6 7 8 9

A simple method to measure response time of your Web services

Web Services ToolKit proxygen
The Service Proxy Generator tool can be used to create a client proxy that can interact with a Web service. This tool inspects a WSDL document and generates the Java programming language classes that can be used to invoke a Web service. This tool was a part of the WSDL Toolkit. This tool can be run by using the proxygen command. This command is located in the WSTK_HOME/bin directory. This command has one required input parameter. This parameter is the filename of the WSDL service description document.

A simple method to measure the performance characteristics of your Web services can be developed by adding a little bit of extra functionality in the service proxy. Service proxies in Web services are similar to stubs in Java RMI. They contain the code that is specific to a binding within the service interface, thereby hiding the complex network communications details from the client. For example, if the binding is a SOAP binding, then the service proxy will contain SOAP-specific code that can be used by the client to invoke the service.

The steps involved in developing a proxy capable of measuring response time is as follows:

  1. Generate service proxy from the WSDL service definition file.
  2. Modify the generated service proxy to add code to clock the time (see Listing 2).
  3. Re-compile the modified service proxy.
  4. Develop a client program to create a object of the service proxy and invoke the necessary methods .

Step 1: Generate a service proxy from service definition

Typically, service proxies are not written by the programmer. Service proxies can be easily generated from the WSDL file. Web Service Toolkits (including the alphaWorks WSTK) provide tools to generate service proxies (see the sidebar). A sample WSDL service definition for an EchoService is given in Listing 1. This is a simple Web service, which echos back the original string with "Hello" appended to it.


<?xml version="1.0" encoding="UTF-8"?>
<definitions name="EchoService"
  targetNamespace="http://www.echoserviceservice.com/EchoService-interface"
  xmlns="http://schemas.xmlsoap.org/wsdl/"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  xmlns:tns="http://www.echoserviceservice.com/EchoService"
    xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<message name="InechoRequest">

  <part name="meth1_inType1" type="xsd:string"/>
</message>
<message name="OutechoResponse">
  <part name="meth1_outType" type="xsd:string"/>
</message>
<portType name="EchoService">
  <operation name="echo">

    <input message="InechoRequest"/>
    <output message="OutechoResponse"/>
  </operation>
</portType>
<binding name="EchoServiceBinding" type="EchoService">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="echo">

    <soap:operation soapAction="urn:echoservice-service"/>
    <input>
      <soap:body
          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
          namespace="urn:echoservice-service"
          use="encoded"/>
    </input>
    <output>
      <soap:body
          encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
          namespace="urn:echoservice-service" use="encoded"/>

    </output>
  </operation>
</binding>
<service
      name="EchoService">
  <documentation>IBM WSTK 2.0 generated service definition file</documentation>
  <port binding="EchoServiceBinding" name="EchoServicePort">

    <soap:address location="http://localhost:8080/soap/servlet/rpcrouter"/>
  </port>
</service>
</definitions>    

Step 2: Modify the generated service proxy

Even though the machine-generated Service Proxy code is not to be edited, let us slightly bend this rule by adding a few lines of code. These added lines instantiates a Timer object to measure the time it takes to bind to the server and invoke a method. This is illustrated in the sample code given in Listing 2.


import java.net.*;
import java.util.*;
import org.apache.soap.*;
import org.apache.soap.encoding.*;
import org.apache.soap.rpc.*;
import org.apache.soap.util.xml.*;

import mytimer.Timer;
public class EchoServiceProxy
{
  private Call call = new Call();
  private URL url = null;
  private String SOAPActionURI = "";
  private SOAPMappingRegistry smr = call.getSOAPMappingRegistry();
  public EchoServiceProxy() throws MalformedURLException
  {
    call.setTargetObjectURI("urn:echoservice-service");
    call.setEncodingStyleURI("http://schemas.xmlsoap.org/soap/encoding/");
    this.url = new URL("http://localhost:8080/soap/servlet/rpcrouter");
    this.SOAPActionURI = "urn:echoservice-service";
  }
  public synchronized void setEndPoint(URL url)
  {
    this.url = url;
  }
  public synchronized URL getEndPoint()
  {
    return url;
  }
  public synchronized java.lang.String echo
    (java.lang.String meth1_inType1) throws SOAPException
  {
    if (url == null)
    {
      throw new SOAPException(Constants.FAULT_CODE_CLIENT,
      "A URL must be specified via " +
      "EchoServiceProxy.setEndPoint(URL).");
    }
    call.setMethodName("echo");
    Vector params = new Vector();
    Parameter meth1_inType1Param = new Parameter("meth1_inType1",
      java.lang.String.class, meth1_inType1, null);
    params.addElement(meth1_inType1Param);
    call.setParams(params);

    // Start a Timer
    Timer timer = new Timer();
    timer.start();

    Response resp = call.invoke(url, SOAPActionURI);

    // Stop the Timer
    timer.stop();
    // Print the response time by calculating the difference
    System.out.println("Response Time = " + timer.getDifference());

    // Check the response.
    if (resp.generatedFault())
    {
      Fault fault = resp.getFault();
      throw new SOAPException(fault.getFaultCode(), fault.getFaultString());
    }
    else
    {
      Parameter retValue = resp.getReturnValue();
      return (java.lang.String)retValue.getValue();
    }
  }
}

Step 3: Re-compile the modified service proxy

The modified service proxy source file has to be recompiled simply by using javac command or by using any other compiler.

Step 4: Develop a client program

Develop a client application, which can use the service proxy to invoke the Web service. This could be a simple Java program or a AWT/Swing based Java GUI application.



View Understanding quality of service for Web services Discussion

Page:  1 2 3 4 5 6 7 8 9 Next Page: Conclusion

First published by IBM developerWorks


Copyright 2004-2024 GrindingGears.com. All rights reserved.
Article copyright and all rights retained by the author.