Class: WSDL::Response
- Inherits:
-
Object
- Object
- WSDL::Response
- Defined in:
- lib/wsdl/response.rb,
lib/wsdl/response/fault.rb,
lib/wsdl/response/parser.rb,
lib/wsdl/response/builder.rb,
lib/wsdl/response/fault_parser.rb,
lib/wsdl/response/type_coercer.rb,
lib/wsdl/response/security_context.rb
Overview
Represents a SOAP response from an operation call.
This class wraps the raw HTTP response and provides methods for parsing and accessing the SOAP envelope contents. When schema information is available, response values are automatically converted to appropriate Ruby types and arrays are handled consistently based on the schema's maxOccurs definitions.
Defined Under Namespace
Classes: Builder, Fault, FaultParser, Parser, SecurityContext, TypeCoercer
Instance Attribute Summary collapse
-
#code ⇒ String?
readonly
The fault code (faultcode in 1.1, Code/Value in 1.2).
-
#detail ⇒ Hash?
readonly
Parsed fault detail children, or nil if absent.
-
#node ⇒ String?
readonly
URI of the SOAP node that generated the fault (SOAP 1.2 only).
-
#reason ⇒ String?
readonly
The fault reason (faultstring in 1.1, Reason/Text in 1.2).
-
#role ⇒ String?
readonly
Role/actor (faultactor in 1.1, Role in 1.2).
-
#subcodes ⇒ Array<String>
readonly
Nested subcodes (SOAP 1.2 only, empty for 1.1).
Instance Method Summary collapse
-
#body ⇒ Hash
Returns the parsed SOAP body as a Hash.
-
#doc ⇒ Nokogiri::XML::Document
Returns the response as a Nokogiri XML document.
-
#fault ⇒ Fault?
Returns the parsed SOAP fault, or nil if the response is not a fault.
-
#fault? ⇒ Boolean
Returns whether the response contains a SOAP fault.
-
#header ⇒ Hash?
Returns the parsed SOAP header as a Hash.
-
#http_headers ⇒ Hash{String => String}
Returns the HTTP response headers.
-
#http_status ⇒ Integer?
Returns the HTTP status code of the response.
-
#initialize(http_response:, output_body_parts: nil, output_header_parts: nil, output_style: 'document/literal', verification: Security::ResponseVerification::Options.default) ⇒ Response
constructor
Creates a new Response instance.
-
#security ⇒ SecurityContext
Returns the security context for signature and timestamp verification.
-
#xml ⇒ String
Returns the raw XML response string.
Constructor Details
#initialize(http_response:, output_body_parts: nil, output_header_parts: nil, output_style: 'document/literal', verification: Security::ResponseVerification::Options.default) ⇒ Response
Creates a new Response instance.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/wsdl/response.rb', line 63 def initialize(http_response:, output_body_parts: nil, output_header_parts: nil, output_style: 'document/literal', verification: Security::ResponseVerification::Options.default) @raw_response = (http_response.body || '').freeze @http_response = http_response @output_body_parts = output_body_parts @output_header_parts = output_header_parts @output_style = output_style @verification = verification end |
Instance Attribute Details
#code ⇒ String? (readonly)
Returns the fault code (faultcode in 1.1, Code/Value in 1.2).
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wsdl/response/fault.rb', line 53 Fault = Data.define(:code, :subcodes, :reason, :detail, :node, :role) { # Returns a human-readable summary of the fault. # # @return [String] fault summary def to_s = "(#{code}) #{reason}" << " [role: #{role}]" if role end } |
#detail ⇒ Hash? (readonly)
Returns parsed fault detail children, or nil if absent.
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wsdl/response/fault.rb', line 53 Fault = Data.define(:code, :subcodes, :reason, :detail, :node, :role) { # Returns a human-readable summary of the fault. # # @return [String] fault summary def to_s = "(#{code}) #{reason}" << " [role: #{role}]" if role end } |
#node ⇒ String? (readonly)
Returns URI of the SOAP node that generated the fault (SOAP 1.2 only).
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wsdl/response/fault.rb', line 53 Fault = Data.define(:code, :subcodes, :reason, :detail, :node, :role) { # Returns a human-readable summary of the fault. # # @return [String] fault summary def to_s = "(#{code}) #{reason}" << " [role: #{role}]" if role end } |
#reason ⇒ String? (readonly)
Returns the fault reason (faultstring in 1.1, Reason/Text in 1.2).
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wsdl/response/fault.rb', line 53 Fault = Data.define(:code, :subcodes, :reason, :detail, :node, :role) { # Returns a human-readable summary of the fault. # # @return [String] fault summary def to_s = "(#{code}) #{reason}" << " [role: #{role}]" if role end } |
#role ⇒ String? (readonly)
Returns role/actor (faultactor in 1.1, Role in 1.2).
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wsdl/response/fault.rb', line 53 Fault = Data.define(:code, :subcodes, :reason, :detail, :node, :role) { # Returns a human-readable summary of the fault. # # @return [String] fault summary def to_s = "(#{code}) #{reason}" << " [role: #{role}]" if role end } |
#subcodes ⇒ Array<String> (readonly)
Returns nested subcodes (SOAP 1.2 only, empty for 1.1).
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wsdl/response/fault.rb', line 53 Fault = Data.define(:code, :subcodes, :reason, :detail, :node, :role) { # Returns a human-readable summary of the fault. # # @return [String] fault summary def to_s = "(#{code}) #{reason}" << " [role: #{role}]" if role end } |
Instance Method Details
#body ⇒ Hash
Returns the parsed SOAP body as a Hash.
When schema information is available (output_body_parts), values are automatically converted to appropriate Ruby types:
- xsd:int, xsd:integer, xsd:long → Integer
- xsd:decimal → BigDecimal
- xsd:float, xsd:double → Float
- xsd:boolean → true/false
- xsd:date → Date
- xsd:dateTime → Time (only when timezone is explicit)
- xsd:base64Binary → decoded String
Elements with maxOccurs > 1 are always returned as Arrays, even when only one element is present.
117 118 119 |
# File 'lib/wsdl/response.rb', line 117 def body @body ||= parse_body end |
#doc ⇒ Nokogiri::XML::Document
Returns the response as a Nokogiri XML document.
Use this when you need full XML manipulation capabilities or want to run XPath queries.
140 141 142 |
# File 'lib/wsdl/response.rb', line 140 def doc @doc ||= XML::Parser.parse(xml) end |
#fault ⇒ Fault?
Returns the parsed SOAP fault, or nil if the response is not a fault.
174 175 176 177 178 |
# File 'lib/wsdl/response.rb', line 174 def fault return @fault if defined?(@fault) @fault = FaultParser.parse(doc) end |
#fault? ⇒ Boolean
Returns whether the response contains a SOAP fault.
Detects faults in both SOAP 1.1 and 1.2 envelopes.
159 160 161 |
# File 'lib/wsdl/response.rb', line 159 def fault? !fault.nil? end |
#header ⇒ Hash?
Returns the parsed SOAP header as a Hash.
When schema information is available (output_header_parts), values are automatically converted to appropriate Ruby types, similar to #body.
The header is extracted from the SOAP envelope and returned with symbolized keys preserving the original element names.
130 131 132 |
# File 'lib/wsdl/response.rb', line 130 def header @header ||= parse_header end |
#http_headers ⇒ Hash{String => String}
Returns the HTTP response headers.
87 88 89 |
# File 'lib/wsdl/response.rb', line 87 def http_headers @http_response.headers end |
#http_status ⇒ Integer?
Returns the HTTP status code of the response.
80 81 82 |
# File 'lib/wsdl/response.rb', line 80 def http_status @http_response.status end |
#security ⇒ SecurityContext
Returns the security context for signature and timestamp verification.
The security context provides methods for:
- Signature verification (
signature_valid?,verify_signature!) - Timestamp validation (
timestamp_valid?,verify_timestamp!) - Combined verification (
valid?,verify!)
205 206 207 |
# File 'lib/wsdl/response.rb', line 205 def security @security ||= SecurityContext.new(xml, @verification) end |
#xml ⇒ String
Returns the raw XML response string.
94 95 96 |
# File 'lib/wsdl/response.rb', line 94 def xml @raw_response end |