|
NAMEGantry::Plugins::SOAP::Doc - document style SOAP support SYNOPSISIn a controller: use Your::App::BaseModule qw(
-PluginNamespace=YourApp
SOAP::Doc
);
# This exports these into the site object:
# soap_out
# do_wsdl
# return_error
do_a_soap_action {
my $self = shift;
my $data = $self->get_post_body();
my $parsed_data = XMLin( $data );
# Use data to process the request, until you have a
# structure like:
my $ret_struct = [
{
yourResponseType => [
{ var => value },
{ var2 => value2 },
{ var3 => undef }, # for required empty tags
{ nesting_var => [
{ subvar => value },
] }
]
}
] );
return $self->soap_out( $ret_struct, 'prefix', 'pretty' );
}
DESCRIPTIONThis module supports document style SOAP. If you need rpc style, see Gantry::Plugins::SOAP::RPC. This module must be used as a plugin, so it can register a pre_init callback to take the POSTed body from the HTTP request before the engine can mangle it, in a vain attempt to make form parameters from it. The document style SOAP request must find its way to your do_ method via its soap_action URL and Gantry's normal dispatching mechanism. Once the do_ method is called, your SOAP request is available via the "get_post_body" accessor exported by each engine. That request is exactly as received. You probably want to use XML::Simple's XMLin function to extract your data. I would do that for you here, but you might need to set attributes of the parsing like ForceArray. When you have finished processing the request, you have two choices. If it did not go well, call "return_error" to deliver a SOAP fault to client. Using die or croak is a bad idea as that will return a regular Gantry error message which is obviously not SOAP compliant. If you succeeded in handling the request, return an array of hashes. Each hash is keyed by XML tag (not including namespace prefix). The value can be a scalar or an array of hashes like the top level one. If the value is "undef", an empty tag will be generated. Generally, you need to take all of the exports from this module, unless you want to replace them with your own versions. If you need to control the namespace of the returned parameters, call "soap_namespace_set" with the URL of the namespace before returning. If you don't do that the namespace will default to "http://example.com/ns". METHODS
Call this with the data to return to the client. If that client cares about the namespace of the tags in the response, call "soap_namespace_set" first. See the SYNOPSIS for an example of the structure you must pass to this method. See the DESCRIPTION for an explanation of what you can put in the structure. You should return the value returned from this method directly. It turns off all templating and sets the content type to text/xml.
AUTHORPhil Crow, <crow.phil@gmail.com> Tim Keefer, <tim@timkeefer.com<gt> COPYRIGHT and LICENSECopyright (c) 2007, Phil Crow This 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.
|