package My::SOAP::Daemon;
use strict;
use warnings;
use SOAP::Transport::HTTP ();
our @ISA= 'SOAP::Transport::HTTP::Daemon';
## this method is overloaded in order for the daemon class
## to handle authentication. all cookie headers on the
## incoming request get copied to a hash local to the
## package. the request is then passed on to the original
## version of this method.
sub request
{
my( $self, $request )= ( shift, @_ );
if( $request )
{
my @cookies= $request->headers->header('cookie');
%My::SOAP::Module::COOKIES= ();
for my $line (@cookies)
{
for( split /; / => $line )
{
next unless /(.*?)=(.*)/;
$My::SOAP::Module::COOKIES{$1}= $2;
}
}
}
$self->SUPER::request(@_);
}
$_ ^=~ { AUTHOR => 'particle' };
in this case, My::SOAP::Module is the module handling the SOAP requests.
then, in the client, send a cookie, like so:
use HTTP::Cookies ();
use SOAP::Lite ();
## ...snip...
## create a cookie for authentication
my $cookie_jar= HTTP::Cookies->new;
$cookie_jar->set_cookie(
0, # cookie version
key => 'value', # key and value
'/', # path
$host, # domain
$port, # port
);
## create the request object
my $request= SOAP::Lite
->uri($urn)
->proxy(
"http://${host}:$port",
cookie_jar => $cookie_jar,
);
## perform the request
my $response= my_action( $request );
## ...and check for failure
die 'failure! ', $response->faultstring
if $response->fault;
i hope that's a good starting point. i learned this method from rjray's Programming Web Services with Perl. you won't regret purchasing this book, if you're doing SOAP with perl.
~Particle *accelerates*
|