Problems transporting nil values using XMLRPC (net/http ?)

Hi all,

I am using XMLRPC in a project that I am currently working on. It seems
that net/http is throwing an error to XMLRPC when I try to transport nil
values between a server and a client.

Although this might seem like a strange thing to be doing - imagine the
following:

def createACustomer
{“name”=>nil, “age”=>nil, “whatever”=>“some default value”}
end

Now - if i call createACustomer() via XMLRPC, the following error is
reported:

/usr/local/lib/ruby/site_ruby/1.6/xmlrpc/client.rb:502:in do_rpc': HTTP-Error: 500 Internal Server Error (RuntimeError) from /usr/local/lib/ruby/site_ruby/1.6/xmlrpc/client.rb:382:incall2’
from /usr/local/lib/ruby/site_ruby/1.6/xmlrpc/client.rb:372:in
call' from /usr/local/lib/ruby/site_ruby/1.6/xmlrpc/client.rb:560:insend’
from /usr/local/lib/ruby/site_ruby/1.6/xmlrpc/client.rb:560:in
`method_missing’
etc etc etc

Having spend a little (15mins) time looking for the problem, I believe
that it is because nil is being sent to the http library (which requires
a string?). Everything works fine if the hash does not contain nil
values.

Some questions:

  1. Am I doing something wrong/have I misread/not read the relevant docs
    carefully enough/is this a faq?
  2. If not, is this a bug (more likely in xmlrpc than in net/http?)
  • I really don’t want to have to fill my hashes with empty strings
    -it will break a lot of existing tests for one thing :-),
    -it will also screw up the database writing (inserting ‘’ instead of
    NULL).
  1. Can anyone point me in the direction of a workaround, or tell me what
    to focus on in order to fix it myself.
  2. If none of the above, should I be looking at an alternative
    client/server protocol (the SOAP stuff for instance?)
  • As a slightly OT point, I would be interested in knowing what other
    people are using (XMLRPC, SOAP, RYO etc) for client/server projects

FYI this is the relevant information from my environment:

ruby 1.6.6 (2002-01-21) [i686-linux]
xmlrpc4r-1_7_13

I will keep investigating, and will post again if i stumble blindly
across a fix

Thanks for any light you can shed,

···


Martin Hart Tel: +44 (0) 1582 618468
Arnclan Fax: +44 (0) 1582 619596
Union Street, E-mail: martin@zsdfherg.com
Dunstable, Beds LU6 1EX Web : http://www.arnclan.com

On 12/10/02, 3:28:36 PM, Martin Hart martin@zsdfherg.com wrote regarding
Problems transporting nil values using XMLRPC (net/http ?):

Hi all, (blah blah)

I hate replying to my own questions :slight_smile:

Ignore everything - I see a configuration value for XMLRPC
(ENABLE_NIL_xxx) that will probably solve my problems.

Sorry for the wasted bandwidth

Martin

Hi,

This is a response to your OT.

From: “Martin Hart” martin@zsdfherg.com
Sent: Wednesday, December 11, 2002 12:28 AM

  • As a slightly OT point, I would be interested in knowing what other
    people are using (XMLRPC, SOAP, RYO etc) for client/server projects

case rpcType
when “Ruby/Ruby”
if you.required_speed > Speed::ThresholdExtra
raise NotImplementedError.new(
“proprietary text/bin format over socket”)
else
require ‘drb/drb’
end
when “Ruby/other”, “other/Ruby”
if someone.let(you) { |use| use == “XML” }
if you.favorite === Simplicity::High
require ‘xmlrpc/client’
require ‘xmlrpc/server’
elsif you.favorite === Simplicity::Low # Complexity::High
# you want multi-byte chars as a first-class object, multi-ref object
# graph such as a digraph, user defined class, or etc.
require ‘soap/driver’
require ‘soap/cgiStub’
else
raise NotImplementedError.new(
“proprietary XML wire format over some protocol(BEEP?)”)
end
elsif !you.like?(“XML”)
require ‘yaml’
else
require ‘http-access2’
p HTTPClient.new.getContent(
http://rrr.jin.gr.jp/rwiki?cmd=view;name=Marshal”)
raise NoMethodError.new(
“You have to choose one of it or implement yourself.”)
end
else
raise TypeError.new(“Ruby is required here.”)
end

Regards,
// NaHi

In my opinion, definitely not a waste – someone else may have the same
question and appreciate you’re solution.

···

On Tuesday, December 10, 2002, at 10:35 AM, Martin Hart wrote:

On 12/10/02, 3:28:36 PM, Martin Hart martin@zsdfherg.com wrote
regarding
Problems transporting nil values using XMLRPC (net/http ?):

Hi all, (blah blah)

I hate replying to my own questions :slight_smile:

Ignore everything - I see a configuration value for XMLRPC
(ENABLE_NIL_xxx) that will probably solve my problems.

Sorry for the wasted bandwidth

Martin

Martin Hart martin@zsdfherg.com writes:

On 12/10/02, 3:28:36 PM, Martin Hart martin@zsdfherg.com wrote regarding
Problems transporting nil values using XMLRPC (net/http ?):

Hi all, (blah blah)

I hate replying to my own questions :slight_smile:

Ignore everything - I see a configuration value for XMLRPC
(ENABLE_NIL_xxx) that will probably solve my problems.

Sorry for the wasted bandwidth

No it is not, don’t worry :slight_smile:

Don’t forget that NIL/NULL values are not part of the XML-RPC
spec. I know that some implementations support them, but since
there is no official way to pass them, your code could break
when used with other servers or clients.

S.

if someone.let(you) { |use| use == “XML” }

Favorite line!

elsif !you.like?(“XML”)
require ‘yaml’

  require 'okay/rpc' if you.read( "http://wiki.yaml.org/yamlwiki/OkayRpcProtocol" )

Comes with yaml.rb. If you have yaml.rb, you can check out the demo
server via irb:

require ‘okay/rpc’
==>true
c = Okay::RPC::Client.new( ‘whytheluckystiff.net’ )
==>#<Okay::RPC::Client:0x401ec8c0 @create=nil, @port=80,
@http=#<Net::HTTP whytheluckystiff.net:80 open=false>, @timeout=30,
@path=“/okayRpc/”, @parser=nil, @auth=nil, @use_ssl=false,
@password=nil, @host=“whytheluckystiff.net”, @proxy_port=nil, @user=nil,
@queue=#<YAML::Stream:0x401ec758 @options={:UseHeader=>true},
@documents=>, @proxy_host=nil>
c.call( ‘system.listMethods’ )
==>[“currentTime.getCurrentTime”, “examples.addtwo”,
“examples.addtwofloat”, “examples.base64”, “examples.echo”,
“examples.getStateName”, “examples.invertBooleans”,
“examples.sortByAge”, “examples.stringecho”, “system.about”,
“system.getCapabilities”, “system.listMethods”, “system.methodBlank”,
“system.methodHelp”, “system.methodSignature”]
c.call( ‘system.methodHelp’, ‘system.about’ )
==>“Provides a short description of this !okay/rpc server’s intent.”

Yep.

_why

···

NAKAMURA, Hiroshi (nahi@keynauts.com) wrote:

regarding Re: Problems transporting nil values using XMLRPC (net/http ?):

Hi,

This is a response to your OT.

[snip snip]

Thanks very much for the information, sorry for delay in posting back -
can’t keep up with the volume of traffic on the list :slight_smile:

I think you make the point clearly that Ruby allows me to be pretty
flexible in this regard - which is sort of what I expected when I
implemented everything in a single process before thinking too much about
how to make it client/server.

Cheers,

Martin

···

On 12/11/02, 4:59:47 AM, “NAKAMURA, Hiroshi” nahi@keynauts.com wrote

regarding Re: Problems transporting nil values using XMLRPC (net/http ?):

Don’t forget that NIL/NULL values are not part of the XML-RPC
spec. I know that some implementations support them, but since
there is no official way to pass them, your code could break
when used with other servers or clients.

Ah, I didn’t know that - I’d better go and read the spec :slight_smile:

Given that I ought not to be doing this as it is “non-standard”, I can
see only two solutions:

  1. Don’t send null values - rely on the fact that if a value is “missing”
    then it is NULL.
  2. Encode null values in some other way - e.g. “NULL” - which is really
    messy and will likely break :slight_smile:

1 looks best but unfortunately breaks a load of existing test cases :frowning:

I am not all that hot on this rpc type technology. Can anybody see any
alternatives (perhaps some other protocol supports the transportation of
null values SOAP ??)

TIA

···

On 12/11/02, 3:36:17 AM, Stefan Arentz stefan.arentz@soze.com wrote


Martin Hart Tel: +44 (0) 1582 618468
Arnclan Fax: +44 (0) 1582 619596
Union Street, E-mail: martin@zsdfherg.com
Dunstable, Beds LU6 1EX

Hi, _why,

From: why the lucky stiff [mailto:ruby-talk@whytheluckystiff.net]
Sent: Wednesday, December 11, 2002 2:16 PM

if someone.let(you) { |use| use == “XML” }

Favorite line!

elsif !you.like?(“XML”)
require ‘yaml’

  require 'okay/rpc' if you.read( 

http://wiki.yaml.org/yamlwiki/OkayRpcProtocol” )

Sure.

By the way, what does Okay stand for?

Regards,
// NaHi

···

NAKAMURA, Hiroshi (nahi@keynauts.com) wrote:

Hi,

From: Martin Hart [mailto:martin@zsdfherg.com]
Sent: Thursday, December 12, 2002 7:23 AM

I am not all that hot on this rpc type technology. Can
anybody see any
alternatives (perhaps some other protocol supports the
transportation of
null values SOAP ??)

$ ruby -rsoap/marshal -e ‘puts SOAPMarshal.dump(nil)’

<?xml version="1.0" encoding="utf-8" ?>

<env:Envelope
xmlns:xsd=“http://www.w3.org/2001/XMLSchema
xmlns:env=“http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>
env:Body


</env:Body>
</env:Envelope>

$ ruby -rsoap/marshal -e ‘puts SOAPMarshal.load(SOAPMarshal.dump(nil))’
nil

$ ruby -ryaml -e ‘puts nil.to_yaml’
— ~

$ ruby -ryaml -e ‘puts YAML.load(nil.to_yaml)’
nil

Regards,
// NaHi

Object Kit Across YAML.

It’s a great short word, a YAML type family which will cover a wide
range (a complete kit) of prototype YAML formats. News syndication is
!okay/news, schema is !okay/schema, and so on. Hopefully simple and I
might drop the acronym because sometimes they’re neat but a lot of times
it feels like just another thing to remember.

_why

···

NAKAMURA, Hiroshi (nahi@keynauts.com) wrote:

  require 'okay/rpc' if you.read( 

http://wiki.yaml.org/yamlwiki/OkayRpcProtocol” )

Sure.

By the way, what does Okay stand for?

  1. Encode null values in some other way - e.g. “NULL” - which is really
    messy and will likely break :slight_smile:

I think the standard (as a separate spec extension) way to encode null values is . Check at:

http://www.ontosys.com/xml-rpc/extensions.html

Josu Oyanguren