Class SOAP::HTTPStreamHandler
In: lib/soap/streamHandler.rb
Parent: StreamHandler

Methods

Included Modules

SOAP

Constants

Client = HTTPAccess2::Client
RETRYABLE = true
Client = SOAP::NetHttpClient
RETRYABLE = false
MAX_RETRY_COUNT = 10

Attributes

client  [R] 
wiredump_file_base  [RW] 

Public Class methods

[Source]

    # File lib/soap/streamHandler.rb, line 83
83:   def initialize(options)
84:     super()
85:     @client = Client.new(nil, "SOAP4R/#{ Version }")
86:     @wiredump_file_base = nil
87:     @charset = @wiredump_dev = nil
88:     @options = options
89:     set_options
90:     @client.debug_dev = @wiredump_dev
91:     @cookie_store = nil
92:     @accept_encoding_gzip = false
93:   end

Public Instance methods

[Source]

     # File lib/soap/streamHandler.rb, line 99
 99:   def accept_encoding_gzip=(allow)
100:     @accept_encoding_gzip = allow
101:   end

[Source]

     # File lib/soap/streamHandler.rb, line 103
103:   def inspect
104:     "#<#{self.class}>"
105:   end

[Source]

     # File lib/soap/streamHandler.rb, line 112
112:   def reset(endpoint_url = nil)
113:     if endpoint_url.nil?
114:       @client.reset_all
115:     else
116:       @client.reset(endpoint_url)
117:     end
118:     @client.save_cookie_store if @cookie_store
119:   end

[Source]

     # File lib/soap/streamHandler.rb, line 107
107:   def send(endpoint_url, conn_data, soapaction = nil, charset = @charset)
108:     conn_data.soapaction ||= soapaction # for backward conpatibility
109:     send_post(endpoint_url, conn_data, charset)
110:   end

[Source]

    # File lib/soap/streamHandler.rb, line 95
95:   def test_loopback_response
96:     @client.test_loopback_response
97:   end

Private Instance methods

[Source]

     # File lib/soap/streamHandler.rb, line 215
215:   def decode_gzip(instring)
216:     unless send_accept_encoding_gzip?
217:       raise HTTPStreamError.new("Gzipped response content.")
218:     end
219:     begin
220:       gz = Zlib::GzipReader.new(StringIO.new(instring))
221:       gz.read
222:     ensure
223:       gz.close
224:     end
225:   end

[Source]

     # File lib/soap/streamHandler.rb, line 211
211:   def send_accept_encoding_gzip?
212:     @accept_encoding_gzip and defined?(::Zlib)
213:   end

[Source]

     # File lib/soap/streamHandler.rb, line 151
151:   def send_post(endpoint_url, conn_data, charset)
152:     conn_data.send_contenttype ||= StreamHandler.create_media_type(charset)
153: 
154:     if @wiredump_file_base
155:       filename = @wiredump_file_base + '_request.xml'
156:       f = File.open(filename, "w")
157:       f << conn_data.send_string
158:       f.close
159:     end
160: 
161:     extra = {}
162:     extra['Content-Type'] = conn_data.send_contenttype
163:     extra['SOAPAction'] = "\"#{ conn_data.soapaction }\""
164:     extra['Accept-Encoding'] = 'gzip' if send_accept_encoding_gzip?
165:     send_string = conn_data.send_string
166:     @wiredump_dev << "Wire dump:\n\n" if @wiredump_dev
167:     begin
168:       retry_count = 0
169:       while true
170:         res = @client.post(endpoint_url, send_string, extra)
171:         if RETRYABLE and HTTP::Status.redirect?(res.status)
172:           retry_count += 1
173:           if retry_count >= MAX_RETRY_COUNT
174:             raise HTTPStreamError.new("redirect count exceeded")
175:           end
176:           endpoint_url = res.header["location"][0]
177:           puts "redirected to #{endpoint_url}" if $DEBUG
178:         else
179:           break
180:         end
181:       end
182:     rescue
183:       @client.reset(endpoint_url)
184:       raise
185:     end
186:     @wiredump_dev << "\n\n" if @wiredump_dev
187:     receive_string = res.content
188:     if @wiredump_file_base
189:       filename = @wiredump_file_base + '_response.xml'
190:       f = File.open(filename, "w")
191:       f << receive_string
192:       f.close
193:     end
194:     case res.status
195:     when 405
196:       raise PostUnavailableError.new("#{ res.status }: #{ res.reason }")
197:     when 200, 500
198:       # Nothing to do.
199:     else
200:       raise HTTPStreamError.new("#{ res.status }: #{ res.reason }")
201:     end
202:     if res.respond_to?(:header) and !res.header['content-encoding'].empty? and
203:         res.header['content-encoding'][0].downcase == 'gzip'
204:       receive_string = decode_gzip(receive_string)
205:     end
206:     conn_data.receive_string = receive_string
207:     conn_data.receive_contenttype = res.contenttype
208:     conn_data
209:   end

[Source]

     # File lib/soap/streamHandler.rb, line 145
145:   def set_cookie_store_file(value)
146:     value = nil if value and value.empty?
147:     @cookie_store = value
148:     @client.set_cookie_store(@cookie_store) if @cookie_store
149:   end

[Source]

     # File lib/soap/streamHandler.rb, line 123
123:   def set_options
124:     HTTPConfigLoader.set_options(@client, @options)
125:     @charset = @options["charset"] || XSD::Charset.xml_encoding_label
126:     @options.add_hook("charset") do |key, value|
127:       @charset = value
128:     end
129:     @wiredump_dev = @options["wiredump_dev"]
130:     @options.add_hook("wiredump_dev") do |key, value|
131:       @wiredump_dev = value
132:       @client.debug_dev = @wiredump_dev
133:     end
134:     set_cookie_store_file(@options["cookie_store_file"])
135:     @options.add_hook("cookie_store_file") do |key, value|
136:       set_cookie_store_file(value)
137:     end
138:     ssl_config = @options["ssl_config"]
139:     basic_auth = @options["basic_auth"]
140:     @options.lock(true)
141:     ssl_config.unlock
142:     basic_auth.unlock
143:   end

[Validate]