Reputation: 61
using Savon version 3.x (the current master branch found https://github.com/savonrb/savon).
currently to generate a soap request in savon 3 you define the body of the message as a hash, ex:
operation.body = {
Search: {
accountID: 23,
accountStatus: 'closed'
}
}
response = operation.call
from the hash, savon will generate the complete soap message xml (envelope, headers, etc..) and pass that message onto HttpClient to post the request to your soap endpoint.
instead of a hash, i'd like to be able to pass in a complete xml message as my request, ex: my_xml_request_message =' ..... lots more nested nodes, namespaces and tons of attributes, etc ..... '
it appears that body
is sent to build
to create the soap request, and is then posted by call
:
https://github.com/savonrb/savon/blob/master/lib/savon/operation.rb#L79
def call
raw_response = @http.post(endpoint, http_headers, build)
Response.new(raw_response)
end
so i thinking was to monkey patch? call
to allow me to override build
with my xml block, ex:
def call
raw_response = @http.post(endpoint, http_headers, my_xml_request_message)
Response.new(raw_response)
end
that's where we're getting stuck - it's not clear to me if my xml is getting created or posted correctly. or if this is the correct way to proceed...
thanks in advance for any help!
Upvotes: 2
Views: 1664
Reputation: 61
monkey patch solved our problem - so i think this is good answer for now. we're looking to add this solution to savon 3 master if possible, details: https://github.com/savonrb/savon/issues/546
class Savon
class Operation
attr_accessor :raw_xml_envelope
def call
message = (raw_xml_envelope != nil ? raw_xml_envelope : build)
raw_response = @http.post(endpoint, http_headers, message)
Response.new(raw_response)
end
end
end
more background:
we've built a webservices (SOAP & REST) testing framework using Savon for the soap backbone. in our framework we define a couple methods describing each wsdl operation, our use case is to allow usage of the savon body() method when wanting to define the xml body as a hash (as described by savon's example_body()) or to pass in the complete raw xml envelope - which we are able to do using raw_xml_envelope() method above via monkey patch.
Upvotes: 1
Reputation: 3494
I don't use Savon3 yet, because it's not stable yet. What you can do in v2 is:
client.call(:authenticate, xml: "<envelope><body></body></envelope>")
I suppose something similar will work in v3 as well. It existed in v1 and v2.
Upvotes: 1