handsoap 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/VERSION.yml +1 -1
  3. data/lib/handsoap/service.rb +54 -29
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Zjg4MmMzOTQ1YWMzZWEwMDQwMDBiYmY2MjM1M2NiMGQxMGM2YTBkMQ==
4
+ YjVlMDlmZDhmYWQ2NWFhNzc2ZDYzODRjNjM2YWJlZjlhZDY2ODc5Zg==
5
5
  data.tar.gz: !binary |-
6
- ODdhNDYwNmM5N2I0ZWEzZmVjNTNhMDNmN2M4NTgzYTk2ODZhODI3OQ==
6
+ NWIxMzA5MDM5Yjg2ZGVmZjEyNjk0NmY0YzZiNmI2MTU2NDJhNTFhNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NGRhNmU4ZThlYTljY2E2NjE1NGJlOWVjZTcxOTVjZjRmM2M4NTZmYmM4MzRj
10
- OWYzM2ZjZDllZmE2N2U2M2EzMzRiMzQwYjQ4OWMxNDRkMzdlOGQyY2NhYmZh
11
- ZGQ1MjZmNzNkODVjMWE4MWEzNWE4ZTkxMDA5MjIzOWVjMDM4MTc=
9
+ N2RlNzkyMzVlOTZlYzczNzEyYjc5MDcyM2EyMmMyODc0NmNkM2M2Y2NiNmNm
10
+ OWNkM2ViNmYwMjQwNjBiNzdkYWIyZGZmMThiNjUyZjA4MDYxOGU4OTY4NWFl
11
+ MTFjOGU4M2VkMjM3NTc5ZmE1NzZiNGQ5NGY4ZDEyNDU5N2E4N2M=
12
12
  data.tar.gz: !binary |-
13
- NjI5MTY2Nzk2N2RjM2M2MTU4MjU1ODIzNDJjM2YyYmJmYmYyZjZmNDA4ZWFj
14
- ZTQ3OWYyOGZjMGE0MjI0YzZlYzM5OGIyOTExZjViODE4ZDMxNGNmNmRlZGVk
15
- ZTkwMGFmMjc4NTQ5YjUyYTc3OTFkYjdlNDU3ODkwNDYxYzAyZDc=
13
+ MmRlN2IyMDBkZDMzMjI2OTZhMzI0NWMwYTc2ODkxZWZlNmI5MjJiZGRmOTNm
14
+ ZmI1Y2FhNTRmYjc0MDYyNGVlOTI5ZmU1NjdiNDM1ZmZjMTEzOTE5ZjFhMDU4
15
+ Zjk2M2M5ZmE0OThiZGMwNzM3MjgxMDQ3MmRhMzBlNGZmNGEzODY=
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 3
3
+ :minor: 4
4
4
  :patch: 0
5
5
  :build:
@@ -7,6 +7,14 @@ require 'handsoap/deferred'
7
7
 
8
8
  module Handsoap
9
9
 
10
+ def self.store_raw_response=(boolean)
11
+ @store_raw_response = boolean
12
+ end
13
+
14
+ def self.store_raw_response?
15
+ !!@store_raw_response
16
+ end
17
+
10
18
  def self.http_driver
11
19
  @http_driver || (self.http_driver = :curb)
12
20
  end
@@ -24,28 +32,28 @@ module Handsoap
24
32
  def self.xml_query_driver=(driver)
25
33
  @xml_query_driver = Handsoap::XmlQueryFront.load_driver!(driver)
26
34
  end
27
-
35
+
28
36
  # Sets the timeout
29
37
  def self.timeout=(timeout)
30
38
  @timeout = timeout
31
39
  end
32
40
 
33
41
  # fetches the timeout
34
- # the default timeout is set to 60seconds
42
+ # the default timeout is set to 60seconds
35
43
  def self.timeout
36
44
  @timeout || (self.timeout = 60)
37
45
  end
