Skip to content

Instantly share code, notes, and snippets.

@razum2um
Last active October 31, 2019 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save razum2um/80a1636b376e62bf42c5d781337846a0 to your computer and use it in GitHub Desktop.
Save razum2um/80a1636b376e62bf42c5d781337846a0 to your computer and use it in GitHub Desktop.
rubyjedi-soap4r => No "warning: constant ::Fixnum is deprecated"

Proper SOAP support on newest rubies

TLDR: let's replace rubyjedi-soap4r with soap4r-ng

If someone requires latest atm rubyjedi-soap4r https://rubygems.org/gems/rubyjedi-soap4r/versions/2.0.2.1 he sees the warning:

...gems/rubyjedi-soap4r-2.0.2.1/lib/soap/mapping/encodedregistry.rb:149: warning: constant ::Fixnum is deprecated

About a year ago I fixed this in the upstream git repository: rubyjedi/soap4r#21

This eliminates the warning and removes Fixnum usage

The author merged the change but released another gem! https://rubygems.org/gems/soap4r-ng/versions/2.0.4

Also see my comment-reminder about the need to bump rubyjedi-soap4r as well, but no reaction so far.

As gems at rubygems cannot depend on github sha, I suggest to just swap rubyjedi-soap4r with soap4r-ng

Any difference bewteen rubyjedi-soap4r and soap4r-ng

TLDR: no significant difference. safe, in-place replacement, besides 2 dependencies

Don't know why such code:

require 'logger-application' unless defined?(Logger::Application)

but soap4r-ng declared no dependencies explicitly. ¯_(ツ)_/¯ let's add them manyally

besides, no code differs:

  • I extracted both gem contents
  • applied my diff inside lib folder (see 21.diff)
  • diff rubyjedi-soap4r-2.0.2.1 soap4r-ng-2.0.4 shows following:
diff --git rubyjedi-soap4r-2.0.2.1/lib/soap/rpc/httpserver.rb soap4r-ng-2.0.4/lib/soap/rpc/httpserver.rb
index 3190644..37d6390 100644
--- rubyjedi-soap4r-2.0.2.1/lib/soap/rpc/httpserver.rb
+++ soap4r-ng-2.0.4/lib/soap/rpc/httpserver.rb
@@ -41,6 +41,7 @@ class HTTPServer < Logger::Application
     @router = ::SOAP::RPC::Router.new(actor)
     @soaplet = ::SOAP::RPC::SOAPlet.new(@router)
     on_init
+
     @server = WEBrick::HTTPServer.new(@webrick_config)
     @server.mount('/soaprouter', @soaplet)
     if wsdldir = config[:WSDLDocumentDirectory]
@@ -58,7 +59,13 @@ class HTTPServer < Logger::Application
   end

   def shutdown
-    @server.shutdown if @server
+    if @server
+      @server.shutdown
+      while (@server.listeners.length > 0) && (@server.tokens.length > 0) && (@server.status != :Stop)
+        sleep(0.25)
+      end
+      sleep(0.25) # One more for good measure.
+    end
   end

   def authenticator
diff --git rubyjedi-soap4r-2.0.2.1/lib/soap/version.rb soap4r-ng-2.0.4/lib/soap/version.rb
index e70cc67..19fff82 100644
--- rubyjedi-soap4r-2.0.2.1/lib/soap/version.rb
+++ soap4r-ng-2.0.4/lib/soap/version.rb
@@ -3,7 +3,7 @@ module SOAP
   module VERSION #:nodoc:
     MAJOR = 2
     MINOR = 0
-    TINY  = 3
+    TINY  = 4
     STRING = [MAJOR, MINOR, TINY].join('.')

     FORK  = "SOAP4R-NG"
