Store SOAP::RPC::Driver in user session throws TypeError

Hi All

I have a
requirement to consume a 3rd party web service from my Rails
application. I am doing this
in my action

require ‘soap/wsdlDriver’
factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL)
soap = factory.create_rpc_driver
soap.wiredump_file_base="#{RAILS_ROOT}/log/transidiom.log"

param = %(
110
2442
ccvdev2 ccvdev2
ORC wmasprod
)

result = soap…retrieveCustomerData(param)

I get the expected result, but the real problem is performance since I
have
to re-create the rpc-driver to the same service on each request. So I
try
and store the soap object which is SOAP::RPC::Driver type.

session[:soap] = soap

and I get TypeError (singleton can’t be dumped):
C:/ruby/lib/ruby/1.8/pstore.rb:348:in dump' C:/ruby/lib/ruby/1.8/pstore.rb:348:indump’
C:/ruby/lib/ruby/1.8/pstore.rb:326:in transaction' C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:90:inupdate’
C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in close' C:/ruby/lib/ruby/1.8/cgi/session.rb:330:inclose’
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:984:in
`close_session’

Now ofcourse I realize that RPC Driver has some singleton object or
anonymous class/method which can’t be serialized hence the TypeError. My
question is what can I do to improve the performance and reduce the
overhead
of creating new RPC Driver objects on each request.

Thanks
-daya

Ola, this is a Good idea but can it give rise race conditions?? or are
there
anyother implications which might be painful to debug/fix in the long
run?

linux user wrote:

have to re-create the rpc-driver to the same service on each request. So
C:/ruby/lib/ruby/1.8/cgi/session.rb:330:in `close’
-daya



Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

You don’t store the driver itself in the session but in global singleton
objects. That’s the approach I used not long time ago for exactly this
kind of problem.

I just had someting like this in my model class
if @@driver.nil?
@@driver = SoapWsdlDriver.new
end
@@driver.customWebServiceCall


Ola B. (http://ola-bini.blogspot.com)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.

On 8/7/06, linux user [email protected] wrote:

param = %(<Request
have to re-create the rpc-driver to the same service on each request.
C:/ruby/lib/ruby/1.8/cgi/session/pstore.rb:97:in `close’

[email protected]
@@driver.customWebServiceCall


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

I have put the similar code in my ApplicationController … here is the
code

class ApplicationController < ActionController::Base

require ‘soap/wsdlDriver’
factory = SOAP::WSDLDriverFactory.new(TRANSIDIOM_WSDL_URL)
@@soap = factory.create_rpc_driver
@@soap.wiredump_file_base=“#{RAILS_ROOT}/log/transidiom.log”

def …my actions…

I am in Development environment and the problem is that @@soap which
should
be initialized only once (at class instantiation time) is initialized on
every request (I checkd the object_id and they are different on each
request). Being a newbie my guess is that atleast in development env
there
is a new instance of the controller created on every request. So my
question
is in Production env is there only one instance of the controller to
serve
all requests or is there a new instance of controller created on every
request?

thanks in advance
-daya

I know it is very difficult to simulate and identify a race condition.
But
this is what I think may happen if I use class variable or even global
variable to store SOAP::RPC::Driver object.

In production each controller is loaded only once which I assume means
there
is only one instance of controller serving multiple requests. Now lets
assume that all the parameters needed to make the web service call are
local
to the action (method), which means these parameters are immune from
race
conditions since the are on the thread stack and each thread is unique
for
each request. But the class variable or global variable is shared across
multiple requests, now imagine the same class variable or global
variable
accessed in different controllers or different actions of same
controller.
Hence there is a potential that the result of a webservice call may get
mixed up, depending on who gets the returned value first.

I may completely wrong here since I don’t know about the inner working
of
the CGI/FCGI/Rails request handling. Can anyone please enlighten me or
tell
me if my fears are misplaced?

TIA

-daya

linux user wrote:

Ola, this is a Good idea but can it give rise race conditions?? or are
there anyother implications which might be painful to debug/fix in the
long run?

Not that I know of. And there’s no race condition involved if you don’t
have any trouble with having more than one reference to the Driver
floating around, which shouldn’t be a problem.


Ola B. (http://ola-bini.blogspot.com)
JvYAML, RbYAML, JRuby and Jatha contributor
System Developer, Karolinska Institutet (http://www.ki.se)
OLogix Consulting (http://www.ologix.com)

“Yields falsehood when quined” yields falsehood when quined.