Skip to content

Commit

Permalink
First cut at addressing issue #466 (support for legacy decoding only,…
Browse files Browse the repository at this point in the history
… not for encoding).
  • Loading branch information
greg-dove committed Oct 16, 2019
1 parent 21c2cdf commit 53a001e
Show file tree
Hide file tree
Showing 4 changed files with 373 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ package mx.rpc.http
import mx.rpc.Fault;
import mx.rpc.events.FaultEvent;
import mx.rpc.mxml.Concurrency;
import mx.rpc.xml.SimpleXMLDecoder;
import mx.utils.ObjectProxy;
import mx.utils.ObjectUtil;
import mx.utils.StringUtil;
Expand Down Expand Up @@ -1037,79 +1038,81 @@ package mx.rpc.http
{
if (/*resultFormat == RESULT_FORMAT_XML || */resultFormat == RESULT_FORMAT_OBJECT
|| resultFormat == RESULT_FORMAT_ARRAY)
{/*
//old XML style
var tmp:Object = new XMLDocument();
XMLDocument(tmp).ignoreWhite = true;
try
{
XMLDocument(tmp).parseXML(String(body));
}
catch(parseError:Error)
{
var fault:Fault = new Fault(ERROR_DECODING, parseError.message);
dispatchRpcEvent(FaultEvent.createEvent(fault, token, message));
return false;
}
if (resultFormat == RESULT_FORMAT_OBJECT || resultFormat == RESULT_FORMAT_ARRAY)
{
var decoded:Object;
var msg:String;
if (xmlDecode != null)
{
decoded = xmlDecode(tmp);
if (decoded == null)
{
msg = resourceManager.getString(
"rpc", "xmlDecodeReturnNull");
var fault1:Fault = new Fault(ERROR_DECODING, msg);
dispatchRpcEvent(FaultEvent.createEvent(fault1, token, message));
}
}
else
{
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(makeObjectsBindable);
decoded = decoder.decodeXML(XMLNode(tmp));
if (decoded == null)
{
msg = resourceManager.getString(
"rpc", "defaultDecoderFailed");
var fault2:Fault = new Fault(ERROR_DECODING, msg);
dispatchRpcEvent(FaultEvent.createEvent(fault2, token, message));
}
}
if (decoded == null)
{
return false;
}
{

if (makeObjectsBindable && (getQualifiedClassName(decoded) == "Object"))
{
decoded = new ObjectProxy(decoded);
}
else
try{
var temp:XMLList = new XMLList(String(body));
var tmp:XML = new XML('<root>'+temp.toXMLString()+'</root>');
} catch(parseError:Error)
{
decoded = decoded;
var fault:Fault = new Fault(ERROR_DECODING, parseError.message);
dispatchRpcEvent(FaultEvent.createEvent(fault, token, message));
return false;
}
if (resultFormat == RESULT_FORMAT_ARRAY)
if (resultFormat == RESULT_FORMAT_OBJECT || resultFormat == RESULT_FORMAT_ARRAY)
{
decoded = decodeArray(decoded);
}
_result = decoded;
var decoded:Object;
var msg:String;
if (xmlDecode != null)
{
decoded = xmlDecode(tmp);
if (decoded == null)
{
/*msg = resourceManager.getString(
"rpc", "xmlDecodeReturnNull");*/
msg = 'XMLDecode returned null';
var fault1:Fault = new Fault(ERROR_DECODING, msg);
dispatchRpcEvent(FaultEvent.createEvent(fault1, token, message));
}
}
else
{
var decoder:SimpleXMLDecoder = new SimpleXMLDecoder(makeObjectsBindable);

decoded = decoder.decodeXML(tmp);

if (decoded == null)
{
/*msg = resourceManager.getString(
"rpc", "defaultDecoderFailed");*/
msg = "defaultDecoderFailed";

var fault2:Fault = new Fault(ERROR_DECODING, msg);
dispatchRpcEvent(FaultEvent.createEvent(fault2, token, message));
}
}

if (decoded == null)
{
return false;
}

if (makeObjectsBindable && false /*(getQualifiedClassName(decoded) == "Object")*/)
{
decoded = new ObjectProxy(decoded);
}
else
{
decoded = decoded;
}

if (resultFormat == RESULT_FORMAT_ARRAY)
{
decoded = decodeArray(decoded);
}

_result = decoded;
}
else
/*else
{
if (tmp.childNodes.length == 1)
{
tmp = tmp.firstChild;
}
_result = tmp;
if (tmp.children().length() == 1)
{
tmp = tmp.children()[0];
}
// key difference here is that it will also be E4X:
_result = tmp;
}*/

}
else if (resultFormat == RESULT_FORMAT_E4X)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////////////////////////
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership.
// The ASF licenses this file to You under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

package mx.rpc.xml
{

[ExcludeClass]

/**
* This internal utility class is used by SimpleXMLDecoder. The class is
* basically a dynamic version of the String class (other properties can be
* attached to it).
*
* When you try to get the value of a ComplexString, we attempt to convert the
* value to a number or boolean before returning it.
*
* @private
*/
internal dynamic class ComplexString
{
public var value:String;

public function ComplexString(val:String)
{
super();
value = val;
}

public function toString():String
{
return value;
}

COMPILE::JS {override}
public function valueOf():*
{
return SimpleXMLDecoder.simpleType(value);
}
}

}
Loading

0 comments on commit 53a001e

Please sign in to comment.