diff --git a/webservice/amf/testclient/AMFConnector.as b/webservice/amf/testclient/AMFConnector.as deleted file mode 100644 index 036040a3f0f..00000000000 --- a/webservice/amf/testclient/AMFConnector.as +++ /dev/null @@ -1,63 +0,0 @@ -package { - - import flash.events.Event; - import flash.net.NetConnection; - import flash.net.Responder; - - import nl.demonsters.debugger.MonsterDebugger; - - /** - * Wrapper class for the NetConnection/Responder instances - * - * This program is free software. It comes without any warranty, to - * the extent permitted by applicable law. You can redistribute it - * and/or modify it under the terms of the Do What The Fuck You Want - * To Public License, Version 2, as published by Sam Hocevar. See - * http://sam.zoy.org/wtfpl/COPYING for more details. - * - * @author Jordi Boggiano - */ - public class AMFConnector extends NetConnection { - private var responder:Responder; - public var data:Object; - public var error:Boolean = false; - - public function AMFConnector(url:String) { - responder = new Responder(onSuccess, onError); - connect(url); - } - - /** - * executes a command on the remote server, passing all the given arguments along - */ - public function exec(command:String, args:Array = null):void - { - if (args == null) args = []; - args.unshift(responder); - args.unshift(command); - (call as Function).apply(this, args); - } - - /** - * handles success - */ - protected function onSuccess(result:Object):void { - MonsterDebugger.trace(this, {'result':result}); - data = result; - dispatchEvent(new Event(Event.COMPLETE)); - data = null; - } - - /** - * handles errors - */ - protected function onError(result:Object):void { - data = result; - MonsterDebugger.trace(this, {'result':result}); - error = true; - dispatchEvent(new Event(Event.COMPLETE)); - error = false; - data = null; - } - } -} \ No newline at end of file diff --git a/webservice/amf/testclient/AMFTester.mxml b/webservice/amf/testclient/AMFTester.mxml index deef8ec8a2d..ce1f4f4ca69 100644 --- a/webservice/amf/testclient/AMFTester.mxml +++ b/webservice/amf/testclient/AMFTester.mxml @@ -2,7 +2,7 @@ + * @author Jamie Pratt */ import mx.controls.Label; @@ -33,12 +39,16 @@ // Import the debugger // import nl.demonsters.debugger.MonsterDebugger; - public var api:AMFConnector; protected var methods:Array; protected var introspector:String; public var rooturl:String; + [Bindable] + public var serviceurl:String; + + public var channel:AMFChannel; + [Bindable] public var argumentToolTip:String = "You can use JSON syntax for method arguments ie. an array is written like this [item1, item2, etc.] objects are written {\"propname\":value, \"propname2\":value2, etc}"; @@ -76,9 +86,9 @@ } public function doConnectToken():void { - var url:String = this.rooturl + '/webservice/amf/server.php?'+ + serviceurl = this.rooturl + '/webservice/amf/server.php?'+ 'wstoken='+this.token.text; - this.doConnect(url); + this.doConnect(); // saving settings for next time var so:SharedObject = SharedObject.getLocal('AMFTester'); if (this.rememberpassword.selected == true ){ @@ -92,10 +102,10 @@ } public function doConnectUsername():void { - var url:String = this.rooturl + '/webservice/amf/simpleserver.php?'+ + serviceurl = this.rooturl + '/webservice/amf/simpleserver.php?'+ 'wsusername=' + this.username.text+ '&wspassword=' + this.password.text; - this.doConnect(url); + this.doConnect(); // saving settings for next time var so:SharedObject = SharedObject.getLocal('AMFTester'); if (this.rememberpassword.selected == true ){ @@ -113,15 +123,16 @@ /** * initializes the connection */ - private function doConnect(url:String):void + private function doConnect():void { - api = new AMFConnector(url); - api.exec('MethodDescriptor.getMethods'); - api.addEventListener(Event.COMPLETE, handleConnection); - if (!api.hasEventListener(NetStatusEvent.NET_STATUS)) { - api.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); - api.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); - api.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); + push("Connecting to "+serviceurl); + //api.source = 'MethodDescriptor'; + api.setCredentials(this.username.text, this.password.text); + api.removeEventListener("result", outputResult); + api.addEventListener("result", handleConnection); + api.getOperation("MethodDescriptor.getMethods").send(); + if (!api.hasEventListener("fault")) { + api.addEventListener("fault", faultHandler); } this.panelDebug.enabled = false; } @@ -129,12 +140,12 @@ /** * initializes the debugger dialog with the method list and everything */ - protected function handleConnection(event:Event):void + protected function handleConnection(event:ResultEvent):void { methods = []; - for (var cls:String in api.data) { - for (var meth:String in api.data[cls]['methods']) { - methods.push({label: cls+'.'+meth, docs: api.data[cls]['methods'][meth]['docs'], args: api.data[cls]['methods'][meth]['params']}); + for (var cls:String in event.result) { + for (var meth:String in event.result[cls]['methods']) { + methods.push({label: cls+'.'+meth, docs: event.result[cls]['methods'][meth]['docs'], args: event.result[cls]['methods'][meth]['params']}); } } methods.sortOn('label', Array.CASEINSENSITIVE); @@ -142,8 +153,8 @@ this.panelDebug.enabled = true; this.maintabs.selectedIndex = 1; func.dataProvider = methods; - api.removeEventListener(Event.COMPLETE, handleConnection); - api.addEventListener(Event.COMPLETE, process); + api.removeEventListener("result", handleConnection); + api.addEventListener("result", outputResult); reloadArgs(); } @@ -152,19 +163,53 @@ /** * outputs a response from the server */ - protected function process(event:Event):void + protected function outputResult(event:ResultEvent):void { - if (api.error) { - var keys:String = ''; - for (var key:String in api.data){ - keys += key+' '; - } - push(output, time() + ": Exception (code: "+api.data.code+", description: "+api.data.description+" (line: "+api.data.line+") detail:\n "+api.data.detail+")\n"); - } else { - push(output, time() + ": "+JSON.encode(api.data)+"\n"); + var keys:Array = new Array(); + for (var key:String in event.result){ + keys.push(key); } -// MonsterDebugger.trace(this, {"data":api.data, "error":api.error}); -// MonsterDebugger.trace(this, api.data); + push("Result returned \n" + obj2string(event.result)); + } + + protected function obj2string(obj:Object, depth:Number=0):String{ + var string:String = ''; + if (obj==null){ + return 'NULL'; + } + switch (typeof(obj)){ + case 'object': + if (obj is Array){ + string += "Array\n"; + } else { + string += "Object\n"; + } + string += depth2string(depth+1)+"(\n"; + for (var key:String in obj){ + string += depth2string(depth+2)+'['+key+'] => '+obj2string(obj[key], depth+3); + } + string += depth2string(depth+1)+")\n"; + break; + case 'string': + var formattedstring:String = obj.toString(); + formattedstring = formattedstring.replace(/\r/g, ""); + formattedstring = formattedstring.replace(/\n/g, "\n"+depth2string(depth+3)); + string += '"'+formattedstring+'"'+"-("+typeof(obj)+")"+"\n"; + break; + default : + string += obj.toString()+"-("+typeof(obj)+")"+"\n"; + } + return string; + } + + protected function depth2string(depth:Number):String{ + var string:String = ''; + var i:Number = 0; + while (i + + @@ -345,96 +413,100 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/webservice/amf/testclient/AMFTester.swf b/webservice/amf/testclient/AMFTester.swf index e7c9443dbbe..aceb09084f9 100644 Binary files a/webservice/amf/testclient/AMFTester.swf and b/webservice/amf/testclient/AMFTester.swf differ diff --git a/webservice/amf/testclient/flashcompilationinstructions.txt b/webservice/amf/testclient/flashcompilationinstructions.txt index b82c6eed6cc..d788f170927 100644 --- a/webservice/amf/testclient/flashcompilationinstructions.txt +++ b/webservice/amf/testclient/flashcompilationinstructions.txt @@ -3,7 +3,6 @@ AMFTester.mxml can be compiled as a Flex application in Flex builder or using th Copy the following into a Flex project source folder : * customValidators folder and contents -* AMFConnector.as * AMFTester.mxml Then you need to use either the compiled Flex library or the source for the open source library as3corelib available here : http://code.google.com/p/as3corelib/downloads/list