Flex HTTPService Resultformat - apache-flex

What is the real difference between these resultformats for HTTPService in Flex :
text
object
xml
e4x
Especially, the last three seem pretty close to each other by their description.

from the manual of HTTPService:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/http/HTTPService.html#resultFormat
object: The value returned is XML and is parsed as a tree of ActionScript objects. This is the default.
array: The value returned is XML and is parsed as a tree of ActionScript objects however if the top level object is not an Array, a new Array is created and the result set as the first item. If makeObjectsBindable is true then the Array will be wrapped in an ArrayCollection.
xml: The value returned is XML and is returned as literal XML in an ActionScript XMLnode object.
flashvars: The value returned is text containing name=value pairs separated by ampersands, which is parsed into an ActionScript object.
text: The value returned is text, and is left raw.
e4x: The value returned is XML and is returned as literal XML in an ActionScript XML object, which can be accessed using ECMAScript for XML (E4X) expressions.

The classtype of the returned object differs.
text => String
object => A generic object that you can use like a hash
e4x => an object of type XML
xml => I forget... a String?

I recently had some issues with the "object" and "e4x" resultFormat.
I have a base WebService Class that I use for sending requests and receiving results. By default, all results come back as "object". However, sometimes Flex looks at the data, and converts it to an appropriate type. For instance, if you have an XML result that looks like the following, it will convert it to an Array Object (not sure why...but...):
<root>
<child>text</child>
<child>text text</child>
</root>
Now, an Array Object like this can easily be cast as XML, since, as a string it is also XML.
However, some XML documents are returned as an ObjectProxy, which cannot be cast as XML, when the resultFormat is "object".
I tried using "e4x", as it was suggested here, but then I ran into problems with namespaces not being preserved correctly.
I finally tried "xml", and I am getting the expected results. It's interesting that when you inspect the event result property using the Flex Debugger, it is said to be an Array, even when you specify a resultFormat of "xml". I guess this allows for easily casting to ArrayCollection...not sure....

Related

extracting array of objects from xml response to js

so I'm extracting variables from my xml response and trying to reformat the objects but I want to do that the most efficient way possible. so I want to load the xml array of same objects into a js array that I can cycle thru and output the new format. I found a reference to type="nodeset" when extracting the XPath but i could not find a reference to it on the documentation.
what is the best way to load the full xml objects into a js variable and cycle thru the objects and output the new format
Thanks for any help you can give me on this.
Best way to accomplish this is with the XMLToJSON policy, a JavaScript callout in which you can mediate your payload, and then transform back with JSONToXML if you need it.
For an XML array that doesn't need filtering, you can use XPATH with type="nodeset", just as you described. This allows you to pull a node and all child nodes in a particular XPATH. As I'm sure you noticed, you can't do this by just extracting as type="string". Just know that you will need to convert the extracted variable to string before you can use the XML nodes like you do every other string. You can then do JSON.parse to take the string and manipulate the object like an array. The string conversion is as simple as calling a JS callout with the following code (if someone else has a better way, I'm all ears):
var extractedNodeSet = context.getVariable("extractedNodeSet");
var extractedNodeSetString = String(extractedNodeSet);
For an XML array that needs filtering/manipulation, I recommend to use XSLT along with the trusted <xsl:for-each select=...> element. This will let you set conditions on the XML array nodes, manipulate tags/data, and extract the data, all in one step. The only concern is that this isn't a JS array, so if you absolutely must have a JS array, then you'll need to then do an XMLtoJSON and work with the data from there.

What are the differences between getRawSomething and getSomething methods on Archetypes contents (eg. ATNewsItem)?

What are the differences between getRawSomething and getSomething methods on Archetypes contents (eg. ATNewsItem)?
For exemple, what is the difference between getRawImage and getImage? Or getRawRelatedItems and getRelatedItems? etc.
getRaw* gives you the direct, unprocessed raw data as stored on the object. The get* methods are allowed to transform that data in some way as needed.
For example, TextField fields will transform text to safe HTML when using get, but getRaw() gives you the untransformed data, be that markdown, restructuredtext or unprocessed HTML.
From the developer documentation:
Archetypes has two kinds of access methods:
normal, getSomething(), which filters output;
raw, the so-called edit accessor, getRawSomething() which does not filter output.
When you want to edit the current contents of a field, use getRaw*, when rendering the contents, use get*.
Specifically, related items are stored in a reference field, where the getRaw() method returns object UIDs, the get() method returns objects, having first resolved the UIDs for you.
Image fields, like file fields, will wrap the data in the associated object type (OFS.Image for image fields) if not already that type when using .get() but return whatever the underlying storage has got for .getRaw(). Usually the object is already wrapped though.

How can I check for a nil="true" value on XML that is passed back from webservice call?

I am receiving xml from a webservice call that contains a nil="true":
<cacheEntry>
<systemFK nil="true"/>
</cacheEntry>
I used the Flex DataService (webservice) wizard to create the service objects for the cacheEntry component. This object will be serialized later on a different webservice call and stored in a database.
I set a breakpoint on the set SystemFK method in the service object. It appears that the value passed in was an empty string!
Allowing this value to be an empty string will cause problems in the webservice implementation in Java on the other side. Since the database value was null it is expecting a null in return, If I avoid setting this value, the serviceObject should send back a null which will make the database happy.
My question is: How can I detect that a nil = true is present in the XML in order to avoid setting this value?
For some reason the ActionScript XML parsers don't know about Booleans. Without seeing the code that got generated for you, my guess is that somehow you're getting the string "true", instead of true, and that's what's causing your problem.
Make changes to the accessors to act as if #nil comes from the XML as a string, and then convert to Boolean manually.

XmlSerializer, deserializing time only into DateTime type

My WCF uses XmlSerializer to serialize and deserialize fairly complex objects. Problem is, the corresponding XML payload value of one of the DateTime properties could be specified as either xs:date, xs:time or xs:dateTime values. I've noticed that when a time-only value (e.g. 16:55:00Z) is specified in the input XML the current date gets 'prepended' during deserialization (e.g. 2010-12-13T16:55:00Z). This obviously creates false data, I would rather have preferred DateTime.MinValue.
Is there a way I can control this behavior?
Thanks in advance
We use WCFDate to send the date part as xs:date.
See http://www.codeproject.com/Articles/182960/WCF-Support-for-xs-date for code.

remote implementation for HTTPService in flex

In my flex application I am using httpService to connect to the server, for the response from server I wanted it to convert the http response to flex object, Is there any remote implementation availabe for the above purpose
to augment earlier post, it depends on what you are sending from the server side. If you are using HTTPService then it is ideally a XML document (RestFul style). Based on the result format set to the service object, flex tries to convert it to that type of result by mapping XML to other type of flex object. most useful result formats in this case would be object (default), e4x, xml. for more information you need to see ASDoc.
if the payload of your HTTP is custom object which is directly serialized on server side (not to xml), then it is pretty hard to re-construct that object on flex side.
IF you payload is String or any other format which you want to parse manually then set the result format to "text" which will return you a string and you can process it later.
If you want flex to automatically convert the result data from XML to object use:
<mx:HTTPService url="http://theserver.com"
resultFormat="object"/>
or in case you use only actionscript
var service:HTTPService;
service.resultFormat = "object";
This should be the default behaviour when no resultFormat is specified. You might also want to check the "array" result format as it behaves a bit different.
HttpService.resultFormat

Resources