|
NAMEPOE::Component::Server::SOAP - publish POE event handlers via SOAP over HTTPSYNOPSISuse 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, }, ); $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; my $sum = 0; while (my ($field, $value) = each(%$params)) { $sum += $value; } # Fake an error if ( $sum < 100 ) { $_[KERNEL]->post( 'MySOAP', 'FAULT', $response, 'Client.Add.Error', 'The sum must be above 100' ); } else { # Add the content $response->content( "Thanks. Sum is: $sum" ); $_[KERNEL]->post( 'MySOAP', 'DONE', $response ); } } ABSTRACTAn easy to use SOAP/1.1 daemon for POE-enabled programs DESCRIPTIONThis module makes serving SOAP/1.1 requests a breeze in POE.The hardest thing to understand in this module is the SOAP Body. That's it! The standard way to use this module is to do this: use POE; use POE::Component::Server::SOAP; POE::Component::Server::SOAP->new( ... ); POE::Session->create( ... ); POE::Kernel->run(); POE::Component::Server::SOAP is a bolt-on component that can publish event handlers via SOAP over HTTP. Currently, this module only supports SOAP/1.1 requests, work will be done in the future to support SOAP/1.2 requests. The HTTP server is done via POE::Component::Server::SimpleHTTP. Starting Server::SOAPTo start Server::SOAP, just call it's new method:POE::Component::Server::SOAP->new( 'ALIAS' => 'MySOAP', 'ADDRESS' => '192.168.1.1', 'PORT' => 11111, 'HOSTNAME' => 'MySite.com', 'HEADERS' => {}, ); This method will die on error or return success. This constructor accepts only 7 options.
EventsThere are only a few ways to communicate with Server::SOAP.
Processing Requestsif you're new to the world of SOAP, reading the documentation by the excellent author of SOAP::Lite is recommended! It also would help to read some stuff at http://www.soapware.org/ -> they have some excellent links :)Now, once you have set up the services/methods, what do you expect from Server::SOAP? Every request is pretty straightforward, you just get a Server::SOAP::Response object in ARG0. The Server::SOAP::Response object contains a wealth of information about the specified request: - There is the SimpleHTTP::Connection object, which gives you connection information - There is the various SOAP accessors provided via Server::SOAP::Response - There is the HTTP::Request object Example information you can get: $response->connection->remote_ip() # IP of the client $response->soaprequest->uri() # Original URI $response->soapmethod() # The SOAP method that was called $response->soapbody() # The arguments to the method Probably the most important part of SOAP::Response is the body of the message, which contains the arguments to the method call. The data in the body is a hash, for more information look at SOAP::Lite -> SOAP::Deserializer. I cannot guarantee what will be in the body, it is all up to the SOAP serializer/deserializer. I can provide some examples: NOTE: It is much easier to play around with parameters if they are properly encoded. If you are using SOAP::Lite, make extensive use of SOAP::Data->name() to create parameters :) Calling a SOAP method with no arguments: print SOAP::Lite -> uri('http://localhost:32080/') -> proxy('http://localhost:32080/?session=MyServer') -> Sum_Things() -> result The body will look like this: $VAR1 = undef; Calling a SOAP method with multiple arguments: print SOAP::Lite -> uri('http://localhost:32080/') -> proxy('http://localhost:32080/?session=MyServer') -> Sum_Things( 8, 6, 7, 5, 3, 0, 9, 183 ) -> result The body will look like this: $VAR1 = { 'c-gensym17' => '183', 'c-gensym5' => '6', 'c-gensym13' => '0', 'c-gensym11' => '3', 'c-gensym15' => '9', 'c-gensym9' => '5', 'c-gensym3' => '8', 'c-gensym7' => '7' }; NOTE: The original array ordering can be received by sorting on the keys. Calling a SOAP method with an arrayref print SOAP::Lite -> uri('http://localhost:32080/') -> proxy('http://localhost:32080/?session=MyServer') -> Sum_Things( [ 8, 6, 7, 5, 3, 0, 9, 183 ] ) -> result The body will look like this: $VAR1 = { 'Array' => [ '8', '6', '7', '5', '3', '0', '9', '183' ] }; Calling a SOAP method with a hash: print SOAP::Lite -> uri('http://localhost:32080/') -> proxy('http://localhost:32080/?session=MyServer') -> Sum_Things( { 'FOO' => 'bax', 'Hello' => 'World!', } ) -> result The body will look like this: $VAR1 = { 'c-gensym21' => { 'Hello' => 'World!', 'FOO' => 'bax', } }; Calling a SOAP method using SOAP::Data methods: print SOAP::Lite -> uri('http://localhost:32080/') -> proxy('http://localhost:32080/?session=MyServer') -> Sum_Things( SOAP::Data->name( 'Foo', 'harz' ), SOAP::Data->name( 'Param', 'value' ), )-> result The body will look like this: $VAR1 = { 'Param' => 'value', 'Foo' => 'harz' }; Simply experiment using Data::Dumper and you'll quickly get the hang of it! When you're done with the SOAP request, stuff whatever output you have into the content of the response object. $response->content( 'The result is ... ' ); The only thing left to do is send it off to the DONE event :) $_[KERNEL]->post( 'MySOAP', 'DONE', $response ); If there's an error, you can send it to the FAULT event, which will convert it into a SOAP fault. # See this website for more details about what "SOAP Fault" is :) # http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383507 $_[KERNEL]->post( 'MySOAP', 'FAULT', $response, 'Client.Authentication', 'Invalid password' ); Server::SOAP NotesThis module is very picky about capitalization!All of the options are uppercase, to avoid confusion. You can enable debugging mode by doing this: sub POE::Component::Server::SOAP::DEBUG () { 1 } use POE::Component::Server::SOAP; In the case you want to see the raw xml being received/sent to the client, set DEBUG to 2. Yes, I broke a lot of things in the release ( 1.01 ), but Rocco agreed that it's best to break things as early as possible, so that development can move on instead of being stuck on legacy issues. Using SSLSo you want to use SSL in Server::SOAP? Here's a example on how to do it:POE::Component::Server::SOAP->new( ... 'SIMPLEHTTP' => { 'SSLKEYCERT' => [ 'public-key.pem', 'public-cert.pem' ], }, ); # And that's it provided you've already created the necessary key + certificate file :) Ah, to use SSL in SOAP::Lite, simply use https://blah.com instead of http://blah.com SUPPORTYou can find documentation for this module with the perldoc command.perldoc POE::Component::Server::SOAP Websites
BugsPlease report any bugs or feature requests to "bug-poe-component-server-soap at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-Server-SOAP>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.SEE ALSOThe examples directory that came with this component.POE HTTP::Response HTTP::Request POE::Component::Server::SOAP::Response POE::Component::Server::SimpleHTTP SOAP::Lite POE::Component::SSLify AUTHORApocalypse <apocal@cpan.org>I took over this module from Rocco Caputo. Here is his stuff: POE::Component::Server::SOAP is Copyright 2002 by Rocco Caputo. All rights are reserved. POE::Component::Server::SOAP is free software; you may redistribute it and/or modify it under the same terms as Perl itself. Rocco may be contacted by e-mail via rcaputo@cpan.org. COPYRIGHT AND LICENSECopyright 2009 by ApocalypseThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |