SOAP::RPC::Driver encoding problem


#1

Hi,

I have trouble setting a SOAP::RPC::Driver class encoding (for the
response) to utf-8. My response contains accentuated character that are
not ok without this. I dont understand why the mandatorychaset= method
doesnt do the trick so I’m looking for some lights here :wink:

Here is my driver class code :

require ‘sw/SecuriteServiceWeb’
require ‘sw/SecuriteServiceWebMappingRegistry’
require ‘soap/rpc/driver’

class SecuriteServiceServerPortType < ::soap::RPC::Driver

DefaultEndpointUrl = $props[RAILS_ENV][‘securite_sw_url’]
NsSecuriteServiceWeb = “SecuriteServiceWeb”

Methods = [
[ XSD::QName.new(NsSecuriteServiceWeb, “getUtilisateurXML”),
“”,
“getUtilisateurXML”,
[ [“in”, “codeApplication”, ["::soap::SOAPString"]],
[“in”, “certificat”, ["::soap::SOAPString"]],
[“retval”, “return”, ["::soap::SOAPString"]] ],
{ :request_style => :rpc, :request_use => :encoded,
:response_style => :rpc, :response_use => :encoded,
:faults => {} }
]
]

def initialize(endpoint_url = nil)
endpoint_url ||= DefaultEndpointUrl
super(endpoint_url, nil)
self.mapping_registry =
SecuriteServiceWebMappingRegistry::EncodedRegistry
self.literal_mapping_registry =
SecuriteServiceWebMappingRegistry::LiteralRegistry
init_methods
end

private

def init_methods
Methods.each do |definitions|
opt = definitions.last
if opt[:request_style] == :document
add_document_operation(*definitions)
else
add_rpc_operation(*definitions)
qname = definitions[0]
name = definitions[2]
if qname.name != name and qname.name.capitalize ==
name.capitalize
::soap::Mapping.define_singleton_method(self, qname.name) do
|*arg|
send(name, *arg)
end
end
end
end
end
end

And here is my call method :

def obtain_xml_element(tag)

  xml_element = nil

  require 'soap/soap'
  require 'sw/SecuriteServiceWebDriver'
  begin
    driver = SecuriteServiceServerPortType.new

#Why is this doest work ?
driver.mandatorycharset = ‘utf-8’

    data_xml = driver.getUtilisateurXML("CDI",

cookies[:certificat].to_s.split(’-’)[0].to_s)
data = REXML::Document.new(data_xml)

    if tag.is_a?(Array)
      xml_element = tag.collect {|t| REXML::XPath.first( data, t

).to_s}
else
xml_element = REXML::XPath.first( data, tag ).to_s
end

  rescue Exception => e
    logger.error $!, $@
    ExceptionNotifier.deliver_exception_notification(e, self,

request, {:xml_element => xml_element, :lacapitale_certificat =>
cookies[:lacapitale_certificat].to_s})

  ensure
    return xml_element
  end
end

Finally, the response looks like :

<?xml version='1.0' encoding='ISO-8859-1'?>

1980-12-12
MACCENT99
Ééâûôé
Ééâûôé

Any helps appreciated !

Thx !

Serge S.