Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > XMLRPC Question

Reply
Thread Tools

XMLRPC Question

 
 
Michael Taras
Guest
Posts: n/a
 
      07-07-2008
I am working on a little project that requires me to interface with an
XMLRPC server they have to grab some data. To first test it, I just
telneted into the server and ran their test function, which was "ping".
It returned a response like so (the server_response area had some
private data so I left it out):

<?xml version="1.0" encoding="UTF-8"?>
<ping>
<CommandStatus>
<code>OK</code>
<transit>0.089925</transit>
</CommandStatus>
<command>
<name>ping</name>
</command>
<server_response>
...just a few strings in here
</server_response>
</ping>


So after that, I set out to see if I could get the same information from
my ruby script, and I wrote the following script:

require 'xmlrpc/client'
require 'pp'

server = XMLRPC::Client.new2("server_info_in_here")
result = server.call("ping")

pp result


However, when I run that script it errors out on the line with
server.call in it. The error that it spits out is:

/usr/local/lib/ruby/1.8/net/http.rb:2019:in `read_status_line': wrong
status line: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
(Net::HTTPBadResponse)
from /usr/local/lib/ruby/1.8/net/http.rb:2006:in `read_new'
from /usr/local/lib/ruby/1.8/net/http.rb:1047:in `request'
from /usr/local/lib/ruby/1.8/net/http.rb:1034:in `request'
from /usr/local/lib/ruby/1.8/net/http.rb:543:in `start'
from /usr/local/lib/ruby/1.8/net/http.rb:1032:in `request'
from /usr/local/lib/ruby/1.8/net/http.rb:989:in `post2'
from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:535:in `do_rpc'
from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:420:in `call2'
from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:410:in `call'
from test.rb:5

Just from my research, it seems that the error is popping up because the
code is trying to match the xml definition line to an HTTP response
code, which of course is not working. My guess is that the server is
not returning any sort of http status, and just the xml, but I'm really
not sure. This is my first time messing with any xmlrpc stuff.

If the problem is easily solvable on my end, that would be awesome. But
if it is something wrong on their end then I can probably get that
fixed, I guess I just need to know exactly what is wrong.

Any help would be greatly appreciated.

Thanks,
Michael
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Eric Hodel
Guest
Posts: n/a
 
      07-07-2008
On Jul 7, 2008, at 15:09 PM, Michael Taras wrote:

> I am working on a little project that requires me to interface with an
> XMLRPC server they have to grab some data. To first test it, I just
> telneted into the server and ran their test function, which was
> "ping".
> It returned a response like so (the server_response area had some
> private data so I left it out):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ping>
> <CommandStatus>
> <code>OK</code>
> <transit>0.089925</transit>
> </CommandStatus>
> <command>
> <name>ping</name>
> </command>
> <server_response>
> ...just a few strings in here
> </server_response>
> </ping>
>
>
> So after that, I set out to see if I could get the same information
> from
> my ruby script, and I wrote the following script:
>
> require 'xmlrpc/client'
> require 'pp'
>
> server = XMLRPC::Client.new2("server_info_in_here")
> result = server.call("ping")
>
> pp result
>
>
> However, when I run that script it errors out on the line with
> server.call in it. The error that it spits out is:
>
> /usr/local/lib/ruby/1.8/net/http.rb:2019:in `read_status_line': wrong
> status line: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
> (Net::HTTPBadResponse)
> from /usr/local/lib/ruby/1.8/net/http.rb:2006:in `read_new'
> from /usr/local/lib/ruby/1.8/net/http.rb:1047:in `request'
> from /usr/local/lib/ruby/1.8/net/http.rb:1034:in `request'
> from /usr/local/lib/ruby/1.8/net/http.rb:543:in `start'
> from /usr/local/lib/ruby/1.8/net/http.rb:1032:in `request'
> from /usr/local/lib/ruby/1.8/net/http.rb:989:in `post2'
> from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:535:in `do_rpc'
> from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:420:in `call2'
> from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:410:in `call'
> from test.rb:5
>
> Just from my research, it seems that the error is popping up because
> the
> code is trying to match the xml definition line to an HTTP response
> code, which of course is not working. My guess is that the server is
> not returning any sort of http status, and just the xml, but I'm
> really
> not sure. This is my first time messing with any xmlrpc stuff.
>
> If the problem is easily solvable on my end, that would be awesome.
> But
> if it is something wrong on their end then I can probably get that
> fixed, I guess I just need to know exactly what is wrong.
>
> Any help would be greatly appreciated.


