Hi,
I'm running ruby 1.9.2-p0 on Centos 5.5 x86_64 along with rails 2.3.8.
I have XMLRPC server on another windows machine (rails 1.9.1) and XMLRPC
client on the Centos machine. I need to return UTF-8 encoded data from
server to client and this is where I'm stuck.
The Server seems to be sending correct UTF-8 encoded data, bud client is
unable to parse the XML. If the XML contains ASCII only strings,
everything's OK, but once there is any multi-byte UTF-8 character, ruby
bails out and outputs this:
There seems to be something wrong with REXML non-ASCII data parsing or
maybe encoding detection. I've tracked it down to the "match" method in
IOSource wrapper class in rexml/source.rb file. The problem seems to be
that the @buffer which the method matches against contains ASCII-8bit
string sometimes. Strangely, it happens only when it contains some
non-ASCII data. If there are only ASCII characters in @buffer, it
happily proceeds as UTF-8.
BTW, my client script looks like this:
----------------------
module SubmitFilesHelper
def self.sendToServer(filename,language)
require 'xmlrpc/client'
server = XMLRPC::Client.new2(@rpc_server_url)
result = server.call('check', filename,language)
end
end
----------------------
Centos has locale set to en_us.UTF-8
Is there anything I'm doing wrong, or is it ruby bug?
Hm, it's possible to encode the offending string to base64 before
handing it to xmlrpc, effectively bypassing any ruby 1.9 encoding
awareness. Not exactly what I would like to see...
Anyway, is there a correct solution to my problem? Base64 encoding is
working solution, but not correct as I'm manually bypassing a language
feature worth having.
In <77a0ce708f3cb00f79bcc1b13733c71b@ruby-forum.com>
"XMLRPC (REXML) incorrectly handles UTF-8 data" on Tue, 16 Nov 2010 23:37:48 +0900,
···
Petr Klima <petr.klima@avg.com> wrote:
I have XMLRPC server on another windows machine (rails 1.9.1) and XMLRPC
client on the Centos machine. I need to return UTF-8 encoded data from
server to client and this is where I'm stuck.
The Server seems to be sending correct UTF-8 encoded data, bud client is
unable to parse the XML. If the XML contains ASCII only strings,
everything's OK, but once there is any multi-byte UTF-8 character, ruby
bails out and outputs this:
Could you show us a reproducable example? We need at least
the HTTP response header and the XML response from your
XML-RPC server.
XML response (should be one line):
---------------
<?xml version="1.0"
?><methodResponse><params><param><value><struct><member><name>result</name><value><string>ok
</string></value></member><member><name>program_ver</name><value><string>10.0.1153</string></value></member><member><na
Damn, I have seen this before and I would swear I tried it and it didn't
help (I was using 1.9.1 at the time). Hm, probably somehow slipped
between my fingers. Thanks a lot, works now
def self.sendToServer(filename,language)
require 'xmlrpc/client'
server = XMLRPC::Client.new2(@rpc_server_url)
server.extend(XMLRPCWorkAround)
result = server.call('check', filename,language)
end
end