@@parser_factory is nil

1 view
Skip to first unread message

jtanium

unread,
Nov 6, 2006, 12:49:54 PM11/6/06
to soap4r
I'm trying to generate the client code for a web service, and keep
running into this problem:

~/temp$ wsdl2ruby.rb --wsdl query.wsdl --type client
F, [2006-11-06T10:16:03.544373 #23107] FATAL -- app: Detected an
exception. Stopping ... undefined method `new' for nil:NilClass
(NoMethodError)
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/xsd/xmlparser/parser.rb:33:in
`create_parser'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/xsd/xmlparser.rb:17:in
`create_parser'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/parser.rb:53:in
`initialize'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/importer.rb:29:in
`parse'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/xmlSchema/importer.rb:30:in
`import'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/importer.rb:18:in
`import'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/soap/wsdl2ruby.rb:190:in
`import'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/soap/wsdl2ruby.rb:34:in
`run'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/bin/wsdl2ruby.rb:44:in
`run'
/usr/lib/ruby/1.8/logger.rb:668:in `start'
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/bin/wsdl2ruby.rb:131
/usr/bin/wsdl2ruby.rb:18
I, [2006-11-06T10:16:03.544758 #23107] INFO -- app: End of app.
(status: -1)

Here's the code from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/xsd/xmlparser/parser.rb:

26 @@parser_factory = nil
27
28 def self.factory
29 @@parser_factory
30 end
31
32 def self.create_parser(host, opt = {})
33 @@parser_factory.new(host, opt)
34 end
35
36 def self.add_factory(factory)
37 if $DEBUG
38 puts "Set #{ factory } as XML processor."
39 end
40 @@parser_factory = factory
41 end

When it comes to Ruby, I'm a n00b. Obviously, the problem here is that
'@@parser_factory' is nil, my question is: why? I'm hoping someone can
point me in the right direction.

shaper

unread,
Nov 6, 2006, 6:55:37 PM11/6/06
to soap4r
This is due to a bug in the way rubygems overloads 'require', which
breaks the way soap4r tries to auto-detect the right xml parser to use.
I've reported the bug and example code demonstrating the issue here:

http://rubyforge.org/tracker/?func=detail&aid=6264&group_id=126&atid=575

The latest soap4r code in subversion fixes this. I believe NaHi is
planning to update the gem soon.

To patch it yourself in the meantime you can either use the latest
subversion code (see http://dev.ctor.org/soap4r for instructions on
checking it out) or try applying this diff to your code. Finding gem
code can be tricky, mine is under:

/site/ruby/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib

but by default it probably ends up in /usr/local/lib/ruby/...
somewhere.

Below is the patch, hope this helps.

- Walter Korman -- http://www.lemurware.com

[3:53pm] lemur:~/workspace/soap4r > svn diff -r 1746:1747
Index: lib/xsd/xmlparser.rb
===================================================================
--- lib/xsd/xmlparser.rb (revision 1746)
+++ lib/xsd/xmlparser.rb (revision 1747)
@@ -51,6 +51,12 @@
].each do |lib|
begin
require lib
+ # XXX: for a workaround of rubygems' require inconsistency
+ # XXX: MUST BE REMOVED IN THE FUTURE
+ name = lib.sub(/^.*\//, '')
+ raise LoadError unless XSD::XMLParser.constants.find { |c|
+ c.downcase == name
+ }
loaded = true
break
rescue LoadError
Index: lib/xsd/xmlparser/parser.rb
===================================================================
--- lib/xsd/xmlparser/parser.rb (revision 1746)
+++ lib/xsd/xmlparser/parser.rb (revision 1747)
@@ -22,6 +22,7 @@
class UnknownAttributeError < FormatDecodeError; end
class UnexpectedElementError < FormatDecodeError; end
class ElementConstraintError < FormatDecodeError; end
+ class ParserError < ParseError; end

@@parser_factory = nil

@@ -30,6 +31,9 @@
end

def self.create_parser(host, opt = {})

+ unless @@parser_factory
+ raise ParserError.new("illegal XML parser configuration")
+ end
@@parser_factory.new(host, opt)
end

@@ -59,7 +63,7 @@
private

def do_parse(string_or_readable)
- raise NotImplementError.new(
+ raise ParserError.new(
'Method do_parse must be defined in derived class.')
end

Sylvain

unread,
Nov 9, 2006, 8:49:26 AM11/9/06
to soap4r
hi,
I had the same problem. At first I was using vanilla ruby 1.8.4 but -
create_rpc_driver is not defined so I installed soap4r gem
now since reading this thread I applied the patch but I'm still
getting the error .
btw http://dev.ctor.org/soap4r is down, so no chance to get the latest
svn for a check.
Is there any library to upgrade, when installing soap4r gem ?

The ruby code I used was someone's code found in another forum :
#!/usr/bin/ruby
t = Time.now
starter = Time.local(t.year,t.mon, t.day) + (24 *3600)
ender = starter + 7 * 24 *3600
lat = 40.352039
lon = -74.191961

require 'soap/wsdlDriver'

params = {:maxt => false, :mint => false, :temp => true, :dew => false,
:pop12 => false, :qpf => false, :sky => false, :snow => false,
:wspd => false, :wdir => false, :wx => false, :waveh => false,
:icons => false, :rh => false, :appt => true}

wsdl = "http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl"
drv = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_driver
drv.wiredump_dev = STDOUT if $DEBUG
dwml = drv.NDFDgen(lat, lon, 'time-series', starter, ender, params)

execution went :

/usr/lib/ruby/1.8/xsd/xmlparser/parser.rb:33:in `create_parser':


undefined method `new' for nil:NilClass (NoMethodError)

from /usr/lib/ruby/1.8/xsd/xmlparser.rb:17:in `create_parser'
from /usr/lib/ruby/1.8/wsdl/parser.rb:53:in `initialize'
from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/importer.rb:29:in
`new'
from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/importer.rb:29:in
`parse'
from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/xmlSchema/importer.rb:30:in
`import'
from
/usr/lib/ruby/gems/1.8/gems/soap4r-1.5.5.20061022/lib/wsdl/importer.rb:18:in
`import'
from /usr/lib/ruby/1.8/soap/wsdlDriver.rb:73:in `import'
from /usr/lib/ruby/1.8/soap/wsdlDriver.rb:37:in `initialize'
from ./time.rb:16:in `new'
from ./time.rb:16

shaper

unread,
Nov 12, 2006, 12:54:28 AM11/12/06
to soap4r
Make sure you have:

require 'rubygems'
require_gem 'soap4r'

at the top of your script, so that you explicitly set up soap4r earlier
in your ruby load path than the older version you already have in your
path that shipped with ruby.

And you do need to apply the patch mentioned earlier in this thread to
the soap4r code wherever it gets installed on your system. On mine
it's in:

/usr/local/lib/ruby/gems/1.8/gems

FYI http://dev.ctor.org/soap4r is up and working right now.

- Walter Korman -- http://www.lemurware.com

Reply all
Reply to author
Forward
0 new messages