POE and SOAP

Discussion in 'Perl Misc' started by Mpapec, Mar 14, 2008.

  1. Mpapec

    Mpapec Guest

    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;
    Mpapec, Mar 14, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fmp Fmpf
    Replies:
    0
    Views:
    80
    Fmp Fmpf
    May 27, 2008
  2. Krisztian VASAS

    problem between perl-gtk2 and POE::Session

    Krisztian VASAS, Jun 21, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    94
    Rocco Caputo
    Jun 24, 2004
  3. Krisztian VASAS

    Problem with Gtk2 and POE

    Krisztian VASAS, Jun 28, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    113
    Rocco Caputo
    Jun 30, 2004
  4. Theo James

    POE and Port Redirection

    Theo James, Sep 18, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    133
    news.hinet.net
    Sep 20, 2004
  5. Kurt M. Weber

    POE::Component::IRC::State and nick changes

    Kurt M. Weber, Nov 9, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    84
    Kurt M. Weber
    Nov 9, 2007
Loading...

Share This Page