Index: lams_common/src/flash/org/lamsfoundation/lams/common/comms/Communication.as =================================================================== diff -u -r274fababe44d98713888b5a4f6483e363f47af6a -rdc18fc1f7338d4df46a5ecfc113df0cd5f32b50c --- lams_common/src/flash/org/lamsfoundation/lams/common/comms/Communication.as (.../Communication.as) (revision 274fababe44d98713888b5a4f6483e363f47af6a) +++ lams_common/src/flash/org/lamsfoundation/lams/common/comms/Communication.as (.../Communication.as) (revision dc18fc1f7338d4df46a5ecfc113df0cd5f32b50c) @@ -11,10 +11,16 @@ */ class org.lamsfoundation.lams.common.comms.Communication { - private static var FRIENDLY_ERROR_CODE:Number = 1; //Server error codes + + + + + private static var FRIENDLY_ERROR_CODE:Number = 1; //Server error codes private static var SYSTEM_ERROR_CODE:Number = 2; private static var MAX_REQUESTS:Number = 20; //Maximum no of simultaneous requests + + private var _serverURL:String; private var ignoreWhite:Boolean; @@ -54,7 +60,11 @@ //Debugger.log('_serverURL:'+_serverURL,4,'Consturcutor','Communication'); wddx = new Wddx(); - } + } + + + + /** * Make a request to the server. Each request handlers is added to a queue whilst waiting for the (asynchronous) response @@ -94,7 +104,55 @@ } } + + + /** + * Sends a data object to the server and directs response to handler function. + * + * @param dto:Object The flash object to send. Will be WDDX serialised + * @param requestURL:String The url to send and load the data from + * @param handler:Function The function that will handle the response (usually an ACK response) + * @param isFullURL:Boolean Inicates if the requestURL is fully qualified, if false serverURL will be prepended + * + * @usage: + * + */ + public function sendAndReceive(rawDto:Object, requestURL:String,handler:Function,isFullURL){ + //denull the object first, stops the wddx processor on java side form barfing + + + //var dto:Object = ObjectUtils.deNull(rawDto); + + //Serialise the Data Transfer Object + var xmlToSend:XML = serializeObj(rawDto); + //xmlToSend.contentType="dave"; + + //Create XML response object + var responseXML = new XML(); + //Assign onLoad handler + responseXML.onLoad = Proxy.create(this,onServerResponse,queueID); + + //Assign onLoad handler + // responseXML.onLoad = Proxy.create(this,onSendACK,queueID); + //Add handler to queue + addToQueue(handler); + //Assign onData function + setOnData(responseXML); + + //TODO DI 11/04/05 Stub here for now until we have server implmenting new WDDX structure + if(isFullURL){ + Debugger.log('Posting to:'+requestURL,Debugger.GEN,'sendAndReceive','Communication'); + Debugger.log('Sending XML:'+xmlToSend.toString(),Debugger.GEN,'sendAndReceive','Communication'); + xmlToSend.sendAndLoad(requestURL,responseXML); + }else{ + Debugger.log('Posting to:'+_serverURL+requestURL,Debugger.GEN,'sendAndReceive','Communication'); + Debugger.log('Sending XML:'+xmlToSend.toString(),Debugger.GEN,'sendAndReceive','Communication'); + xmlToSend.sendAndLoad(_serverURL+requestURL,responseXML); + } + } + + /** * XML load handler for getRequest() * @param success XML load status * @param wrappedPacketXML The wrapped XML response object @@ -117,6 +175,8 @@ //Check for errors in message type that's returned from server if(responseObj.messageType == FRIENDLY_ERROR_CODE){ //user friendly error + var e = new LFError(responseObj.messageValue,"onServerResponse",this); + dispatchToHandlerByID(queueID,e); //showAlert("Oops", responseObj.body, "sad"); }else if(responseObj.messageType == SYSTEM_ERROR_CODE){ //showAlert("System error", "
Sorry there has been a system error, please try the operation again. If the problem persistes please contact support
Additional information:"+responseObj.body+"
", "sad"); @@ -138,48 +198,7 @@ } } - /** - * Sends a data object to the server and directs response to handler function. - * - * @param dto:Object The flash object to send. Will be WDDX serialised - * @param requestURL:String The url to send and load the data from - * @param handler:Function The function that will handle the response (usually an ACK response) - * @param isFullURL:Boolean Inicates if the requestURL is fully qualified, if false serverURL will be prepended - * - * @usage: - * - */ - public function sendAndReceive(dto:Object, requestURL:String,handler:Function,isFullURL){ - //Serialise the Data Transfer Object - var xmlToSend:XML = serializeObj(dto); - //xmlToSend.contentType="dave"; - - //Create XML response object - var responseXML = new XML(); - //Assign onLoad handler - responseXML.onLoad = Proxy.create(this,onServerResponse,queueID); - - //Assign onLoad handler - // responseXML.onLoad = Proxy.create(this,onSendACK,queueID); - //Add handler to queue - addToQueue(handler); - //Assign onData function - setOnData(responseXML); - - //TODO DI 11/04/05 Stub here for now until we have server implmenting new WDDX structure - if(isFullURL){ - Debugger.log('Posting to:'+requestURL,Debugger.GEN,'sendAndReceive','Communication'); - Debugger.log('Sending XML:'+xmlToSend.toString(),Debugger.GEN,'sendAndReceive','Communication'); - xmlToSend.sendAndLoad(requestURL,responseXML); - }else{ - Debugger.log('Posting to:'+_serverURL+requestURL,Debugger.GEN,'sendAndReceive','Communication'); - Debugger.log('Sending XML:'+xmlToSend.toString(),Debugger.GEN,'sendAndReceive','Communication'); - xmlToSend.sendAndLoad(_serverURL+requestURL,responseXML); - } - } - - /** * Received Acknowledgement from server, response to sendAndReceive() method * * @usage @@ -287,7 +306,9 @@ public function deserializeObj(xmlObj:XML):Object{ var dto:Object = wddx.deserialize(xmlObj); return dto; - } + } + + /** * Finds handler in queue, dispatches object to it and deletes item from queue