views:

85

answers:

2

I want to compress XML in Flex, send it to Java, decompress it in Java and recompress it in Java, resend it to Flex, decompress it and use it. How to do please ? thnx

+3  A: 

Just use an AMF Gateway which is a binary format and gives much smaller transfer sizes for your data.

Look into BlazeDS and/or LiveCycle. I believe it is possible to send XML over an AMF Gateway, although most of hte time I take advantage of the built in "Backend Object to AS Object" translation,

www.Flextras.com
Hello, thnx a lotIn this project, we are using LCDS (Im not a Flex coder, I'm java developer).But we are using RemoteObject in Flex side, so that we send directly XML.Is it already compressed ? because the size of the XML is realy important, so if we can compress it more, it will go faster.
taichimaro
If you are using Remote Objects, what Jeff wrote above is correct. It gets transformed into Binary which is much faster than sending the XML directly. You haven't got any work to do here.
Gregor Kiddie
The RemoteObject tag needs an AMF Gateway on the server; so you're probably built into LiveCycle. So, that's good. AMF is a binary format. I assume they use compression, but I don't know. XML is often lengthy, so I suspect you may minimize size by moving from XML into Value Objects.
www.Flextras.com
But if I compress the XML before sending it ? it will be better ?? don't you think so ??thnx for your responses it's really nice :)
taichimaro
You'll have to experiment to figure it out. When I compress compressed files they oftn increase the size. Even if you can make the 'transfer' size smaller, will those saved bites make up for the time it takes to compress / uncompress the data before it can be used?
www.Flextras.com
umm but, suppose that my server is strong, but bandwith isn't ? what will be the best ??Do you have an example of compress/decompress in Flex and Java ?I'll do a benchmark, and see what happenthnx a lot
taichimaro
Don't forget you'll have to compress/decompress on the client too; which will most likely have less processing power than your server. I don't know of anyone trying to do what you're asking. You'll need to find compression algorithms for flex/Java, implement, and benchmark. You might check out ASCrypt3 and/or the Crypto library, although they are focused on encryption not compression. I'm not sure of any Flex compression implementations.
www.Flextras.com
Putting XML strings in RemoteObjects negates the benefits of AMF. Either leave stuff as objects or use HTTPService instead of RemoteObject. For encryption over the wire use https.
James Ward
James, thanks for the clarification. I didn't know for sure how the AMF Gateway worked w/ XML. For completeness, I mentioned he encryption libraries because I Was pretty sure one or both had some compression utilities built in. (LZW is in ASCrypt3 )
www.Flextras.com
There is a deflate method on ByteArray that could be used to manually compress something (AMF, XML, whatever) in AS3. But that is just too much pain since http already supports gzip encoding.
James Ward
Wow ! Thanx for your AWSOME answers !!For the RemoteObject : in this project, we have some special modifications to use on the XML transfered by the Client, re-send the new XML to a CGI (the old architecture was Flex -> CGI, now it's Flex -> Java -> CGI ). This is why we use RemoteObject.
taichimaro
+1  A: 

Just turn on gzip in your server. Then requests and responses will be automatically gzipped across the wire. In Tomcat add the compression property to the server config, like:

<Connector protocol="HTTP/1.1" port="8080" connectionTimeout="20000"
    redirectPort="8443" compression="force" maxThreads="500"
    minSpareThreads="100" maxSpareThreads="75"/>
James Ward
and can this compress an HTTP request sent from Java to my CGI ????
taichimaro
This will compress every HTTP response from the server. The client / browser determines whether to send compressed data to the server.
James Ward