class SOAP::HTTPStreamHandler
Constants
- Client
- MAX_RETRY_COUNT
- RETRYABLE
Attributes
client[R]
wiredump_file_base[RW]
Public Class Methods
create(options)
click to toggle source
# File lib/soap/streamHandler.rb, line 140 def self.create(options) new(options) end
new(options)
click to toggle source
Calls superclass method
SOAP::StreamHandler::new
# File lib/soap/streamHandler.rb, line 144 def initialize(options) super() if Client == HTTPClient && SHARED_HTTPCLIENT @client = SHARED_HTTPCLIENT else @client = Client.new(nil, SOAP::VERSION::FORK_STRING) end if @client.respond_to?(:request_filter) @client.request_filter << HttpPostRequestFilter.new(@filterchain) end @wiredump_file_base = nil @charset = @wiredump_dev = nil @options = options set_options @client.debug_dev = @wiredump_dev @cookie_store = nil @accept_encoding_gzip = false end
Public Instance Methods
accept_encoding_gzip=(allow)
click to toggle source
# File lib/soap/streamHandler.rb, line 167 def accept_encoding_gzip=(allow) @accept_encoding_gzip = allow end
inspect()
click to toggle source
# File lib/soap/streamHandler.rb, line 171 def inspect "#<#{self.class}>" end
reset(url = nil)
click to toggle source
# File lib/soap/streamHandler.rb, line 181 def reset(url = nil) if url.nil? @client.reset_all else @client.reset(url) end @client.save_cookie_store if @cookie_store end
send(url, conn_data, charset = @charset)
click to toggle source
# File lib/soap/streamHandler.rb, line 175 def send(url, conn_data, charset = @charset) conn_data = send_post(url, conn_data, charset) @client.save_cookie_store if @cookie_store conn_data end
test_loopback_response()
click to toggle source
# File lib/soap/streamHandler.rb, line 163 def test_loopback_response @client.test_loopback_response end
Private Instance Methods
decode_gzip(instring)
click to toggle source
# File lib/soap/streamHandler.rb, line 292 def decode_gzip(instring) unless send_accept_encoding_gzip? raise HTTPStreamError.new("Gzipped response content.") end begin gz = Zlib::GzipReader.new(StringIO.new(instring)) gz.read ensure gz.close end end
send_accept_encoding_gzip?()
click to toggle source
# File lib/soap/streamHandler.rb, line 288 def send_accept_encoding_gzip? @accept_encoding_gzip and defined?(::Zlib) end
send_post(url, conn_data, charset)
click to toggle source
# File lib/soap/streamHandler.rb, line 223 def send_post(url, conn_data, charset) conn_data.send_contenttype ||= StreamHandler.create_media_type(charset) if @wiredump_file_base filename = @wiredump_file_base + '_request.xml' f = File.open(filename, "w") f << conn_data.send_string f.close end extheader = {} extheader['Content-Type'] = conn_data.send_contenttype extheader['SOAPAction'] = "\"#{ conn_data.soapaction }\"" extheader['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip? send_string = conn_data.send_string @wiredump_dev << "Wire dump:\n\n" if @wiredump_dev begin retry_count = 0 while true res = @client.post(url, send_string, extheader) if RETRYABLE and HTTP::Status.redirect?(res.status) retry_count += 1 if retry_count >= MAX_RETRY_COUNT raise HTTPStreamError.new("redirect count exceeded") end url = res.header["location"][0] puts "redirected to #{url}" if $DEBUG else break end end rescue @client.reset(url) raise end @wiredump_dev << "\n\n" if @wiredump_dev receive_string = res.content if @wiredump_file_base filename = @wiredump_file_base + '_response.xml' f = File.open(filename, "w") f << receive_string f.close end case res.status when 405 raise PostUnavailableError.new("#{ res.status }: #{ res.reason }") when 200, 202, 500 # Nothing to do. 202 is for oneway service. else raise HTTPStreamError.new("#{ res.status }: #{ res.reason }") end # decode gzipped content, if we know it's there from the headers if res.respond_to?(:header) and !res.header['content-encoding'].empty? and res.header['content-encoding'][0].downcase == 'gzip' receive_string = decode_gzip(receive_string) # otherwise check for the gzip header elsif @accept_encoding_gzip && receive_string[0..1] == "\x1f\x8b" receive_string = decode_gzip(receive_string) end conn_data.receive_string = receive_string conn_data.receive_contenttype = res.contenttype conn_data end
set_options()
click to toggle source
# File lib/soap/streamHandler.rb, line 192 def set_options @options["http"] ||= ::SOAP::Property.new HTTPConfigLoader.set_options(@client, @options["http"]) @charset = @options["http.charset"] || XSD::Charset.xml_encoding_label @options.add_hook("http.charset") do |key, value| @charset = value end @wiredump_dev = @options["http.wiredump_dev"] @options.add_hook("http.wiredump_dev") do |key, value| @wiredump_dev = value @client.debug_dev = @wiredump_dev end set_cookie_store_file(@options["http.cookie_store_file"]) @options.add_hook("http.cookie_store_file") do |key, value| set_cookie_store_file(value) end ssl_config = @options["http.ssl_config"] basic_auth = @options["http.basic_auth"] auth = @options["http.auth"] @options["http"].lock(true) ssl_config.unlock basic_auth.unlock auth.unlock end