summaryrefslogtreecommitdiff
path: root/fs_selfservice
diff options
context:
space:
mode:
authorjeff <jeff>2008-10-21 15:50:39 +0000
committerjeff <jeff>2008-10-21 15:50:39 +0000
commit1abd1d374114f36a1f2550a40a374b9fd4589292 (patch)
tree1668c1bd25e7906de2da12cd189380c452c82981 /fs_selfservice
parentbeab5e8857fa4961c22c7ccc49c9fea333c593a7 (diff)
biz.freeside.SelfService class and sample applications
Diffstat (limited to 'fs_selfservice')
-rwxr-xr-xfs_selfservice/java/biz/freeside/SelfService.java52
-rwxr-xr-xfs_selfservice/java/freeside_login_example.java45
-rwxr-xr-xfs_selfservice/java/freeside_signup_example.java69
3 files changed, 166 insertions, 0 deletions
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 ));
+ }
+}
diff --git a/fs_selfservice/java/freeside_login_example.java b/fs_selfservice/java/freeside_login_example.java
new file mode 100755
index 000000000..cb6d2bcac
--- /dev/null
+++ b/fs_selfservice/java/freeside_login_example.java
@@ -0,0 +1,45 @@
+
+import biz.freeside.SelfService;
+import org.apache.commons.logging.impl.SimpleLog; //included in apache xmlrpc
+import java.util.HashMap;
+import java.util.Vector;
+
+public class freeside_login_example {
+ private static SimpleLog logger = new SimpleLog("SelfService");
+
+ public static void main( String args[] ) throws Exception {
+ SelfService client =
+ new SelfService( "http://192.168.1.221:8081/xmlrpc.cgi" );
+
+ Vector params = new Vector();
+ params.addElement( "username" );
+ params.addElement( "testuser" );
+ params.addElement( "domain" );
+ params.addElement( "example.com" );
+ params.addElement( "password" );
+ params.addElement( "testpass" );
+ HashMap result = client.execute( "login", params );
+
+ String error = (String) result.get("error");
+
+ if (error.length() < 1) {
+
+ // successful login
+
+ String sessionId = (String) result.get("session_id");
+
+ logger.trace("[login] logged into freeside with session_id="+sessionId);
+
+ // store session id in your session store to be used for other calls
+
+ }else{
+
+ // successful login
+
+ logger.warn("[login] error logging into freeside: "+error);
+
+ // display error message to user
+
+ }
+ }
+}
diff --git a/fs_selfservice/java/freeside_signup_example.java b/fs_selfservice/java/freeside_signup_example.java
new file mode 100755
index 000000000..6c695c445
--- /dev/null
+++ b/fs_selfservice/java/freeside_signup_example.java
@@ -0,0 +1,69 @@
+
+import biz.freeside.SelfService;
+import org.apache.commons.logging.impl.SimpleLog; // included in apache xmlrpc
+import java.util.HashMap;
+import java.util.Vector;
+
+public class freeside_signup_example {
+ private static SimpleLog logger = new SimpleLog("SelfService");
+
+ public static void main( String args[] ) throws Exception {
+ SelfService client =
+ new SelfService( "http://192.168.1.221:8081/xmlrpc.cgi" );
+
+ Vector params = new Vector();
+ params.addElement( "first" );
+ params.addElement( "Test" );
+ params.addElement( "last" );
+ params.addElement( "User" );
+ params.addElement( "address1");
+ params.addElement( "123 Test Street" );
+ params.addElement( "address2");
+ params.addElement( "Suite A" );
+ params.addElement( "city");
+ params.addElement( "Testville" );
+ params.addElement( "state");
+ params.addElement( "OH" );
+ params.addElement( "zip");
+ params.addElement( "44632" );
+ params.addElement( "country");
+ params.addElement( "US" );
+ params.addElement( "daytime" );
+ params.addElement( "216-412-1234" );
+ params.addElement( "fax" );
+ params.addElement( "216-412-1235" );
+ params.addElement( "payby" );
+ params.addElement( "BILL" );
+ params.addElement( "invoicing_list" );
+ params.addElement( "test@test.example.com" );
+ params.addElement( "pkgpart" );
+ params.addElement( "101" );
+ params.addElement( "popnum" );
+ params.addElement( "4018" );
+ params.addElement( "username" );
+ params.addElement( "testy" );
+ params.addElement( "_password" );
+ params.addElement( "tester" );
+ HashMap result = client.execute( "new_customer", params );
+
+ String error = (String) result.get("error");
+
+ if (error.length() < 1) {
+
+ // successful signup
+
+ String custnum = (String) result.get("custnum");
+
+ logger.trace("[new_customer] signup with custnum "+custnum);
+
+ }else{
+
+ // unsuccessful signup
+
+ logger.warn("[new_customer] signup error: "+error);
+
+ // display error message to user
+
+ }
+ }
+}