Alternately, a HEAD request was performed and the server dumped a
content body on it because it handles it the same as GET. I suggest
you break out tcpdump for some closer examination.

 
Reply With Quote
 
 
 
 
Michael Neumann
Guest
Posts: n/a
 
      07-07-2008
Michael Taras wrote:
> I am working on a little project that requires me to interface with an
> XMLRPC server they have to grab some data. To first test it, I just
> telneted into the server and ran their test function, which was "ping".
> It returned a response like so (the server_response area had some
> private data so I left it out):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <ping>
> <CommandStatus>
> <code>OK</code>
> <transit>0.089925</transit>
> </CommandStatus>
> <command>
> <name>ping</name>
> </command>
> <server_response>
> ...just a few strings in here
> </server_response>
> </ping>
>
>
> So after that, I set out to see if I could get the same information from
> my ruby script, and I wrote the following script:
>
> require 'xmlrpc/client'
> require 'pp'
>
> server = XMLRPC::Client.new2("server_info_in_here")
> result = server.call("ping")
>
> pp result
>
>
> However, when I run that script it errors out on the line with
> server.call in it. The error that it spits out is:
>
> /usr/local/lib/ruby/1.8/net/http.rb:2019:in `read_status_line': wrong
> status line: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
> (Net::HTTPBadResponse)
> from /usr/local/lib/ruby/1.8/net/http.rb:2006:in `read_new'
> from /usr/local/lib/ruby/1.8/net/http.rb:1047:in `request'
> from /usr/local/lib/ruby/1.8/net/http.rb:1034:in `request'
> from /usr/local/lib/ruby/1.8/net/http.rb:543:in `start'
> from /usr/local/lib/ruby/1.8/net/http.rb:1032:in `request'
> from /usr/local/lib/ruby/1.8/net/http.rb:989:in `post2'
> from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:535:in `do_rpc'
> from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:420:in `call2'
> from /usr/local/lib/ruby/1.8/xmlrpc/client.rb:410:in `call'
> from test.rb:5
>
> Just from my research, it seems that the error is popping up because the
> code is trying to match the xml definition line to an HTTP response
> code, which of course is not working. My guess is that the server is
> not returning any sort of http status, and just the xml, but I'm really
> not sure. This is my first time messing with any xmlrpc stuff.


I think your analysis is correct. The server is returning the plain XML
and not a HTTP request. Btw, what did you enter in telnet? And what did
you got as a result from telnet?

XML-RPC is usually served via HTTP. IIRC it is even required. If you use
XML-RPC not over HTTP, then you need to fetch the response yourself (you
can use plain sockets) and then invoke the parser on it yourself. But
it's probably easier to take a look at the server, because it's very
uncommon to not use HTTP!

And btw, are you sure that the XML shown above is valid XML-RPC? AFAIK
it's not! Yeah, it's not XML-RPC

Regards,

Michael

 
Reply With Quote
 
Michael Taras
Guest
Posts: n/a
 
      07-08-2008
Michael Neumann wrote:
> Michael Taras wrote:
>> <transit>0.089925</transit>
>> So after that, I set out to see if I could get the same information from
>>
>> from /usr/local/lib/ruby/1.8/net/http.rb:1032:in `request'
>> not sure. This is my first time messing with any xmlrpc stuff.

> I think your analysis is correct. The server is returning the plain XML
> and not a HTTP request. Btw, what did you enter in telnet? And what did
> you got as a result from telnet?
>
> XML-RPC is usually served via HTTP. IIRC it is even required. If you use
> XML-RPC not over HTTP, then you need to fetch the response yourself (you
> can use plain sockets) and then invoke the parser on it yourself. But
> it's probably easier to take a look at the server, because it's very
> uncommon to not use HTTP!
>
> And btw, are you sure that the XML shown above is valid XML-RPC? AFAIK
> it's not! Yeah, it's not XML-RPC
>
> Regards,
>
> Michael



Thank you very much for the response.

So what I entered into telnet was just: <ping></ping>
And I got out exactly what I posted in the original post, which
apparently isn't even valid XML-RPC I will definitely check that
stuff out and see what's up.

In case I'm not able to get anything on the server side changed, how
exactly would i go about making an XML-RPC call using sockets? I'm not
really sure how to encode the xml in the request or anything of that
sort. So some general direction would be greatly appreciated.


@Eric

I broke out tcpdump and examined the request. From what I could tell it
was just an HTTP POST. I really have no experience with tcpdump so I
could have been wrong.


Thanks everyone for all the help so far.

-Michael
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Eric Hodel
Guest
Posts: n/a
 
      07-08-2008
On Jul 7, 2008, at 15:40 PM, Michael Neumann wrote:
> Michael Taras wrote:
>> However, when I run that script it errors out on the line with
>> server.call in it. The error that it spits out is:
>> /usr/local/lib/ruby/1.8/net/http.rb:2019:in `read_status_line': wrong
>> status line: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
>> (Net::HTTPBadResponse)
>>
>> Just from my research, it seems that the error is popping up
>> because the
>> code is trying to match the xml definition line to an HTTP response
>> code, which of course is not working. My guess is that the server is
>> not returning any sort of http status, and just the xml, but I'm
>> really
>> not sure. This is my first time messing with any xmlrpc stuff.

>
> I think your analysis is correct. The server is returning the plain
> XML
> and not a HTTP request. Btw, what did you enter in telnet? And what
> did
> you got as a result from telnet?


I encountered the HEAD problem running RubyGems against a gem
repository on a misconfigured server. The HEAD request would return
ok, but a subsequent GET request would pick up the body that the
misconfigured server had left on the socket, so this second request
would fail.

In this case it would look like the server was sending a body with no
HTTP section, but it was really just left on the socket.

I've never used XML-RPC.

 
Reply With Quote
 
yermej
Guest
Posts: n/a
 
      07-08-2008
On Jul 7, 5:09 pm, Michael Taras <(E-Mail Removed)> wrote:

> Just from my research, it seems that the error is popping up because the
> code is trying to match the xml definition line to an HTTP response
> code, which of course is not working. My guess is that the server is
> not returning any sort of http status, and just the xml, but I'm really
> not sure. This is my first time messing with any xmlrpc stuff.


That seems to be the case - XMLRPC uses HTTP for transport so a
request should be an HTTP POST and a response should have an HTTP
status and HTTP headers (which must include Content-Length and Content-
Type - there can be others too).

> But
> if it is something wrong on their end then I can probably get that
> fixed, I guess I just need to know exactly what is wrong.


As it stands, they haven't correctly implemented the XMLRPC spec.
Point them here http://www.xmlrpc.com/spec for the actual spec. It's
really simple and shouldn't be much work to implement - there's
probably a library in whatever language/environment they're using. As
for specifics, the response isn't a valid HTTP response - they need to
have something like:

HTTP/1.1 200 OK
Content-Length: 32
Content-Type: text/xml

<?xml version="1.0"?>
<methodResponse>
<params>
<param>
...
</methodResponse>

A valid request would be something like (the headers shown are
required):

POST / HTTP/1.0
User-Agent: whatever/1.1
Host: you.must.have.this.tld
Content-Type: text/xml
Content-Length: 32

<?xml version="1.0"?>
<methodCall>
<methodName>ping</methodName>
<params>
<param>
...
</methodCall>

Did you really have to type all that to test the function? If not, it
may be easier to just use some sort of Ruby telnet package and adapt
your app to their odd format. Just depends on what the other side is
willing to do.
 
Reply With Quote
 
Michael Taras
Guest
Posts: n/a
 
      07-10-2008
yermej wrote:
...
>
> Did you really have to type all that to test the function? If not, it
> may be easier to just use some sort of Ruby telnet package and adapt
> your app to their odd format. Just depends on what the other side is
> willing to do.


Cool, thanks everyone so much for all the help. So it looks like
they're just accepting raw xml for the requests and returning raw xml
for the response. Because there is no HTTP headers in any of the data.
It actually was pretty simple to get it all working just opening up a
tcpsocket and sending the raw xml through as that is what someone
recommended.

I'll definitely come back if I have any more questions on all these
things, since they're all a bit new to me.

Thanks again everyone.

-Michael

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
question about xmlrpc server: returning a list of lists to a Java client? fortepianissimo Python 1 10-23-2006 06:41 AM
Question about xmlrpc and threading David Hirschfield Python 3 02-16-2006 11:43 PM
py-xmlrpc postpone question elbertlev@hotmail.com Python 0 01-31-2005 08:03 PM
Re: xmlrpc, httplib and SSL (HTTP 1.1 XMLRPC client) Etienne Posthumus Python 1 04-01-2004 05:13 PM
xmlrpc server on red hat 9 question Jason Kratz Python 0 06-29-2003 04:27 AM



Advertisments