XMLRPC and complex data structures 
Author Message
 XMLRPC and complex data structures

Hi all,

Ruby 1.6.7, REXML 2.4.2, Sys/ProcTable 3.1, XML-RPC 1.7.11

I'm getting the dreaded "Internal Server Error" when I try to return an
array of structs within a handler.

Here's the code:

require "xmlrpc/server"
require "sys/proctable"
include Sys

class Test
   def add(a,b)
      a + b
   end

   def ps
      a = []
      a = ProcTable.ps # This fails
      #ProcTable.ps{|struct| a.push(struct.pid)} # This works
      return a
   end
end

server = XMLRPC::Server.new(8889,"1.2.3.4",4,$stdout) # Use a real IP
server.add_handler("test",Test.new)
server.serve

The ProcTable.ps call returns an array of structs in lvalue context, and
that seems to be the problem.  I also tried just returning a list of
pid's and that worked fine.  The "add" method also works fine (I just
threw that in for testing purposes).

Here's the actual client code:

require "xmlrpc/client"

client = XMLRPC::Client.new("1.2.3.4",nil,8889) # Use a real IP

begin
   v = client.call("test.ps")
rescue RuntimeError => e
   puts "Error:"
   puts e.faultCode
   puts e.faultString
rescue XMLRPC::FaultException => e
   puts "Error:"
   puts e.faultCode
   puts e.faultString
end

Here's the RuntimeError message:

Quote:
>ruby xmlrpcClientTest.rb

Error:
xmlrpcClientTest.rb:9: undefined method `faultCode' for
#<RuntimeError:0x15bb30> (NameError)

Any ideas?

Regards,

Dan



Fri, 08 Apr 2005 23:57:45 GMT  
 XMLRPC and complex data structures

Quote:

> Hi all,

> Ruby 1.6.7, REXML 2.4.2, Sys/ProcTable 3.1, XML-RPC 1.7.11

> I'm getting the dreaded "Internal Server Error" when I try to return an
> array of structs within a handler.

> Here's the code:

> require "xmlrpc/server"
> require "sys/proctable"
> include Sys

> class Test
>    def add(a,b)
>       a + b
>    end

>    def ps
>       a = []
>       a = ProcTable.ps # This fails
>       #ProcTable.ps{|struct| a.push(struct.pid)} # This works
>       return a
>    end
> end

> server = XMLRPC::Server.new(8889,"1.2.3.4",4,$stdout) # Use a real IP
> server.add_handler("test",Test.new)
> server.serve

Is ProcTable.ps really of type "Struct"? Or is it an object of an
user-defined class?

Does ProcTable.ps return nil under some circumstances.

If that doesn't help, please send me the definition of ProcTable.ps.

- Show quoted text -

Quote:
> The ProcTable.ps call returns an array of structs in lvalue context, and
> that seems to be the problem.  I also tried just returning a list of
> pid's and that worked fine.  The "add" method also works fine (I just
> threw that in for testing purposes).

> Here's the actual client code:

> require "xmlrpc/client"

> client = XMLRPC::Client.new("1.2.3.4",nil,8889) # Use a real IP

> begin
>    v = client.call("test.ps")
> rescue RuntimeError => e
>    puts "Error:"
>    puts e.faultCode
>    puts e.faultString
> rescue XMLRPC::FaultException => e

Should be:

rescue XMLRPC::FaultStructure => e

Quote:
>    puts "Error:"
>    puts e.faultCode
>    puts e.faultString
> end

> Here's the RuntimeError message:

> >ruby xmlrpcClientTest.rb
> Error:
> xmlrpcClientTest.rb:9: undefined method `faultCode' for
> #<RuntimeError:0x15bb30> (NameError)

> Any ideas?

You call faultCode on a RuntimeError! See above.

Regards,

  Michael



Sat, 09 Apr 2005 04:57:30 GMT  
 XMLRPC and complex data structures

<snip>

Quote:
> Is ProcTable.ps really of type "Struct"? Or is it an object of an
> user-defined class?

"ps()" is a class method that returns an array of structs.  Each struct
contains such info as pid, ppid, pgid, etc. This is a C extension, btw.

# This stand-alone example works fine
!/usr/bin/ruby
require 'sys/proctable'
include Sys

# List all pids
a = ProcTable.ps
a.each{ |pstruct| puts pstruct.pid.to_s }

Quote:

> Does ProcTable.ps return nil under some circumstances.

Impossible.  That would mean *no* processes were running.

Quote:

> If that doesn't help, please send me the definition of ProcTable.ps.

The source varies depending on platform (and would be a bit much to post here
anyway), but all platforms return an array of structs.  The struct in
question is called "sProcStruct" and you can view its format within the
Init_proctable() call.

You can find the source at http://www.enteract.com/~mghall/ruby/sys/sys.html

Regards,

Dan

PS - I forgot to mention my platform earlier - Solaris 9



Sat, 09 Apr 2005 05:26:35 GMT  
 XMLRPC and complex data structures
Just to see what would happen with regular Ruby structs (i.e. no extensions), I
tried adding this method to the xmlrpc server:

# Return an array of structs
   def get_aos
      TestStruct = Struct.new("TestStruct",:name,:age)
      dan = TestStruct.new("Dan",32)
      joe = TestStruct.new("Joe",29)
      a = []
      a.push(dan,joe)
      return a
   end

This caused a "dynamic constant assignment" error, and I could only get it to
work if I declared the struct type outside the class.  Could dynamic struct
generation be the source of the problem?  If so, why?

Regards,