38
-
46
+
39
47
  # Tell Handsoap to follow redirects
40
48
  def self.follow_redirects!
41
49
  @follow_redirects = true
42
50
  end
43
-
51
+
44
52
  # Check whether Handsoap should follow redirects
45
53
  def self.follow_redirects?
46
54
  @follow_redirects || false
47
55
  end
48
-
56
+
49
57
  # Sets the max number of redirects
50
58
  def self.max_redirects=(max_redirects)
51
59
  @max_redirects = max_redirects
@@ -60,51 +68,51 @@ module Handsoap
60
68
  # Wraps SOAP errors in a standard class.
61
69
  class Fault < StandardError
62
70
  attr_reader :code, :reason, :details
63
-
71
+
64
72
  def initialize(code, reason, details)
65
73
  @code = code
66
74
  @reason = reason
67
75
  @details = details
68
76
  end
69
-
77
+
70
78
  def to_s
71
79
  "Handsoap::Fault { :code => '#{@code}', :reason => '#{@reason}' }"
72
80
  end
73
-
81
+
74
82
  def self.from_xml(node, options = { :namespace => nil })
75
83
  if not options[:namespace]
76
84
  raise "Missing option :namespace"
77
85
  end
78
-
86
+
79
87
  ns = { 'env' => options[:namespace] }
80
-
88
+
81
89
  # tries to find SOAP1.2 fault code
82
90
  fault_code = node.xpath("./env:Code/env:Value", ns).to_s
83
-
91
+
84
92
  # if no SOAP1.2 fault code was found, try the SOAP1.1 way
85
93
  unless fault_code
86
94
  fault_code = node.xpath('./faultcode', ns).to_s
87
-
95
+
88
96
  # if fault_code is blank, add the namespace and try again
89
97
  unless fault_code
90
98
  fault_code = node.xpath("//env:faultcode", ns).to_s
91
99
  end
92
100
  end
93
-
101
+
94
102
  # tries to find SOAP1.2 reason
95
103
  reason = node.xpath("./env:Reason/env:Text[1]", ns).to_s
96
-
104
+
97
105
  # if no SOAP1.2 faultstring was found, try the SOAP1.1 way
98
106
  unless reason
99
107
  reason = node.xpath('./faultstring', ns).to_s
100
-
108
+
101
109
  # if reason is blank, add the namespace and try again
102
110
  unless reason
103
111
  reason = node.xpath("//env:faultstring", ns).to_s
104
112
  end
105
113
  end
106
-
107
- details = node.xpath('./detail/*', ns)
114
+
115
+ details = node.xpath('./detail/*', ns)
108
116
  self.new(fault_code, reason, details)
109
117
  end
110
118
  end
@@ -118,11 +126,15 @@ module Handsoap
118
126
  end
119
127
 
120
128
  class SoapResponse
121
- attr_reader :document, :http_response
122
- def initialize(document, http_response)
129
+
130
+ attr_reader :document, :http_response, :raw_xml
131
+
132
+ def initialize(document, http_response, raw_xml=nil)
123
133
  @document = document
124
134
  @http_response = http_response
135
+ @raw_xml = raw_xml
125
136
  end
137
+
126
138
  def method_missing(method, *args, &block)
127
139
  if @document.respond_to?(method)
128
140
  @document.__send__ method, *args, &block
@@ -130,6 +142,7 @@ module Handsoap
130
142
  super
131
143
  end
132
144
  end
145
+
133
146
  end
134
147
 
135
148
  class AsyncDispatch
@@ -228,7 +241,7 @@ module Handsoap
228
241
  if options[:soap_header]
229
242
  iterate_hash_array(header, options[:soap_header])
230
243
  end
231
-
244
+
232
245
  if options[:soap_body]
233
246
  action_hash = { action => options[:soap_body] }
234
247
  iterate_hash_array(body, action_hash)
@@ -244,7 +257,7 @@ module Handsoap
244
257
  "Content-Type" => "#{self.request_content_type}; charset=UTF-8"
