LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Sunday, October 15. 2006

Zend_XmlRpc_Server

As noted previously by myself and Davey, I've been working on Zend_XmlRpc_Server for some months now. In the past couple weeks, I've refactored it to push the class/function reflection into Zend_Server_Reflection, and, in doing so, noted that there were further areas for refactoring into additional helper classes. Currently, it now has classes for the Request, Response, and Faults, and all actual XML wrangling is done in those, making the server basically XML-agnostic.

One side benefit of this refactoring was that it allowed me to write tests much more quickly and easily. I no longer needed to worry about adding helper methods to the server in order to determine if it properly parsed the request to get the method call and arguments; I could simply test the public API for actually handling the requests. And I no longer needed to create XML in order to test the server; I could simply populate a request object in order to pass in the request, and check the response object to see if I received an appropriate value. No XML wrangling!

So, for an example, advanced case usage with all the bells and whistles:


<?php
require_once 'Zend/XmlRpc/Server.php';
require_once 'Zend/XmlRpc/Server/Fault.php';
require_once 'Zend/XmlRpc/Server/Cache.php';
require_once 'Services/Request.php';
require_once 'Services/Response.php';
require_once 'Services/Exception.php';

require_once 'Services/Comb.php';
require_once 'Services/Brush.php';
require_once 'Services/Pick.php';

// Specify a cache file
$cacheFile = dirname(__FILE__) . '/xmlrpc.cache';

// Allow Services_Exceptions to report as fault responses
Zend_XmlRpc_Server_Fault::attachFaultException('Services_Exception');

$server = new Zend_XmlRpc_Server();

// Attempt to retrieve server definition from cache
if (!Zend_XmlRpc_Server_Cache::get($cacheFile, $server)) {
    $server->setClass('Services_Comb', 'comb');   // methods called as comb.*
    $server->setClass('Services_Brush', 'brush'); // methods called as brush.*
    $server->setClass('Services_Pick', 'pick');   // methods called as pick.*

    // Save cache
    Zend_XmlRpc_Server_Cache::save($cacheFile, $server));
}

// Create a request object
$request = new Services_Request();

// Utilize a custom response
$server->setResponseClass('Services_Response');

echo $server->handle($request);
 

As an afterthought, something that hit me as I finished writing the Request, Response, and Fault classes is that, since the server doesn't need to do anything with XML, there's really no saying that these classes do, either. This means it could, theoretically, be used as a scaffold for other types of RPC web services -- for instance, using compression or ssl-encoded transactions, YAML, JSON, etc. That will be a subject for another day.

If you're interested in testing the XML-RPC server, which is mostly complete at this stage (@todo items at this stage only include verifying arguments received in a request match one of the signatures and that reflection translates the signature parameter and return types to XML-RPC types), you can grab it from the Zend Framework subversion repository, in the incubator tree.

Posted by Matthew Weier O'Phinney in PHP at 22:23 | Comments (2) | Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

I've been getting my feet wet with the Zend Framework lately and I'm wanting to use your Zend_XmlRpc_Server in the usual confines of the framework. Meaning, I'd like to use something like http://localhost/xmlrpc/action being mapped to a class XmlrpcController, yet this normally extends Zend_Controller_Action. I'm thinking maybe Zend_XmlRpc_Server could subclass Zend_Controller_Action? Right now I'm thinking I'll need to use XmlrpcController as an adapter and I'll also have to write adapters for Zend_Controller_Request_Http to Zend_XmlRpc_Request_Http and Zend_Controller_Response_Http to Zend_XmlRpc_Response_Http.
Would you agree with this, or do you think I'm way off base?

Thank you,
Jordan Raub
#1 Jordan Raub on 2007-01-05 12:21 (Reply)
Sorry I took so long to reply to this; for some reason, my blog software's decided not to send notifications when comments are made. :-(

Anyways, there's a flaw in your thinking: an XML-RPC server is a single end point for multiple services. The request made to an XML-RPC server is expected to contain the action requested in the XML POST'd to the server -- it shouldn't be part of the URL.

It is possible to server the XML-RPC server via the MVC, however; simply create an XmlrpcController class that will accept any POST request, and dispatch the XML-RPC server; you'll likely need to disable the ViewRenderer for this to work ;-)

I've done this successfully alongside a SOAP server implementation, allowing me to use /soap and /xmlrpc as my endpoints.
#1.1 Matthew Weier O'Phinney (Link) on 2007-07-22 21:47 (Reply)
Yeah I figured it out. That was 6 months ago an I think I was using ZF 0.7.0 :-)
I did get a comment notification email on this one though...
#1.1.1 Jordan Raub on 2007-07-26 09:52 (Reply)

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back March '10 Forward
Mon Tue Wed Thu Fri Sat Sun
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Paul M. Jones
  • Mike Naberezny
  • Shahar Evron
  • Planet PHP
  • Zend Where I now work
  • Garden.org Where I once worked

Archives

March 2010
February 2010
January 2010
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml best practices
xml books
xml conferences
xml cw09
xml decorators
xml dojo
xml dpc08
xml file_fortune
xml git
xml linux
xml mvc
xml oop
xml pear
xml perl
xml personal
xml php
xml phpworks08
xml programming
xml rest
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zendcon09
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net