Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Testing XML-RPC Servers written in Perl

by Plankton (Vicar)
on Mar 26, 2012 at 05:52 UTC ( #961590=perlquestion: print w/replies, xml ) Need Help??

Plankton has asked for the wisdom of the Perl Monks concerning the following question:

Oh Wise Monks,

I have given up trying to write a SOAP server. Instead, I need to write an XML-RPC Listener. So I have installed Frontier-RPC and started playing with the examples. I got server a working with Frontier::Daemon no problem. I use this script to test it ...

#!/usr/bin/perl # Testing sum() use strict; use warnings; use Frontier::Client; my $url = "http://localhost:8181/RPC2"; my @args = (2,5); my $client = Frontier::Client->new( url => $url, debug => 1 ); print "$args[0] + $args[1] = ", $client->call('sum', @args), "\n";
... here's the output to that shows my daemon server works:
$ ./ ---- request ---- <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param><value><i4>2</i4></value></param> <param><value><i4>5</i4></value></param> </params> </methodCall> ---- response ---- <?xml version="1.0"?> <methodResponse> <params> <param><value><string>7</string></value></param> </params> </methodResponse> 2 + 5 = 7
... but I also want to use Frontier::Responder so I can respond to request for normal CGI processes. So I put the script in my webserver's cgi-bin dir ...
plankton@ubuntu:/usr/lib/cgi-bin$ cat fcresponder.cgi #!/usr/bin/perl -w use strict; use Frontier::Responder; use CGI; my $cgi = new CGI; my $xml = $cgi->param('POSTDATA'); my $res = Frontier::Responder->new( methods => { sum => sub{ $_[0] + $ +_[1] }, add => sub{ $_[0] + $ +_[1] }, cat => sub{ $_[0] . $ +_[1] }, }, ); print $res->answer;
... and then I change my test script to this ...
plankton@ubuntu:/usr/lib/cgi-bin$ cat test_fcresonder.cgi #!/usr/bin/perl -w use strict; use Frontier::Client; my $server = Frontier::Client->new(url => "http://localhost/cgi-bin/fc +responder.cgi", debug => 1); my $method = 'sum'; my @args = (1,1); my $result = $server->call($method, @args); print "$result\n";
... and when I run the above I get this output ...
plankton@ubuntu:/usr/lib/cgi-bin$ ./test_fcresonder.cgi ---- request ---- <?xml version="1.0"?> <methodCall> <methodName>sum</methodName> <params> <param><value><i4>1</i4></value></param> <param><value><i4>1</i4></value></param> </params> </methodCall> ---- response ---- no element found at line 1, column 0, byte -1 at /usr/lib/perl5/XML/Pa line 187
... what am I doing wrong?

Replies are listed 'Best First'.
Re: Testing XML-RPC Servers written in Perl
by Plankton (Vicar) on Mar 26, 2012 at 07:05 UTC
    Looks like the problem was in Frontier::Responder itself. I made these changes:
    plankton@ubuntu:/usr/local/share/perl/5.10.1/Frontier$ diff Responder. +pm Responder.pm_old 19,20d18 < #plankton I put it back < use CGI; 53,55c51 < # my $request = get_cgi_request(); < my $cgi = new CGI; < my $request = $cgi->param('POSTDATA'); --- > my $request = get_cgi_request();
    and now my test script works.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://961590]
Approved by Old_Gray_Bear
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2020-09-24 12:34 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (133 votes). Check out past polls.