POE and SOAP

M

Mpapec

I want to build small soap server which should provide persistent DBI
statement handles. POE::Component::Server::SOAP handles one client at
the time, so there is a lot of waiting for other clients.

I've tried to change perldoc example so the server wouldn't block, but
now server doesn't respond at all. :)
http://search.cpan.org/~apocal/POE-Component-Server-SOAP-1.11/lib/POE/Component/Server/SOAP.pm



server
++++++
use strict;
use warnings;

use Data::Dumper;
use POE;
use POE::Component::Server::SOAP;

POE::Component::Server::SOAP->new(
'ALIAS' => 'MySOAP',
'ADDRESS' => 'localhost',
'PORT' => 32080,
'HOSTNAME' => 'MyHost.com',
);

POE::Session->create(
inline_states => {
_start => \&setup_service,
_stop => \&shutdown_service,
Sum_Things => \&do_sum,

task_result => \&handle_task_result,
task_done => \&handle_task_done,
task_debug => \&handle_task_debug,
},
);

$poe_kernel->run;
exit 0;

sub setup_service {
my $kernel = $_[KERNEL];
$kernel->alias_set( 'MyServer' );
$kernel->post( 'MySOAP', 'ADDMETHOD', 'MyServer', 'Sum_Things' );
}
sub shutdown_service {
$_[KERNEL]->post( 'MySOAP', 'DELMETHOD', 'MyServer',
'Sum_Things' );
}


sub do_sum {

my $response = $_[ARG0];
my $params = $response->soapbody;

use POE qw(Wheel::Run Filter::Reference);
my $task = POE::Wheel::Run->new(
Program => sub { do_stuff($response, $params) },
StdoutFilter => POE::Filter::Reference->new(),
StdoutEvent => "task_result",
StderrEvent => "task_debug",
CloseEvent => "task_done",
);
}



sub do_stuff {
binmode(STDOUT); # Required for this to work on MSWin32
my ($response, $params) = @_;

my $filter = POE::Filter::Reference->new();
# console output
my $output = $filter->put( [ $response ] );
print @$output;

# soap client output
$response->content(
[
{ res => $_[HEAP]{i}++ },
]
);
$_[KERNEL]->post( 'MySOAP', 'DONE', $response );

}

sub handle_task_result {
my $result = $_[ARG0];
print Dumper $result;
}

# Catch and display information from the child's STDERR. This was
# useful for debugging since the child's warnings and errors were not
# being displayed otherwise.
sub handle_task_debug {
my $result = $_[ARG0];
print "Debug: $result\n";
}

# The task is done. Delete the child wheel, and try to start a new
# task to take its place.
sub handle_task_done {
# my ( $kernel, $heap, $task_id ) = @_[ KERNEL, HEAP, ARG0 ];
# delete $heap->{task}->{$task_id};
# $kernel->yield("next_task");
}




client
++++++
use Data::Dumper;
use SOAP::Lite;
my $client = SOAP::Lite
-> uri('http://localhost:32080/')
-> proxy('http://localhost:32080/?session=MyServer');
my $response = $client->Sum_Things( {
'FOO' => 'bax',
'Hello' => 'World!',
}
);

print Dumper $response->result;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top