Search

Monday, 25 February 2013

Ruby: soap4r - fixing wsdl2ruby for 1.9.3 version

Some time before when I was trying to generate SOAP Ruby client for my project I encountered the problem with soap4r library. The key problem was with Ruby 1.8 and 1.9 versions compatibility. I've found several independent fixes for that:

and many others. But there were problems with getting them work properly. So, I had to dig into the installed gem code to find out what causes the errors. In particular, I'm getting error like:
[2011-06-09T17:16:01.012268 #10104] INFO -- app: Creating class definition. I, 
[2011-06-09T17:16:01.012268 #10104] INFO -- app: Creates file 'SessionServic e.rb'. F, 
[2011-06-09T17:16:01.014268 #10104] FATAL -- app: Detected an exception. Stop ping ... undefined method collect' for # (NoMethodError) C:/Ruby192/lib/ruby/gems/1.9.1/gems/soap4r-1.5.8/lib/xsd/codegen/gensupport.rb:2 39:intrim_eol' 
C:/Ruby192/lib/ruby/gems/1.9.1/gems/soap4r-1.5.8/lib/xsd/codegen/gensupport.rb:2 27:in format' 
C:/Ruby192/lib/ruby/gems/1.9.1/gems/soap4r-1.5.8/lib/xsd/codegen/commentdef.rb:2 7:indump_comment' 
C:/Ruby192/lib/ruby/gems/1.9.1/gems/soap4r-1.5.8/lib/xsd/codegen/classdef.rb:51: in dump' 
C:/Ruby192/lib/ruby/gems/1.9.1/gems/soap4r-1.5.8/lib/wsdl/soap/classDefCreator.r b:118:inblock in dump_complextype' 
C:/Ruby192/lib/ruby/gems/1.9.1/gems/soap4r-1.5.8/lib/wsdl/soap/classDefCreator.r b:116
...
Actually I was interested in wsdl2ruby utility which was needed for SOAP client generation. So, what should be done to make it working?

The above error was caused by the collect method of the String class which was no longer supported by Ruby since 1.9 version. The same problem appeared for the each method. What the solution is? The solution is to replace all occurences of such calls with the ones doing the same but working under 1.9 ruby version. Actually, the collect method returned an array of string characters represented as separate string (ruby doesn't have dedicated char type, all characters are actually strings). But the following instruction works the same way:

str.split('//')
So, if we replace all occurences of String::collect or String::each with the above method we'll get the code doing the same but compatible with 1.9 Ruby version.

It didn't take me too much to fix all errors like that and make wsdl2ruby working for me. So, now I can generate Ruby SOAP client using standard libraries.

No comments:

Post a Comment