diff --git a/lib/soap/mapping/encodedregistry.rb b/lib/soap/mapping/encodedregistry.rb
index c948e15c..7be73985 100644
--- a/lib/soap/mapping/encodedregistry.rb
+++ b/lib/soap/mapping/encodedregistry.rb
@@ -6,6 +6,11 @@
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.
+# in 2.4, 2.5 Fixnum/Bignum aliased to 'Integer'
+FixnumShim = 1.class
+FIXNUM_PRESENT = FixnumShim.name == 'Fixnum'
+BignumShim = (10**20).class
+BIGNUM_PRESENT = BignumShim.name == 'Bignum'
require 'soap/baseData'
require 'soap/mapping/mapping'
@@ -122,7 +127,7 @@ def find_mapped_obj_class(target_soap_class)
StringFactory = StringFactory_.new
BasetypeFactory = BasetypeFactory_.new
- FixnumFactory = FixnumFactory_.new
+ FixnumFactory = FixnumFactory_.new if FIXNUM_PRESENT
DateTimeFactory = DateTimeFactory_.new
ArrayFactory = ArrayFactory_.new
Base64Factory = Base64Factory_.new
@@ -146,7 +151,6 @@ def find_mapped_obj_class(target_soap_class)
{:derived_class => true}],
[::Float, ::SOAP::SOAPFloat, BasetypeFactory,
{:derived_class => true}],
- [::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
[::Integer, ::SOAP::SOAPInt, BasetypeFactory,
{:derived_class => true}],
[::Integer, ::SOAP::SOAPLong, BasetypeFactory,
@@ -199,6 +203,8 @@ def find_mapped_obj_class(target_soap_class)
{:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
]
+ SOAPBaseMap << [FixnumShim, ::SOAP::SOAPInt, FixnumFactory] if FIXNUM_PRESENT
+
RubyOriginalMap = [
[::NilClass, ::SOAP::SOAPNil, BasetypeFactory],
[::TrueClass, ::SOAP::SOAPBoolean, BasetypeFactory],
@@ -212,7 +218,6 @@ def find_mapped_obj_class(target_soap_class)
{:derived_class => true}],
[::Float, ::SOAP::SOAPFloat, BasetypeFactory,
{:derived_class => true}],
- [::Fixnum, ::SOAP::SOAPInt, FixnumFactory],
[::Integer, ::SOAP::SOAPInt, BasetypeFactory,
{:derived_class => true}],
[::Integer, ::SOAP::SOAPLong, BasetypeFactory,
@@ -263,6 +268,8 @@ def find_mapped_obj_class(target_soap_class)
{:type => XSD::QName.new(RubyCustomTypeNamespace, "SOAPException")}],
]
+ RubyOriginalMap << [FixnumShim, ::SOAP::SOAPInt, FixnumFactory] if FIXNUM_PRESENT
+
attr_accessor :default_factory
attr_accessor :excn_handler_obj2soap
attr_accessor :excn_handler_soap2obj
@@ -411,7 +418,10 @@ def addextend2obj(obj, attr)
end
def addextend2soap(node, obj)
- return if [Symbol, Fixnum, Bignum, Float].any?{ |c| obj.is_a?(c) }
+ return if [Symbol, Integer, Float].any?{ |c| obj.is_a?(c) }
+ return if FIXNUM_PRESENT && obj.is_a?(FixnumShim)
+ return if BIGNUM_PRESENT && obj.is_a?(BignumShim)
+ return if obj.is_a?(String) && obj.frozen?
list = (class << obj; self; end).ancestors - obj.class.ancestors
list = list.reject{|c| c.class == Class } ## As of Ruby 2.1 Singleton Classes are now included in the ancestry. Need to filter those out here.
diff --git a/lib/soap/mapping/rubytypeFactory.rb b/lib/soap/mapping/rubytypeFactory.rb
index e6b04947..21e17eea 100644
--- a/lib/soap/mapping/rubytypeFactory.rb
+++ b/lib/soap/mapping/rubytypeFactory.rb
@@ -6,6 +6,10 @@
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any later version.
+old_verbose, $VERBOSE = $VERBOSE, nil # silence warnings
+DATA_PRESENT = defined?(Data)
+DataShim = Kernel.const_get('Data') if DATA_PRESENT
+$VERBOSE = old_verbose
module SOAP
module Mapping
@@ -38,6 +42,7 @@ def initialize(config = {})
def obj2soap(soap_class, obj, info, map)
param = nil
+
case obj
when ::String
unless @allow_original_mapping
@@ -193,7 +198,7 @@ def obj2soap(soap_class, obj, info, map)
param.add('member', ele_member)
addiv2soapattr(param, obj, map)
end
- when ::IO, ::Binding, ::Data, ::Dir, ::File::Stat,
+ when ::IO, ::Binding, DataShim, ::Dir, ::File::Stat,
::MatchData, Method, ::Proc, ::Process::Status, ::Thread,
::ThreadGroup, ::UnboundMethod
return nil
diff --git a/lib/soap/property.rb b/lib/soap/property.rb
index 6cf74577..dc10d1de 100644
--- a/lib/soap/property.rb
+++ b/lib/soap/property.rb
@@ -33,7 +33,9 @@ module SOAP
# aaa.hhh = iii
#
class Property
- FrozenError = (RUBY_VERSION >= "1.9.0") ? RuntimeError : TypeError
+ unless defined?(FrozenError) # defined since 2.5
+ FrozenError = (RUBY_VERSION >= "1.9.0") ? RuntimeError : TypeError
+ end
include Enumerable
@@ -327,4 +329,4 @@ def loadstr(str)
end
-end
\ No newline at end of file
+end
diff --git a/lib/soap/rpc/cgistub.rb b/lib/soap/rpc/cgistub.rb
index 89dbda14..51938fdb 100644
--- a/lib/soap/rpc/cgistub.rb
+++ b/lib/soap/rpc/cgistub.rb
@@ -202,7 +202,7 @@ def set_fcgi_request(request)
HTTPVersion = WEBrick::HTTPVersion.new('1.0') # dummy; ignored
def run
- res = WEBrick::HTTPResponse.new({:HTTPVersion => HTTPVersion})
+ res = WEBrick::HTTPResponse.new({:HTTPVersion => HTTPVersion, :Logger => logger})
begin
@log.info { "received a request from '#{ @remote_host }'" }
if @fcgi
@@ -227,9 +227,12 @@ def run
r.send_http_header
buf = res.body
else
- buf = ''
+ # since 2.5 it doesn't work with empty string in WEBRICK::HTTPResponse#send_header(socket)
+ # https://github.com/ruby/ruby/commit/c44978b99f0454b8f00674f2f407893c8c47248e
+ buf = StringIO.new
res.send_response(buf)
- buf.sub!(/^[^\r]+\r\n/, '') # Trim status line.
+
+ buf = buf.string.sub(/^[^\r]+\r\n/, '') # Trim status line.
end
@log.debug { "SOAP CGI Response:\n#{ buf }" }
if @fcgi
diff --git a/lib/xsd/xmlparser/oxparser.rb b/lib/xsd/xmlparser/oxparser.rb
index 79cc384b..52bf6068 100644
--- a/lib/xsd/xmlparser/oxparser.rb
+++ b/lib/xsd/xmlparser/oxparser.rb
@@ -28,7 +28,7 @@ def do_parse(string_or_readable)
::Ox.sax_parse(handler, string, {:symbolize=> false, :convert_special=> true, :skip=> :skip_return} )
else
# Use HTMLEntities Decoder. Leave the special-character conversion alone and let HTMLEntities decode it for us.
- ::Ox.sax_parse(handler, string, {})
+ ::Ox.sax_parse(handler, string, {:skip=> :skip_none})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment