|
NAMEGantry::Plugins::SOAP::RPC - RPC style SOAP supportSYNOPSISIn your GEN module:use Your::App::BaseModule qw( -PluginNamespace=YourApp SOAP::RPC ); # this will export these into your package: # soap_in # soap_out # do_main # do_wsdl # return_error sub get_soap_ops { my $self = shift; return { soap_name => 'Kids', location => $self->location, namespace_base => 'localhost', operations => [ { name => 'get_count', expects => [ { name => 'table_name', type => 'xsd:string' }, ], returns => [ { name => 'count', type => 'xsd:int' }, ], }, ], }; } Add as many operations as you need. In your stub: use Your::GEN::Module; sub get_count { my $self = shift; my $data = shift; return { ... }; } Your data will have whatever was in your client's soap request. You are responsible for diagnosing all errors and for returning the correct structure (it should match the returns list). But feel free to just die when you spot an error, this module traps those and uses its "return_error" method which sends valid SOAP fault messages. DESCRIPTIONThis plugin is for rpc style SOAP requests only. If you need document style requests, you should use Gantry::Plugins::SOAP::Doc.Bigtop can help a lot with the use of this plugin. Below is what you need to do manually, should you choose that route. But first, I'll explain what is happening from overhead. For each SOAP handler in your app, there should be one controller (or a stub/GEN controller pair) placed on a location in your httpd conf. If you do the normal thing, the GEN module (or controller if you don't have a GEN) uses this module and accepts all the exports (the list is mainly for documentation, since all of them are exported by default). Two of the exports are Gantry handlers: "do_main" and "do_wsdl". This means that the caller will look for the service itself at the location from httpd.conf, while they will add /wsdl to get the WSDL file. For example, suppose you have this in your httpd.conf: <Location /appname/SOAP> SetHandler perl-script PerlHandler YourApp::YourSoapStub </Location> Then users will hit "/appname/SOAP" to get the service and "/appname/SOAP/wsdl" to get the WSDL file. This module registers a "pre_init" callback which steals all of the body of the POST from the client. Then it lets Gantry do its normal work. So your stub methods will be called through a site object. All SOAP requests are handled by "do_main", which this module exports. It uses the internal "soap_in" method to parse the input. You must import "soap_in", so it will be in the site object. It fishes the client's desired action out of the incoming SOAP request and calls the method of the same name in the stub module. That method receives the SOAP request as parsed by XML::Simple's "XMLin" function. It must return the structure which will be returned to the client. The action method's structure is then fed to "soap_out" (which you must also import) and the result is returned as a plain text/xml SOAP message to the client. "SOAP::Lite"'s "SOAP::Data" and "SOAP::Serializer" are used to the hard work of making output. Here are the details of what your need to implement. You need a "namespace" method which returns the same name as the "-PluginNamespace". You also need a "get_soap_ops" method which returns a hash describing your WSDL file. See the SYNOPSIS for an example. Here's what the keys do:
WSDL TYPESGantry ships with wsdl.tt which it uses by default to construct the WSDL file from the result of "get_soap_ops". If you need to define types, simply copy that template into your own root path and add the types you need. If you want to supply your own data to the template, just implement your own "get_soap_ops" and return whatever your template expects.METHODSAll of these are exported by default. You may supply your own, or accept the imports. Failure to do one of those two is fatal. Doing both will earn you a subroutine redefinition warning.
AUTHORPhil Crow, <crow.phil@gmail.com>COPYRIGHT and LICENSECopyright (c) 2007, Phil CrowThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
Visit the GSP FreeBSD Man Page Interface. |