Forum: Ruby on Rails SOAP::RPC::Driver encoding problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
30a8995b21cae8803ae22f207733b1de?d=identicon&s=25 Serge Savoie (seurdge)
on 2009-02-05 14:37
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 ;-)

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'?><com.lacapitale.commun.model.securite.dto.Utilisateur>
  <dateNaissance class='sql-date'>1980-12-12</dateNaissance>
  <codeUtilisateur>MACCENT99</codeUtilisateur>
  <nom>Ééâûôé</nom>
  <prenom>Ééâûôé</prenom>


Any helps appreciated !

Thx !

Serge Savoie
This topic is locked and can not be replied to.