Class: Savon::Addressing

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(enabled:, action: nil, to: nil) ⇒ Addressing

Returns a new instance of Addressing.

Parameters:

  • enabled (Object)

    whether the headers are emitted, any truthy value counts (the :use_wsa_headers global)

  • action (String, nil) (defaults to: nil)

    the resolved SOAPAction, emitted as wsa:Action, or nil when the caller disabled it

  • to (URI, String, nil) (defaults to: nil)

    the resolved endpoint, emitted as wsa:To



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.

Returns:

  • (Boolean)

    whether the WS-Addressing headers are emitted



32
33
34
# File 'lib/savon/addressing.rb', line 32

def enabled?
  !!@enabled
end

#namespace_attributesHash{String => String}

Returns the namespace declaration the enclosing Header element needs. The wsa prefix is declared once on the Header, not on each child.

Returns:

  • (Hash{String => String})

    {"xmlns:wsa" => NAMESPACE}, or an empty Hash when disabled



41
42
43
# File 'lib/savon/addressing.rb', line 41

def namespace_attributes
  enabled? ? { "xmlns:wsa" => NAMESPACE } : {}
end

#to_xmlString

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.

Returns:

  • (String)

    the header elements, or an empty String when disabled



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