Sending Raw Xml Using Savon 2

Sending raw XML using Savon 2

The call should look like this:

client.call(:some_op, xml: "<elem />")

Or if you just want to set one or multiple namespaces then create a client as follows (without WSDL):

client = Savon.client(
:endpoint => 'http://www.example.com',
:namespace => 'urn:core.example.com',
:namespaces => { 'ns1' => 'http://v1.example.com',
'ns2' => 'http://v2.example.com' },
:log => true,
:log_level => :debug,
:pretty_print_xml => true
)

The namespaces are a Hash parameter.

SAVON passing XML as a request to wsdl and getting response as xml

Hello I found the answer and below is the code

Then (/^I test wsdl$/) do
require 'savon'

require 'nokogiri'

xml_file = File.read("/test.xml")

client = Savon.client(wsdl: '/globalweather.wsdl', ssl_verify_mode: :none, ssl_version: :TLSv1)

response = client.call(:get_cities_by_country, xml: xml_file)
puts response.to_xml
print response.to_xml

end

Converting raw XML query to Savon 2 Format

have you looked into the resulting XML message?

you should set the parameters

log => true,
log_level => :debug,
pretty_print_xml => true

and have a look.

View Savon Request XML without Sending to Server

Savon uses HTTPI to execute SOAP requests. HTTPI is a common interface on top of various Ruby HTTP clients. You could probably mock/stub the HTTP request executed by Savon via:

HTTPI.expects(:post).with do |http|
SchemaValidation.validate(:get_user, http.body)
end

Please note that I used Mocha for mocking the SOAP request, getting the HTTP body and validating it against some validation method (pseudo-code).

Currently, Savon does not support building up requests without executing them. So the only way to validate the request would be to intercept it.

If you would need Savon to support this feature, please let me know and open a ticket over at GitHub.

EDIT: There's also savon_spec, which is a little helper for basic fixture-based testing with Savon.

Savon using built in request builder instead of raw xml

I usually do just this (untested). It's not pretty but it works.

credentials = { 'ns1:username' => 'user',
'ns1:password' => 'pwd!!',
'ns1:cultureInfo' => "it" }
response = client.call(:authenticate, message: credentials)

You might want to adapt the use of ns1 to the actually used namespace in your case.

Savon v3.x - how to pass complete xml message as soap request

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.



Related Topics



Leave a reply



Submit