Class: Savon::Addressing
- Inherits:
-
Object
- Object
- Savon::Addressing
- Defined in:
- lib/savon/addressing.rb
Overview
Emits the WS-Addressing message addressing properties of a request
(WS-Addressing 1.0 - Core §3.2): wsa:Action, wsa:To and wsa:MessageID.
This object owns everything Savon knows about WS-Addressing: the namespace, whether the headers are emitted at all, and how the resolved SOAPAction and endpoint map onto the addressing properties. It works on plain values. Header resolves them via EffectiveOptions and constructs this object, keeping option resolution and WSA emission separate.
Constant Summary collapse
- NAMESPACE =
The WS-Addressing 1.0 namespace, https://www.w3.org/TR/ws-addr-core/#namespaces.
"http://www.w3.org/2005/08/addressing"
Instance Method Summary collapse
-
#enabled? ⇒ Boolean
Whether the WS-Addressing headers are emitted.
-
#initialize(enabled:, action: nil, to: nil) ⇒ Addressing
constructor
A new instance of Addressing.
-
#namespace_attributes ⇒ Hash{String => String}
Returns the namespace declaration the enclosing Header element needs.
-
#to_xml ⇒ String
Renders the three addressing properties, each rendering with a freshly generated
wsa:MessageID.
Constructor Details
#initialize(enabled:, action: nil, to: nil) ⇒ Addressing
Returns a new instance of Addressing.
25 26 27 28 29 |
# File 'lib/savon/addressing.rb', line 25 def initialize(enabled:, action: nil, to: nil) @enabled = enabled @action = action @to = to end |
Instance Method Details
#enabled? ⇒ Boolean
Returns whether the WS-Addressing headers are emitted.
32 33 34 |
# File 'lib/savon/addressing.rb', line 32 def enabled? !!@enabled end |
#namespace_attributes ⇒ Hash{String => String}
Returns the namespace declaration the enclosing Header element needs.
The wsa prefix is declared once on the Header, not on each child.
41 42 43 |
# File 'lib/savon/addressing.rb', line 41 def namespace_attributes enabled? ? { "xmlns:wsa" => NAMESPACE } : {} end |
#to_xml ⇒ String
Renders the three addressing properties, each rendering with a freshly
generated wsa:MessageID. A nil action or destination is emitted as
an xsi:nil element rather than being dropped.
50 51 52 53 54 55 56 57 58 |
# File 'lib/savon/addressing.rb', line 50 def to_xml return "" unless enabled? Gyoku.xml( "wsa:Action" => @action, "wsa:To" => @to, "wsa:MessageID" => "urn:uuid:#{SecureRandom.uuid}" ) end |