POE::C...::SOAP(3pm)
π POE::Component::Server::SOAP π
User Contributed Perl Documentation Β· POE::C...::SOAP(3pm)
okay so bestie, welcome to the POE::Component::Server::SOAP page and it is literally about making your POE program serve SOAP/1.1 requests over HTTP. grab a strawberry π and let's go.
β¨ NAME β¨
POE::Component::Server::SOAP β publish POE event handlers via SOAP over HTTP π¦
πΈ SYNOPSIS πΈ
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,
},
);
$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 );
}
}
π ABSTRACT π
An easy to use SOAP/1.1 daemon for POE-enabled programs
π DESCRIPTION π
This module makes serving SOAP/1.1 requests a breeze in POE. periodt.
The hardest thing to understand in this module is the SOAP Body. That's it! no cap, that is genuinely the whole boss fight. π
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::SOAP π
To 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. (iconic behaviour honestly, it does not do the "return undef and hope" thing π)
This constructor accepts only 7 options.
π ALIAS π
This will set the alias Server::SOAP uses in the POE Kernel. This will default to SOAPServer
π ADDRESS π
This value will be passed to POE::Component::Server::SimpleHTTP to bind to.
Examples: ADDRESS => 0 # Bind to all addresses + localhost
ADDRESS => 'localhost' # Bind to localhost
ADDRESS => '192.168.1.1' # Bind to specified IP
π PORT π
This value will be passed to POE::Component::Server::SimpleHTTP to bind to.
π HOSTNAME π
This value is for the HTTP::Request's URI to point to. If this is not supplied, POE::Component::Server::SimpleHTTP will use Sys::Hostname to find it.
π HEADERS π
This should be a hashref, that will become the default headers on all HTTP::Response objects. You can override this in individual requests by setting it via $response->header( ... )
The default header is:
Server => 'POE::Component::Server::SOAP/' . $VERSION
For more information, consult the HTTP::Headers module.
π MUSTUNDERSTAND π
This is a boolean value, controlling whether Server::SOAP will check for this value in the Headers and Fault if it is present. This will default to true.
π SIMPLEHTTP π
This allows you to pass options to the SimpleHTTP backend. One of the real reasons is to support SSL in Server::SOAP, yay! π To learn how to use SSL, please consult the POE::Component::Server::SimpleHTTP documentation. Of course, you could totally screw up things, just use this with caution :)
bestie listen. this one is a caution situation, okay? the manpage literally says "you could totally screw up things". respect the warning. π«Ά
You must pass a hash reference as the value, because it will be expanded and put in the Server::SimpleHTTP->new() constructor.
π¦ Events π¦
There are only a few ways to communicate with Server::SOAP.
π ADDMETHOD
This event accepts four arguments:
- The intended session alias
- The intended session event
- The public service name ( not required -> defaults to session alias )
- The public method name ( not required -> defaults to session event )
Calling this event will add the method to the registry.
NOTE: This will overwrite the old definition of a method if it exists! π
π DELMETHOD
This event accepts two arguments:
- The service name
- The method name
Calling this event will remove the method from the registry.
NOTE: if the service now contains no methods, it will also be removed. it takes the whole vibe with it π
π DELSERVICE
This event accepts one argument:
- The service name
Calling this event will remove the entire service from the registry.
π DONE
This event accepts only one argument: the SOAP::Response object we sent to the handler.
Calling this event implies that this particular request is done, and will proceed to close the socket.
The content in $response->content() will be automatically serialized via SOAP::Lite's SOAP::Serializer
NOTE: This method automatically sets some parameters: - HTTP Status =200( if not defined ) - HTTP Header value of'Content-Type'='text/xml'
To get greater throughput and response time, do not post() to the DONE event, call() it! However, this will force your program to block while servicing SOAP requests... (a little tradeoff, a little main character sacrifice β¨)
π RAWDONE
This event accepts only one argument: the SOAP::Response object we sent to the handler.
Calling this event implies that this particular request is done, and will proceed to close the socket.
The only difference between this and the DONE event is that the content in $response->content() will not be serialized and passed through intact to the SOAP envelope. This is useful if you generate the xml yourself.
NOTE: - The xml content does not need to have a<?xml version="1.0" encoding="UTF-8">header - In SOAP::Lite, the client sees'<foo>54</foo><bar>89</bar>'as'54'only! The solution is to enclose the xml in another name, i.e.'<data><foo>54</foo><bar>89</bar></data>'- If the xml is malformed or is not escaped properly, the client will get terribly confused! π
It will be inserted here:
...<soap:Body><namesp4:TestResponse xmlns:namesp4="http://localhost:32080/">YOURSTUFFHERE</namesp4:TestResponse></soap:Body>...
π FAULT
This event accepts five arguments:
- the HTTP::Response object we sent to the handler
- SOAP Fault Code ( not required -> defaults to
'Server') - SOAP Fault String ( not required -> defaults to
'Application Faulted') - SOAP Fault Detail ( not required )
- SOAP Fault Actor ( not required )
Again, calling this event implies that this particular request is done, and will proceed to close the socket.
Calling this event will generate a SOAP Fault and return it to the client.
NOTE: This method automatically sets some parameters: - HTTP Status =500( if not defined ) - HTTP Header value of'Content-Type'='text/xml'- HTTP Content = SOAP Envelope of the fault ( overwriting anything that was there )
π RAWFAULT
This event accepts only one argument: the SOAP::Response object we sent to the handler.
Calling this event implies that this particular request is done, and will proceed to close the socket.
The only difference between this and the FAULT event is that you are given freedom to create your own xml for the fault. It will be passed through intact to the SOAP envelope. Be sure to read the SOAP specs :)
This is very similar to the RAWDONE event, so go read the notes up there! π
It will be inserted here:
...<soap:Body>YOURSTUFFHERE</soap:Body>...
π CLOSE
This event accepts only one argument: the SOAP::Response object we sent to the handler.
Calling this event will proceed to close the socket, not sending any output.
π STARTLISTEN
Starts the listening socket, if it was shut down
π STOPLISTEN
Simply a wrapper for SHUTDOWN GRACEFUL, but will not shutdown Server::SOAP if there is no more requests
π SHUTDOWN
Without arguments, Server::SOAP does this:
- Close the listening socket
- Kills all pending requests by closing their sockets
- Removes it's alias
With an argument of 'GRACEFUL', Server::SOAP does this:
- Close the listening socket
- Waits for all pending requests to come in via DONE/FAULT/CLOSE, then removes it's alias
π§ Processing Requests π§
if 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.
so like, the Server::SOAP::Response object is literally a whole treasure chest of info about the request you just got, bestie:
- there's the
SimpleHTTP::Connectionobject, which hands you all the connection deets π« - there's the various SOAP accessors that come with
Server::SOAP::Response - there's the
HTTP::Requestobject too
Here's a lil taste of the info you can pull out:
$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, 'cause that's where the arguments to the method call live. The data in the body is a hash β for more deets, go look at SOAP::Lite -> SOAP::Deserializer. π
Ngl I cannot promise you what's gonna be in that body β it's all up to the SOAP serializer/deserializer, no cap. But I can give you some examples, so here we go:
NOTE: it's so much easier to play around with parameters when they're properly encoded. If you're onSOAP::Lite, make extensive use ofSOAP::Data->name()to create your 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: you can get the original array ordering back 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'
};
Just experiment with Data::Dumper and you'll get the hang of it so fast, fr fr. π§
When you're done with the SOAP request, you shove whatever output you've got into the content of the response object:
$response->content( 'The result is ... ' );
And the only thing left is to send it off to the DONE event π:
$_[KERNEL]->post( 'MySOAP', 'DONE', $response );
If something went wrong, you can send it to the FAULT event instead, which converts 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 Notes π
This module is very picky about capitalization, okay?? Like, do not test it.
All of the options are uppercase, purely to avoid confusion. Periodt.
You can turn on debugging mode by doing this:
sub POE::Component::Server::SOAP::DEBUG () { 1 }
use POE::Component::Server::SOAP;
And in case you wanna 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 development can move on instead of being stuck on legacy issues. Growth mindset, bestie π
π Using SSL π
So you wanna use SSL in Server::SOAP? Here's an example of 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, and to use SSL in SOAP::Lite, simply use https://blah.com instead of http://blah.com β¨
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc POE::Component::Server::SOAP
πΈ Websites πΈ
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/POE-Component-Server-SOAP>
- CPAN Ratings
<http://cpanratings.perl.org/d/POE-Component-Server-SOAP>
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-Server-SOAP>
- Search CPAN
<http://search.cpan.org/dist/POE-Component-Server-SOAP>
π Bugs π
Please 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. Teamwork, honestly π«Ά
π SEE ALSO π
The 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
π AUTHOR π
Apocalypse <apocal@cpan.org>
I took over this module from Rocco Caputo. Here is his stuff:
POE::Component::Server::SOAPis Copyright 2002 by Rocco Caputo. All rights are reserved.POE::Component::Server::SOAPis 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 LICENSE π
Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
And that's the whole vibe check, bestie β this page is from perl v5.34.0, dated 2022-06-17, and it's the POE::C...::SOAP(3pm) page, slay π
β¨
π¦ where this page comes from
- debian bookworm: libpoe-component-server-soap-perl 1.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libpoe-component-server-soap-perl 1.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libpoe-component-server-soap-perl 1.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libpoe-component-server-soap-perl 1.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libpoe-component-server-soap-perl 1.14-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms