Body Wrappers

101 views
Skip to first unread message

Brian Loomis

unread,
Aug 10, 2011, 12:26:06 PM8/10/11
to Savon
I'm trying to clean up my soap (pun intended) for some interactions
with the ExactTarget API similar to what was shown here:
http://expertbeginner.com/2010/11/11/exacttarget-wsdl-examples/

Currently my ruby reads like this to generate the client requests.

@soap_body = {
':RetrieveRequestMsg' => {
':RetrieveRequest' => {
':ObjectType' => 'List',
':Properties' => ['ListName','ID'],
':Filter' => {
':Property' => 'ID',
':SimpleOperator' => 'equals',
':Value' => '12345',
},
:attributes! => {
':Filter' => {'xsi:type' => 'SimpleFilterPart'}
}
}
},
:attributes! => {
':RetrieveRequestMsg' => {'xmlns' => 'http://exacttarget.com/wsdl/
partnerAPI'}
}
}
#
response = client.request(:retrieve) do |soap|
soap.header = @soap_header
soap.body = @soap_body
@method = soap.body
end

This yields the following body:
<env:Body>
<Retrieve>
<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/
partnerAPI">
<RetrieveRequest>
<ObjectType>List</ObjectType>
<Properties>ListName</Properties>
<Properties>ID</Properties>
<Filter xsi:type="SimpleFilterPart">
<Property>ID</Property>
<SimpleOperator>equals</SimpleOperator>
<Value>12345</Value>
</Filter>
</RetrieveRequest>
</RetrieveRequestMsg>
</Retrieve>
</env:Body>

The vendor however needs the <Retrieve> and </Retrieve> removed to
not return the error. The body should look like this:
<env:Body>
<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/
partnerAPI">
<RetrieveRequest>
<ObjectType>List</ObjectType>
<Properties>ListName</Properties>
<Properties>ID</Properties>
<Filter xsi:type="SimpleFilterPart">
<Property>ID</Property>
<SimpleOperator>equals</SimpleOperator>
<Value>12345</Value>
</Filter>
</RetrieveRequest>
</RetrieveRequestMsg>
</env:Body>

I note in the documention here:
http://savonrb.com/#executing_soap_requests
"The argument(s) passed to the #request method will affect the SOAP
input tag inside the SOAP request.
To make sure you know what this means, here’s an example for a simple
request:"

I'm trying to find a method to eliminate the input tag in my request
from happening.

I can't see where you can explicitly declare to not have that in there
without resorting to handcoding the whole XML request so I'm down to
monkey patching the gem locally so that I can eliminate this
behavior. I'm looking at the XML file:
https://github.com/rubiii/savon/blob/master/lib/savon/soap/xml.rb

I'm wondering:
1) If I want to eliminate that input is there a declaration to do it?
2) What would be the best place to fix this at?

thanks in advance
Brian
"

Brian Loomis

unread,
Aug 10, 2011, 12:37:29 PM8/10/11
to Savon
Just edited this in the xml.rb file in the savon gem. Fortunately
this is the only thing I'm using savon on so I can monkey patch it for
now.
# Returns the XML for a SOAP request.
def to_xml
@xml ||= tag(builder, :Envelope, complete_namespaces) do |xml|
tag(xml, :Header) { 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

to

# Returns the XML for a SOAP request.
def to_xml
@xml ||= tag(builder, :Envelope, complete_namespaces) do |xml|
tag(xml, :Header) { xml << header_for_xml } unless
header_for_xml.empty?

if input.nil?
tag(xml, :Body)
else
tag(xml, :Body) { xml << body_to_xml }
end
end
end

That is in the gem in the .rvm for 1.9.2. I've never written a patch
before but I guess if I figure out a way to set a value to return this
instead of the other I could and submit it.

rubiii

unread,
Aug 25, 2011, 9:13:38 AM8/25/11
to Savon
you can overwrite the input tag with an array of [namespace, tag,
attributes] like this:

client.request(:retrieve) do
soap.input = [nil, "RetrieveRequestMsg", "xmlns" => "http://
exacttarget.com/wsdl/partnerAPI"]
soap.body = {
':RetrieveRequest' => {
':ObjectType' => 'List',
':Properties' => ['ListName','ID'],
':Filter' => {
':Property' => 'ID',
':SimpleOperator' => 'equals',
':Value' => '12345',
}
}
}
end

cheers,
daniel

rubiii

unread,
Aug 25, 2011, 9:15:35 AM8/25/11
to Savon
just released that this might work even better without syntax
errors ;)

Mathijs Mohlmann

unread,
Feb 29, 2012, 11:34:14 AM2/29/12
to sav...@googlegroups.com
My issues is simular. My request must look like this, but whatever I try I cannot get this to work. Is there a way to do this?

?xml version="1.0" encoding="utf-8" ?>
  <env:Body>
    <cpaId>ApNL99_to_ApDE01</cpaId>
    <action>ApNL99_send_to_ApDE01</action>
    <convId>convId</convId>
    <fromPartyId>ApNL99</fromPartyId>
    <fromPartyType>string</fromPartyType>
    <toPartyId>ApDE01</toPartyId>
    <toPartyType>string</toPartyType>
    <refToMessageId xsi:nil="true"></refToMessageId>
    <serviceType xsi:nil="true"></serviceType>
  </env:Body>
</env:Envelope>
Reply all
Reply to author
Forward
0 new messages