245
258
  }
246
259
  headers["SOAPAction"] = options[:soap_action] unless options[:soap_action].nil?
247
- on_before_dispatch
260
+ on_before_dispatch(doc)
248
261
  request = make_http_request(self.uri, doc.to_s, headers, options[:http_options])
249
262
  response = http_driver_instance.send_http_request(request)
250
263
  parse_http_response(response)
@@ -281,8 +294,17 @@ module Handsoap
281
294
  elsif options[:soap_action] == :none
282
295
  options[:soap_action] = nil
283
296
  end
284
- doc = make_envelope do |body|
285
- body.add action
297
+ doc = make_envelope do |body,header|
298
+ if options[:soap_header]
299
+ iterate_hash_array(header, options[:soap_header])
300
+ end
301
+
302
+ if options[:soap_body]
303
+ action_hash = { action => options[:soap_body] }
304
+ iterate_hash_array(body, action_hash)
305
+ else
306
+ body.add(action)
307
+ end
286
308
  end
287
309
  dispatcher.request_block.call doc.find(action)
288
310
  # ready to dispatch
@@ -290,7 +312,7 @@ module Handsoap
290
312
  "Content-Type" => "#{self.request_content_type}; charset=UTF-8"
291
313
  }
292
314
  headers["SOAPAction"] = options[:soap_action] unless options[:soap_action].nil?
293
- on_before_dispatch
315
+ on_before_dispatch(doc)
294
316
  request = make_http_request(self.uri, doc.to_s, headers)
295
317
  driver = self.http_driver_instance
296
318
  if driver.respond_to? :send_http_request_async
@@ -352,7 +374,7 @@ module Handsoap
352
374
  # Hook that is called before the message is dispatched.
353
375
  #
354
376
  # You can override this to provide filtering and logging.
355
- def on_before_dispatch
377
+ def on_before_dispatch(doc)
356
378
  end
357
379
  # Hook that is called after the http_client is created.
358
380
  #
@@ -408,7 +430,7 @@ module Handsoap
408
430
  request.set_client_cert_files(http_options[:client_cert_file], http_options[:client_cert_key_file]) if http_options[:client_cert_file] && http_options[:client_cert_key_file]
409
431
  request.set_ssl_verify_mode(http_options[:ssl_verify_mode]) if http_options[:ssl_verify_mode]
410
432
  end
411
-
433
+
412
434
  headers.each do |key, value|
413
435
  request.add_header(key, value)
414
436
  end
@@ -425,10 +447,11 @@ module Handsoap
425
447
  def parse_http_response(response)
426
448
  debug do |logger|
427
449
  logger.puts(response.inspect do |body|
428
- Handsoap.pretty_format_envelope(body).chomp
450
+ Handsoap.pretty_format_envelope(body.force_encoding('utf-8')).chomp
429
451
  end)
430
452
  end
431
- xml_document = parse_soap_response_document(response.primary_part.body)
453
+ raw_xml_document = response.primary_part.body.force_encoding('utf-8')
454
+ xml_document = parse_soap_response_document(raw_xml_document)
432
455
  soap_fault = parse_soap_fault(xml_document)
433
456
  # Is the response a soap-fault?
434
457
  unless soap_fault.nil?
@@ -444,7 +467,9 @@ module Handsoap
444
467
  end
445
468
  # Everything seems in order.
446
469
  on_response_document(xml_document)
447
- return SoapResponse.new(xml_document, response)
470
+ args = [xml_document, response]
471
+ args << raw_xml_document if Handsoap.store_raw_response?
472
+ return SoapResponse.new(*args)
448
473
  end
449
474
 
450
475
  # Creates a standard SOAP envelope and yields the +Body+ element.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handsoap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troels Knak-Nielsen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-11 00:00:00.000000000 Z
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Handsoap is a library for creating SOAP clients in Ruby
15
15
  email: