Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions lib/handsoap/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ def self.xml_query_driver
def self.xml_query_driver=(driver)
@xml_query_driver = Handsoap::XmlQueryFront.load_driver!(driver)
end

# Sets the timeout
def self.timeout=(timeout)
@timeout = timeout
end

# fetches the timeout
# the default timeout is set to 60seconds
# the default timeout is set to 60seconds
def self.timeout
@timeout || (self.timeout = 60)
end

# Tell Handsoap to follow redirects
def self.follow_redirects!
@follow_redirects = true
end

# Check whether Handsoap should follow redirects
def self.follow_redirects?
@follow_redirects || false
end

# Sets the max number of redirects
def self.max_redirects=(max_redirects)
@max_redirects = max_redirects
Expand All @@ -60,51 +60,51 @@ def self.max_redirects
# Wraps SOAP errors in a standard class.
class Fault < StandardError
attr_reader :code, :reason, :details

def initialize(code, reason, details)
@code = code
@reason = reason
@details = details
end

def to_s
"Handsoap::Fault { :code => '#{@code}', :reason => '#{@reason}' }"
end

def self.from_xml(node, options = { :namespace => nil })
if not options[:namespace]
raise "Missing option :namespace"
end

ns = { 'env' => options[:namespace] }

# tries to find SOAP1.2 fault code
fault_code = node.xpath("./env:Code/env:Value", ns).to_s

# if no SOAP1.2 fault code was found, try the SOAP1.1 way
unless fault_code
fault_code = node.xpath('./faultcode', ns).to_s

# if fault_code is blank, add the namespace and try again
unless fault_code
fault_code = node.xpath("//env:faultcode", ns).to_s
end
end

# tries to find SOAP1.2 reason
reason = node.xpath("./env:Reason/env:Text[1]", ns).to_s

# if no SOAP1.2 faultstring was found, try the SOAP1.1 way
unless reason
reason = node.xpath('./faultstring', ns).to_s

# if reason is blank, add the namespace and try again
unless reason
reason = node.xpath("//env:faultstring", ns).to_s
end
end
details = node.xpath('./detail/*', ns)

details = node.xpath('./detail/*', ns)
self.new(fault_code, reason, details)
end
end
Expand Down Expand Up @@ -228,7 +228,7 @@ def invoke(action, options = { :soap_action => :auto, :http_options => nil }, &b
if options[:soap_header]
iterate_hash_array(header, options[:soap_header])
end

if options[:soap_body]
action_hash = { action => options[:soap_body] }
iterate_hash_array(body, action_hash)
Expand Down Expand Up @@ -391,7 +391,7 @@ def on_missing_document(response)
def debug(message = nil) #:nodoc:
if @@logger
if message
@@logger.puts(message)
@@logger.info(message)
end
if block_given?
yield @@logger
Expand All @@ -408,13 +408,13 @@ def make_http_request(uri, post_body, headers, http_options=nil)
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]
request.set_ssl_verify_mode(http_options[:ssl_verify_mode]) if http_options[:ssl_verify_mode]
end

headers.each do |key, value|
request.add_header(key, value)
end
request.body = post_body
debug do |logger|
logger.puts request.inspect
logger.info request.inspect
end
on_after_create_http_request(request)
request
Expand All @@ -424,7 +424,7 @@ def make_http_request(uri, post_body, headers, http_options=nil)
# There are various stages and hooks for each, so that you can override those in your service classes.
def parse_http_response(response)
debug do |logger|
logger.puts(response.inspect do |body|
logger.info(response.inspect do |body|
Handsoap.pretty_format_envelope(body).chomp
end)
end
Expand Down