inicio mail me! sindicaci;ón

OpenLaszlo XML Workaround

As mentioned in my previous OpenLaszlo post, i had a problem whereby in SOLO mode my app would send the XML data to the server in urlencode format. This meant that my poor REST-based web service barfed up as this was in no way valid XML. Safe to say, i wasn’t best pleased.

Thankfully though, considering i am interfacing with my own web service, i can change how the server interacts with the request data all i want. So it’s pretty easy to work around this issue.

In the case of the Ruby on Rails framework i am using, the easiest way is to make a new mimetype handler which handles our standards hostile custom mimetype (which i promptly called “application/xml-urlencode”). Like so:


Mime::Type.register "application/xml-urlencode", :xml

ActionController::Base.param_parsers[Mime::Type.lookup(
'application/xml-urlencode')] = Proc.new do
|data|
decoded_data =  CGI::unescape(data) # Decode data
XmlSimple.xml_in(data, {'keeproot' => true,
'forcearray' => false}) # Parse decoded XML
end

And then all i have to do in my OpenLaszlo app is something along the lines of:


datasetForSending.setHeader("Content-Type", "application/xml-urlencode");

And hey presto, the data is now recognised!

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus