XMLRPC Question

M

Michael Taras

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
 
E

Eric Hodel

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.
 
M

Michael Neumann

Michael said:
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
 
M

Michael Taras

Michael said:
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
 
E

Eric Hodel

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.
 
Y

yermej

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.
 
M

Michael Taras

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top