Dan



Sat, 09 Apr 2005 05:55:34 GMT  
 XMLRPC and complex data structures

Quote:

> Just to see what would happen with regular Ruby structs (i.e. no extensions), I
> tried adding this method to the xmlrpc server:

> # Return an array of structs
>    def get_aos
>       TestStruct = Struct.new("TestStruct",:name,:age)
>       dan = TestStruct.new("Dan",32)
>       joe = TestStruct.new("Joe",29)
>       a = []
>       a.push(dan,joe)
>       return a
>    end

Simply, don't use a constant:

   def get_aos
      testStruct = Struct.new("TestStruct",:name,:age)
      dan = testStruct.new("Dan",32)
      joe = testStruct.new("Joe",29)
      a = []
      a.push(dan,joe)
      return a
   end

You can also create the structs via Struct::TestStruct.new.

Quote:
> This caused a "dynamic constant assignment" error, and I could only get it to
> work if I declared the struct type outside the class.  Could dynamic struct
> generation be the source of the problem?  If so, why?

This is not a problem, if you don't use constants. See above.
Note that you can also move the struct definition outside the method:

TestStruct = Struct.new("TestStruct",:name,:age)

def get_aos
   dan = TestStruct.new("Dan",32)
   joe = TestStruct.new("Joe",29)
   a = []
   a.push(dan,joe)
   return a
end

Regards,

  Michael



Sat, 09 Apr 2005 12:58:54 GMT  
 XMLRPC and complex data structures
Hi,

Quote:
> From: Daniel Berger
> Sent: Tuesday, October 22, 2002 6:27 AM
> > Is ProcTable.ps really of type "Struct"? Or is it an object of an
> > user-defined class?

> "ps()" is a class method that returns an array of structs.  
> Each struct
> contains such info as pid, ppid, pgid, etc. This is a C
> extension, btw.

Run your xmlrpc standalone server with -d;

ruby -d test_ps_server.rb

Then run the client.  It will dump the reason of
Internal Server Error.
Please show the error message.

I'm wondering it failed marshalling C struct, nil or
Bitnum, etc...

Regards,
// NaHi



Sat, 09 Apr 2005 13:15:26 GMT  
 XMLRPC and complex data structures
<snip>

Quote:

> Run your xmlrpc standalone server with -d;

> ruby -d test_ps_server.rb

> Then run the client.  It will dump the reason of
> Internal Server Error.
> Please show the error message.

> I'm wondering it failed marshalling C struct, nil or
> Bitnum, etc...

> Regards,
> // NaHi

Here's the error message I get:

Quote:
>ruby -d xmlrpcServerTest.rb

/usr/local/lib/ruby/site_ruby/1.6/xmlrpc/utils.rb:116: warning: `&'
interpreted as argument prefix
[Tue Oct 22 07:50:21 2002] HttpServer 151.119.145.36:8889 start
[Tue Oct 22 07:50:34 2002] HttpServer 151.119.145.36:8889 client:38032
my_host<1.2.3.4> connect
in request_handler
Exception `RuntimeError' at
/usr/local/lib/ruby/site_ruby/1.6/xmlrpc/create.rb:179 - Bignum is too
big! Must be signed 32-bit integer!

What do you make of that?

Regards,

Dan



Sat, 09 Apr 2005 21:53:44 GMT  
 XMLRPC and complex data structures
Hi,

Quote:

> Sent: Tuesday, October 22, 2002 10:53 PM
> in request_handler
> Exception `RuntimeError' at
> /usr/local/lib/ruby/site_ruby/1.6/xmlrpc/create.rb:179 - Bignum is too
> big! Must be signed 32-bit integer!

> What do you make of that?

Check if your config.rb
(/usr/local/lib/ruby/site_ruby/1.6/xmlrpc/config.rb or so)
allow you to use big int larger than +2^31.

Normally, XML-RPC spec does now allow you to send
a big integer.  xmlrpc4r does not allow it by default for
interoperability, I think.

Regards,
// NaHi



Sat, 09 Apr 2005 22:33:15 GMT  
 XMLRPC and complex data structures

Quote:

> Hi,


> > Sent: Tuesday, October 22, 2002 10:53 PM

> > in request_handler
> > Exception `RuntimeError' at
> > /usr/local/lib/ruby/site_ruby/1.6/xmlrpc/create.rb:179 - Bignum is too
> > big! Must be signed 32-bit integer!

> > What do you make of that?

> Check if your config.rb
> (/usr/local/lib/ruby/site_ruby/1.6/xmlrpc/config.rb or so)
> allow you to use big int larger than +2^31.

> Normally, XML-RPC spec does now allow you to send
> a big integer.  xmlrpc4r does not allow it by default for
> interoperability, I think.

> Regards,
> // NaHi

That was it!  I had forgotten that was an option in the config.rb file.
Now, to find a faster parser!

Regards,

Dan



Sat, 09 Apr 2005 23:07:19 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Using UNRAR_DLL in LABVIEW6 Complex data structures and DLL calling

2. Does labview 7 allow complex data structures in dll calls

3. using STORABLE to figure out memory usage for a complex data structure

4. Fortran90/C Interface for complex data structures

5. saving complex data structures?

6. Complex C data structures passed to Tcl ?

7. Complex data structures in Tcl/Tk ??

8. How to interface complex data structure

9. Event case loses connection to data structure when data structure is modified

10. GOBO data structure library vs other data structure libraries

11. Losing data on data structure change

12. data structures versus data bases???

 

 
Powered by phpBB® Forum Software