Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case problem in SOAP message tag names using savon

I'm using Ruby 1.9.2 with savon 0.9.2 on Windows 7 Professional 64 bit.

I need to call a web SOAP service that requires a security token that I get from a second web SOAP service. The code I use is as follows:

require 'savon'

client = Savon::Client.new "http://some.url?wsdl"
client.wsdl.soap_actions

start_session_response = client.request :start_session do
  soap.input = ["StartSession", {:xmlns => "http://some.schema" } ]
  soap.body = { :userName => "User", :password => "password" }
end

do_something_response = client.request :do_something do
  soap.input = [ "DoSomething", { :xmlns => "http://some.schema"} ]
  soap.body = { :securityToken => start_session_response.to_hash[:start_session_response][:security_token] }
end

This results in XML that looks like:

<?xml version="1.0" encoding="utf-8"?>
<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://some.schema"
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
  <env:Body>
    <DoSomething xmlns="http://some.schema">
      <wsdl:securityToken>
        <wsdl:tokenType>sessiontoken</wsdl:tokenType>
        <wsdl:token>
         .
        .
        .
        </wsdl:token>
      </wsdl:securityToken>
    </DoSomething>
  </env:Body>
</env:Envelope>

Never mind the weird namespace convention (or is that just me) in this XML that is savon doing its thing.

The problem I face is that the tags inside the securitytoken tag all start with a lower case letter where they should be upper case. So <tokenType> and <token> should have been <TokenType> and <Token>.

In my opinion the definition of these tags are all in the WSDL that is used to create the savon client. That definition seems not to be used or used incorrectly.

What can I do to get the correct XML/SOAP message from savon?

like image 907
Bob Groeneveld Avatar asked Jun 24 '11 08:06

Bob Groeneveld


3 Answers

For later releases of Savon, you should be able to supply a 'global' option of convert_request_keys_to when you initialize your Savon client:

# In Savon 2
Savon.client wsdl:"http://some.url?wsdl", convert_request_keys_to: :camelcase

According to comments in the source file, it accepts one of :lower_camelcase, :camelcase, :upcase, or :none.

like image 198
JellicleCat Avatar answered Nov 15 '22 07:11

JellicleCat


I had a similar problem with Savon and ended up using strings in stead of symbols for my hash keys, you could try something like:

soap.body = { 'TokenType'=> 'some_value', 'Token' => 'some_value' }
like image 21
Cimm Avatar answered Nov 15 '22 08:11

Cimm


Savon uses Gyoku for the conversion of tags I believe. To change the symbol conversion you can insert the following statement:

Gyoku.convert_symbols_to :camelcase # or one of [:none, :lover_camelcase]

hope that helps.

like image 10
Steffen Roller Avatar answered Nov 15 '22 08:11

Steffen Roller