Skip to content

Commit 79548db

Browse files
committed
Add basic WS-Addressing support (refs savonrb#409)
1 parent 6bd65bb commit 79548db

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ gem "httpclient", "~> 2.3.4"
55

66
gem "simplecov", :require => false
77
gem "coveralls", :require => false
8+
gem "uuid"
89

910
platform :rbx do
1011
gem 'json'

lib/savon/builder.rb

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class Builder
1717
2 => "http://www.w3.org/2003/05/soap-envelope"
1818
}
1919

20+
WSA_NAMESPACE = "http://www.w3.org/2005/08/addressing"
21+
2022
def initialize(operation_name, wsdl, globals, locals)
2123
@operation_name = operation_name
2224

@@ -32,15 +34,25 @@ def pretty
3234
Nokogiri.XML(to_s).to_xml(:indent => 2)
3335
end
3436

35-
def to_s
36-
return @locals[:xml] if @locals.include? :xml
37-
37+
def build_document
3838
tag(builder, :Envelope, namespaces_with_globals) do |xml|
39-
tag(xml, :Header) { xml << header.to_s } unless header.empty?
40-
tag(xml, :Body) { xml.tag!(*namespaced_message_tag) { xml << message.to_s } }
39+
tag(xml, :Header, header_attributes) { xml << header.to_s } unless header.empty?
40+
tag(xml, :Body, body_attributes) { xml.tag!(*namespaced_message_tag) { xml << message.to_s } }
4141
end
4242
end
4343

44+
def header_attributes
45+
{ 'xmlns:wsa' => WSA_NAMESPACE } if @globals[:use_wsa_headers]
46+
end
47+
48+
def body_attributes
49+
end
50+
51+
def to_s
52+
return @locals[:xml] if @locals.include? :xml
53+
build_document
54+
end
55+
4456
private
4557

4658
def convert_type_definitions_to_hash

lib/savon/header.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "akami"
22
require "gyoku"
3+
require "uuid"
34

45
module Savon
56
class Header
@@ -13,6 +14,9 @@ def initialize(globals, locals)
1314
@global_header = globals[:soap_header]
1415
@local_header = locals[:soap_header]
1516

17+
@globals = globals
18+
@locals = locals
19+
1620
@header = build
1721
end
1822

@@ -30,7 +34,7 @@ def to_s
3034
private
3135

3236
def build
33-
build_header + build_wsse_header
37+
build_header + build_wsa_header + build_wsse_header
3438
end
3539

3640
def build_header
@@ -51,6 +55,15 @@ def build_wsse_header
5155
wsse_header.respond_to?(:to_xml) ? wsse_header.to_xml : ""
5256
end
5357

58+
def build_wsa_header
59+
return '' unless @globals[:use_wsa_headers]
60+
convert_to_xml({
61+
'wsa:Action' => @locals[:soap_action],
62+
'wsa:To' => @globals[:endpoint],
63+
'wsa:MessageID' => "urn:uuid:#{UUID.new.generate}"
64+
})
65+
end
66+
5467
def convert_to_xml(hash_or_string)
5568
if hash_or_string.kind_of? Hash
5669
Gyoku.xml(hash_or_string, gyoku_options)

lib/savon/operation.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def call_with_logging(request)
8787
end
8888

8989
def build_request(builder)
90+
@locals[:soap_action] ||= soap_action
91+
@globals[:endpoint] ||= endpoint
92+
9093
request = SOAPRequest.new(@globals).build(
9194
:soap_action => soap_action,
9295
:cookies => @locals[:cookies]

lib/savon/options.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def initialize(options = {})
5757
:convert_attributes_to => lambda { |k,v| [k,v] },
5858
:multipart => false,
5959
:adapter => nil,
60+
:use_wsa_headers => false,
6061
}
6162

6263
options = defaults.merge(options)
@@ -271,6 +272,11 @@ def multipart(multipart)
271272
def adapter(adapter)
272273
@options[:adapter] = adapter
273274
end
275+
276+
# Enable inclusion of WS-Addressing headers.
277+
def use_wsa_headers(use)
278+
@options[:use_wsa_headers] = use
279+
end
274280
end
275281

276282
class LocalOptions < Options

0 commit comments

Comments
 (0)