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- 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
Next, Axis2's Object Model
<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
[TOC]