Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Savon Request XML without Sending to Server

I'm using the Savon gem to make a SOAP request using code similar to what's below. It's working, but I would like to view/capture the request XML without actually making a call to their server. I can view it now after a request is made by sticking a debugger line after the request and inspecting the client variable.

Does anyone know of a way to view the request XML without actually making a request? I want to be able to validate the XML against a schema using Cucumber or Rspec.

client = Savon::Client.new do |wsdl, http|   wsdl.document = "http://fakesite.org/fake.asmx?wsdl" end  client.request(:testpostdata, :xmlns => "http://fakesite.org/") do   soap.header = { :cAuthentication => {"UserName" => "MyName", "Password" => "MyPassword" } }   soap.body = { :xml_data => to_xml } end 
like image 755
Peter Brown Avatar asked May 02 '11 17:05

Peter Brown


1 Answers

Using Savon 2 I do it this way, write a method that return the request body from the client.

 client = Savon::Client.new(....) 

this is not mentioned in the documentation

  def get_request      # list of operations can be found using client.operations      ops = client.operation(:action_name_here)       # build the body of the xml inside the message here              ops.build(message: { id: 42, name: "Test User", age: 20 }).to_s   end 
like image 111
carbonr Avatar answered Sep 26 '22 09:09

carbonr