urgent computing topline

 

Sample Web Service Clients

  $Revision: 1.3 $


This page lists some example clients written to access our UserServices Suite using different software packages.

Table of Contents

Java Client using Axis2

This document presents a simple guide to generating a Java WS client for the Spruce web services. It makes use of Apache Axis2 SOAP Stack. From the Axis2 installation, you need to include the following jar files in your class path:
  • axiom-api-1.0.jar
  • axiom-impl-1.0.jar
  • axis2-kernel-1.0.jar
  • neethi-1.0.1.jar
  • stax-api-1.0.jar
  • wstx-asl-2.9.3.jar

Below is the code from the actual client:


import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class UserPortalClient {
        // End-Point Reference
        private static EndpointReference targetEPR = new EndpointReference(
  "http://spruce.uchicago.edu:8080/axis2/services/SpruceUserServices");

        public static void main(String[] args) {
              OMFactory fac = OMAbstractFactory.getOMFactory();
              OMNamespace omNs = fac.createOMNamespace
		("http://spruce.uchicago.edu/ws/xsd/", "spruce");

                /*
                 * test  checkTokenTime()
                 */
              OMElement method = fac.createOMElement("checkTokenTime", omNs);

                /*
                 * set token parameter -- needed for all method calls
                 */

              OMElement token = fac.createOMElement("token", omNs);
                token.addChild(fac.createOMText(token, "0000-0000-0000-0001"));
		 //expired token
              method.addChild(token);

              try {
                        Options options = new Options();
                        options.setTo(targetEPR);

                        // Blocking invocation.
                        ServiceClient sender = new ServiceClient();
                        sender.setOptions(options);
                        OMElement result = sender.sendReceive(method);

                        System.out.println(result);

              } catch (AxisFault axisFault) {
                      axisFault.printStackTrace();
             }
        }
}

The first step is to declare the endpoint reference (EPR). For the SPRUCE web services, this is currently http://spruce.uchicago.edu:8080/axis2/services/SpruceUserServices

Next, Axis2's Object Model (AXIOM) is used to generate the necessary XML for the call. This includes creating the parameter necessary for the call (in this case a 'token') and giving it a value. This parameter is attached as a child to an XML element that represents the method call (in this case, checkTokenTime()). Once the neccessary XML is created, the web service needs to be invoked. We use a Axis2's blocking invocation method, and print out the result. The execution produces the following results:


<spruce:SpruceFault xmlns:spruce="http://spruce.uchicago.edu/ws/xsd/ "
xmlns:tns="http://ws.apache.org/axis2">
     <spruce:code>2</spruce:code>
     <spruce:message>Token expired</spruce:message>
     <spruce:description>checkTokenTime::Token has expired</spruce:description>
</spruce:SpruceFault>

This is the correct return in this case, as the method is being invoked on an expired token, which returns a spruce error message.

[TOC]

Contact Information

Please contact Spruce Team for any questions or problems using Spruce software.

[TOC]