On Wed, Feb 28, 2007 at 07:08:32AM +0900, Ben J. wrote:
soap = SOAP::WSDLDriverFactory.new(“some url”).create_rpc_driver
soap.wiredump_file_base = “soapfile”
response = soap.GetWhatever(:whatever => "whatever)
Ironically, when reading the response it doesn’t dump it into the file
until it gets the entire response into memory, this is what’s killing my
server. Is there a more efficient way of doing this?
You just want to get the whole response into a file? Then I’d suggest:
build the SOAP XML request as a string
connect to the server using HTTP
post the XML you built in step 1
read the response as a stream and write it to a file.
To get the response as a stream, you can probably still use Net::HTTP
this. If the response from the server is chunked (use tcpdump to check
this), you can call HTTPResponse#read_body with a block, and you will
the chunks passed to you in turn. The following example is given in the
# using block
response.read_body do |str| # read body now
If the response is not chunked, then just pull out the @socket from the
object and read(65536) it in a loop.
If you want to parse the response on the fly, then you could use rexml
stream parsing mode: see
scroll down to “Stream Parsing”
You then may need an IO.pipe or similar object which accepts the HTTP
on one side and gives a readable stream on the other.
But this may still be a problem if your 5GB response consists mainly of
single element, …5GB of data…. I’m not sure if
REXML will call text() with blocks, or will try to slurp the whole 5GB
before calling text() once.