lib/savon/request.rb in savon-xaop-0.7.2.6 vs lib/savon/request.rb in savon-xaop-0.7.2.7
- old
+ new
@@ -79,15 +79,28 @@
def ntlm_auth(username, password)
@ntlm_auth = [username, password, true]
end
# Retrieves WSDL document and returns the Net::HTTP response.
- def wsdl
+ def wsdl(retries = 0)
log "Retrieving WSDL from: #{@endpoint}"
http.endpoint @endpoint.host, @endpoint.port
http.use_ssl = @endpoint.ssl?
- http.start { |h| h.request request(:wsdl) }
+ response = http.start { |h| h.request request(:wsdl) }
+ case response
+ when Net::HTTPFound, Net::HTTPMovedPermanently
+ puts "REDIRECT: #{@endpoint} -> #{response["location"]}"
+ @endpoint = URI response["location"]
+ if retries == 10
+ raise Savon::HTTPError.new("Redirect too long", {})
+ end
+ wsdl(retries + 1)
+ when Net::HTTPSuccess
+ response
+ else
+ raise Savon::HTTPError.new(response.body.to_s, response.to_hash)
+ end
end
# Executes a SOAP request using a given Savon::SOAP instance and
# returns the Net::HTTP response.
def soap(soap)
@@ -131,10 +144,10 @@
when :soap then Net::HTTP::Post.new @soap.endpoint.to_s, headers.merge(soap_headers)
end
if @basic_auth
request.basic_auth *@basic_auth
elsif @ntlm_auth
- log "Using NTLM authentication"
+ require 'kconv'
require 'net/ntlm_http'
request.ntlm_auth *@ntlm_auth
end
yield request if block_given?
request