Created
January 29, 2012 12:41
-
-
Save rubiii/1698636 to your computer and use it in GitHub Desktop.
Monkey patch Savon to allow attributes to be added to the SOAP header tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "savon" | |
module Savon | |
module SOAP | |
class XML | |
attr_accessor :header_attributes | |
def to_xml | |
@xml ||= tag(builder, :Envelope, complete_namespaces) do |xml| | |
# adds the header_attributes: | |
tag(xml, :Header, header_attributes) { xml << header_for_xml } unless header_for_xml.empty? | |
if input.nil? | |
tag(xml, :Body) | |
else | |
tag(xml, :Body) { xml.tag!(*add_namespace_to_input) { xml << body_to_xml } } | |
end | |
end | |
end | |
end | |
end | |
end | |
client = Savon::Client.new do | |
wsdl.endpoint = "http://example.com" | |
wsdl.namespace = "http://v1.example.com" | |
end | |
client.request :something do | |
soap.header = { :key => "value" } | |
soap.header_attributes = { "xmlns:wsa" => "http://www.w3.org/2005/08/addressing" } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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://v1.example.com" | |
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"> | |
<env:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"> | |
<key>value</key> | |
</env:Header> | |
<env:Body> | |
<something></something> | |
</env:Body> | |
</env:Envelope> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why can't we just have this as part of savon?