From 1abd1d374114f36a1f2550a40a374b9fd4589292 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 21 Oct 2008 15:50:39 +0000 Subject: biz.freeside.SelfService class and sample applications --- fs_selfservice/java/biz/freeside/SelfService.java | 52 +++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 fs_selfservice/java/biz/freeside/SelfService.java (limited to 'fs_selfservice/java/biz/freeside') diff --git a/fs_selfservice/java/biz/freeside/SelfService.java b/fs_selfservice/java/biz/freeside/SelfService.java new file mode 100755 index 000000000..752815a02 --- /dev/null +++ b/fs_selfservice/java/biz/freeside/SelfService.java @@ -0,0 +1,52 @@ +package biz.freeside; + +// see http://ws.apache.org/xmlrpc/client.html for these classes +import org.apache.xmlrpc.XmlRpcException; +import org.apache.xmlrpc.client.XmlRpcClient; +import org.apache.xmlrpc.client.XmlRpcClientConfig; +import org.apache.xmlrpc.client.XmlRpcClientConfigImpl; + +import java.util.HashMap; +import java.util.List; +import java.net.URL; + +public class SelfService extends XmlRpcClient { + + public SelfService( String url ) throws Exception { + super(); + XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl(); + config.setServerURL(new URL( url )); + this.setConfig(config); + } + + private String canonicalMethod ( String method ) { + String canonical = new String(method); + if (!canonical.startsWith( "FS.SelfService.XMLRPC." )) { + canonical = "FS.SelfService.XMLRPC." + canonical; + } + return canonical; + } + + private HashMap testResponse ( Object toTest ) throws XmlRpcException { + if (! ( toTest instanceof HashMap )) { + throw new XmlRpcException("expected HashMap but got" + toTest.getClass()); + } + return (HashMap) toTest; + } + + public HashMap execute( String method, List params ) throws XmlRpcException { + return testResponse(super.execute( canonicalMethod(method), params )); + } + + public HashMap execute( String method, Object[] params ) throws XmlRpcException { + return testResponse(super.execute( canonicalMethod(method), params )); + } + + public HashMap execute( XmlRpcClientConfig config, String method, List params ) throws XmlRpcException { + return testResponse(super.execute( config, canonicalMethod(method), params )); + } + + public HashMap execute( XmlRpcClientConfig config, String method, Object[] params ) throws XmlRpcException { + return testResponse(super.execute( config, canonicalMethod(method), params )); + } +} -- cgit v1.2.1