Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

namespace_identifier to affect message body and header #362

Closed
courtland opened this issue Jan 10, 2013 · 5 comments
Closed

namespace_identifier to affect message body and header #362

courtland opened this issue Jan 10, 2013 · 5 comments

Comments

@courtland
Copy link
Contributor

I'm using savon 2.x master. The API I'm using seems to want a namespace identifier before ALL of the XML tags.

For example. I need a header that looks like this:

<soapenv:Header>

   <inn:HTNGHeader>

      <inn:From>

         <inn:SystemId>SOMEID</inn:SystemId>

         <inn:Credential>

            <inn:UserName>someusername</inn:UserName>

            <inn:Password>password</inn:Password>

         </inn:Credential>

      </inn:From>

      <inn:To>

         <inn:SystemId>001</inn:SystemId>

      </inn:To>

   </inn:HTNGHeader>

</soapenv:Header>

And a body that looks like:

<soapenv:Body>

   <inn:SearchReservationsRQ>

      <inn:RoomID>128</inn:RoomID>

      <inn:ReservationStatus>

         <inn:RsvStatus>In-house</inn:RsvStatus>

      </inn:ReservationStatus>

   </inn:SearchReservationsRQ>

</soapenv:Body>

When I instantiate the client, I'm using the :namespace_identifier option, which seems to affect only the namespace identifier of the action tag.

However, when I do a client call, I am having to manually set the namespace identifier in the header and body hash. For example:

  ns = 'inn'

  def header
    @header ||= {
      "#{ns}:HTNGHeader" => {
        "#{ns}:From" => {
          "#{ns}:SystemId" => from_system_id,
          "#{ns}:Credential" => {
            "#{ns}:UserName" => username,
            "#{ns}:Password" => password,
          }
        },
        "#{ns}:To" => {
          "#{ns}:SystemId" => to_system_id
        }
      }
    }
  end

  client = Savon.client(
      :wsdl                 => wsdl_file,
      :endpoint             => endpoint_url,
      :soap_header          => header,
      :env_namespace        => :soapenv,
      :namespace_identifier => ns,
      # disable SSL certificate check
      :ssl_verify_mode      => :none,
      :logger               => Rails.logger
    )

    response = client.call(:search_reservations,
      :message => {
        "#{ns}:RoomID" => room,
        "#{ns}:ReservationStatus" => {
          "#{ns}:RsvStatus" => 'In-house'
        }
      }
    )

Note the extensive use of "#{ns}:" prepended to hash keys that yields an XML tag of "<inn:..."

I've been doing it like this for a while with savon 1.2, but its not the cleanest solution. Now that I am in the process of upgrading to 2.x, I thought there might be a better way to do this, perhaps with the namespace_identifier option?

Thanks.

@rubiii
Copy link
Contributor

rubiii commented Jan 10, 2013

i've seen your wsdl and the problem is that the type information are included in a separate file and imported into the wsdl. unfortunately savon doesn't support imports just yet. see #340

but you should be able to manually specify whether you want the elements to be namespaced:
http://savonrb.com/version2.html#element-form-default

@courtland
Copy link
Contributor Author

Ok. Thanks!

@courtland
Copy link
Contributor Author

I tried setting element_form_default to :qualified in my client options. It seems to affect the tags in the message but not the header. The header is configured via setting the soap_header option. For now I am just explicitly setting the namespace in the header Hash as described above, but not in the message bodies. Not sure if you want to do anything about that or have an alternate suggestion?

@rubiii
Copy link
Contributor

rubiii commented Jan 11, 2013

there's already an open issue for that. i just haven't found the time to work on this, but it needs to be fixed.
you can follow the ticket for updates: #305

@courtland
Copy link
Contributor Author

Thanks. I greatly appreciate your time and effort today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants