1POE::Component::Server:U:sSeOrAPC(o3n)tributed Perl DocuPmOeEn:t:aCtoimopnonent::Server::SOAP(3)
2
3
4

NAME

6       POE::Component::Server::SOAP - publish POE event handlers via SOAP over
7       HTTP
8

SYNOPSIS

10               use POE;
11               use POE::Component::Server::SOAP;
12
13               POE::Component::Server::SOAP->new(
14                       'ALIAS'         =>      'MySOAP',
15                       'ADDRESS'       =>      'localhost',
16                       'PORT'          =>      32080,
17                       'HOSTNAME'      =>      'MyHost.com',
18               );
19
20               POE::Session->create(
21                       'inline_states' =>      {
22                               '_start'        =>      \&setup_service,
23                               '_stop'         =>      \&shutdown_service,
24                               'Sum_Things'    =>      \&do_sum,
25                       },
26               );
27
28               $poe_kernel->run;
29               exit 0;
30
31               sub setup_service {
32                       my $kernel = $_[KERNEL];
33                       $kernel->alias_set( 'MyServer' );
34                       $kernel->post( 'MySOAP', 'ADDMETHOD', 'MyServer', 'Sum_Things' );
35               }
36
37               sub shutdown_service {
38                       $_[KERNEL]->post( 'MySOAP', 'DELMETHOD', 'MyServer', 'Sum_Things' );
39               }
40
41               sub do_sum {
42                       my $response = $_[ARG0];
43                       my $params = $response->soapbody;
44                       my $sum = 0;
45                       while (my ($field, $value) = each(%$params)) {
46                               $sum += $value;
47                       }
48
49                       # Fake an error
50                       if ( $sum < 100 ) {
51                               $_[KERNEL]->post( 'MySOAP', 'FAULT', $response, 'Client.Add.Error', 'The sum must be above 100' );
52                       } else {
53                               # Add the content
54                               $response->content( "Thanks.  Sum is: $sum" );
55                               $_[KERNEL]->post( 'MySOAP', 'DONE', $response );
56                       }
57               }
58

ABSTRACT

60               An easy to use SOAP/1.1 daemon for POE-enabled programs
61

DESCRIPTION

63       This module makes serving SOAP/1.1 requests a breeze in POE.
64
65       The hardest thing to understand in this module is the SOAP Body. That's
66       it!
67
68       The standard way to use this module is to do this:
69
70               use POE;
71               use POE::Component::Server::SOAP;
72
73               POE::Component::Server::SOAP->new( ... );
74
75               POE::Session->create( ... );
76
77               POE::Kernel->run();
78
79       POE::Component::Server::SOAP is a bolt-on component that can publish
80       event handlers via SOAP over HTTP.  Currently, this module only
81       supports SOAP/1.1 requests, work will be done in the future to support
82       SOAP/1.2 requests.  The HTTP server is done via
83       POE::Component::Server::SimpleHTTP.
84
85   Starting Server::SOAP
86       To start Server::SOAP, just call it's new method:
87
88               POE::Component::Server::SOAP->new(
89                       'ALIAS'         =>      'MySOAP',
90                       'ADDRESS'       =>      '192.168.1.1',
91                       'PORT'          =>      11111,
92                       'HOSTNAME'      =>      'MySite.com',
93                       'HEADERS'       =>      {},
94               );
95
96       This method will die on error or return success.
97
98       This constructor accepts only 7 options.
99
100       "ALIAS"
101           This will set the alias Server::SOAP uses in the POE Kernel.  This
102           will default to "SOAPServer"
103
104       "ADDRESS"
105           This value will be passed to POE::Component::Server::SimpleHTTP to
106           bind to.
107
108           Examples:      ADDRESS => 0             # Bind to all addresses +
109           localhost      ADDRESS => 'localhost'        # Bind to localhost
110                ADDRESS => '192.168.1.1'  # Bind to specified IP
111
112       "PORT"
113           This value will be passed to POE::Component::Server::SimpleHTTP to
114           bind to.
115
116       "HOSTNAME"
117           This value is for the HTTP::Request's URI to point to.  If this is
118           not supplied, POE::Component::Server::SimpleHTTP will use
119           Sys::Hostname to find it.
120
121       "HEADERS"
122           This should be a hashref, that will become the default headers on
123           all HTTP::Response objects.  You can override this in individual
124           requests by setting it via $response->header( ... )
125
126           The default header is:      Server =>
127           'POE::Component::Server::SOAP/' . $VERSION
128
129           For more information, consult the HTTP::Headers module.
130
131       "MUSTUNDERSTAND"
132           This is a boolean value, controlling whether Server::SOAP will
133           check for this value in the Headers and Fault if it is present.
134           This will default to true.
135
136       "SIMPLEHTTP"
137           This allows you to pass options to the SimpleHTTP backend. One of
138           the real reasons is to support SSL in Server::SOAP, yay!  To learn
139           how to use SSL, please consult the
140           POE::Component::Server::SimpleHTTP documentation. Of course, you
141           could totally screw up things, just use this with caution :)
142
143           You must pass a hash reference as the value, because it will be
144           expanded and put in the Server::SimpleHTTP->new() constructor.
145
146   Events
147       There are only a few ways to communicate with Server::SOAP.
148
149       "ADDMETHOD"
150                   This event accepts four arguments:
151                           - The intended session alias
152                           - The intended session event
153                           - The public service name       ( not required -> defaults to session alias )
154                           - The public method name        ( not required -> defaults to session event )
155
156                   Calling this event will add the method to the registry.
157
158                   NOTE: This will overwrite the old definition of a method if it exists!
159
160       "DELMETHOD"
161                   This event accepts two arguments:
162                           - The service name
163                           - The method name
164
165                   Calling this event will remove the method from the registry.
166
167                   NOTE: if the service now contains no methods, it will also be removed.
168
169       "DELSERVICE"
170                   This event accepts one argument:
171                           - The service name
172
173                   Calling this event will remove the entire service from the registry.
174
175       "DONE"
176                   This event accepts only one argument: the SOAP::Response object we sent to the handler.
177
178                   Calling this event implies that this particular request is done, and will proceed to close the socket.
179
180                   The content in $response->content() will be automatically serialized via SOAP::Lite's SOAP::Serializer
181
182                   NOTE: This method automatically sets some parameters:
183                           - HTTP Status = 200 ( if not defined )
184                           - HTTP Header value of 'Content-Type' = 'text/xml'
185
186                   To get greater throughput and response time, do not post() to the DONE event, call() it!
187                   However, this will force your program to block while servicing SOAP requests...
188
189       "RAWDONE"
190                   This event accepts only one argument: the SOAP::Response object we sent to the handler.
191
192                   Calling this event implies that this particular request is done, and will proceed to close the socket.
193
194                   The only difference between this and the DONE event is that the content in $response->content() will not
195                   be serialized and passed through intact to the SOAP envelope. This is useful if you generate the xml yourself.
196
197                   NOTE:
198                           - The xml content does not need to have a <?xml version="1.0" encoding="UTF-8"> header
199                           - In SOAP::Lite, the client sees '<foo>54</foo><bar>89</bar>' as '54' only!
200                                   The solution is to enclose the xml in another name, i.e. '<data><foo>54</foo><bar>89</bar></data>'
201                           - If the xml is malformed or is not escaped properly, the client will get terribly confused!
202
203                   It will be inserted here:
204                           ...<soap:Body><namesp4:TestResponse xmlns:namesp4="http://localhost:32080/">YOURSTUFFHERE</namesp4:TestResponse></soap:Body>...
205
206       "FAULT"
207                   This event accepts five arguments:
208                           - the HTTP::Response object we sent to the handler
209                           - SOAP Fault Code       ( not required -> defaults to 'Server' )
210                           - SOAP Fault String     ( not required -> defaults to 'Application Faulted' )
211                           - SOAP Fault Detail     ( not required )
212                           - SOAP Fault Actor      ( not required )
213
214                   Again, calling this event implies that this particular request is done, and will proceed to close the socket.
215
216                   Calling this event will generate a SOAP Fault and return it to the client.
217
218                   NOTE: This method automatically sets some parameters:
219                           - HTTP Status = 500 ( if not defined )
220                           - HTTP Header value of 'Content-Type' = 'text/xml'
221                           - HTTP Content = SOAP Envelope of the fault ( overwriting anything that was there )
222
223       "RAWFAULT"
224                   This event accepts only one argument: the SOAP::Response object we sent to the handler.
225
226                   Calling this event implies that this particular request is done, and will proceed to close the socket.
227
228                   The only difference between this and the FAULT event is that you are given freedom to create your own xml for the
229                   fault. It will be passed through intact to the SOAP envelope. Be sure to read the SOAP specs :)
230
231                   This is very similar to the RAWDONE event, so go read the notes up there!
232
233                   It will be inserted here:
234                           ...<soap:Body>YOURSTUFFHERE</soap:Body>...
235
236       "CLOSE"
237                   This event accepts only one argument: the SOAP::Response object we sent to the handler.
238
239                   Calling this event will proceed to close the socket, not sending any output.
240
241       "STARTLISTEN"
242                   Starts the listening socket, if it was shut down
243
244       "STOPLISTEN"
245                   Simply a wrapper for SHUTDOWN GRACEFUL, but will not shutdown Server::SOAP if there is no more requests
246
247       "SHUTDOWN"
248                   Without arguments, Server::SOAP does this:
249                           Close the listening socket
250                           Kills all pending requests by closing their sockets
251                           Removes it's alias
252
253                   With an argument of 'GRACEFUL', Server::SOAP does this:
254                           Close the listening socket
255                           Waits for all pending requests to come in via DONE/FAULT/CLOSE, then removes it's alias
256
257   Processing Requests
258       if you're new to the world of SOAP, reading the documentation by the
259       excellent author of SOAP::Lite is recommended!  It also would help to
260       read some stuff at http://www.soapware.org/ -> they have some excellent
261       links :)
262
263       Now, once you have set up the services/methods, what do you expect from
264       Server::SOAP?  Every request is pretty straightforward, you just get a
265       Server::SOAP::Response object in ARG0.
266
267               The Server::SOAP::Response object contains a wealth of information about the specified request:
268                       - There is the SimpleHTTP::Connection object, which gives you connection information
269                       - There is the various SOAP accessors provided via Server::SOAP::Response
270                       - There is the HTTP::Request object
271
272               Example information you can get:
273                       $response->connection->remote_ip()      # IP of the client
274                       $response->soaprequest->uri()           # Original URI
275                       $response->soapmethod()                 # The SOAP method that was called
276                       $response->soapbody()                   # The arguments to the method
277
278       Probably the most important part of SOAP::Response is the body of the
279       message, which contains the arguments to the method call.  The data in
280       the body is a hash, for more information look at SOAP::Lite ->
281       SOAP::Deserializer.
282
283       I cannot guarantee what will be in the body, it is all up to the SOAP
284       serializer/deserializer. I can provide some examples:
285
286               NOTE: It is much easier to play around with parameters if they are properly encoded.
287               If you are using SOAP::Lite, make extensive use of SOAP::Data->name() to create parameters :)
288
289               Calling a SOAP method with no arguments:
290                       print SOAP::Lite
291                               -> uri('http://localhost:32080/')
292                               -> proxy('http://localhost:32080/?session=MyServer')
293                               -> Sum_Things()
294                               -> result
295
296               The body will look like this:
297                       $VAR1 = undef;
298
299               Calling a SOAP method with multiple arguments:
300                       print SOAP::Lite
301                               -> uri('http://localhost:32080/')
302                               -> proxy('http://localhost:32080/?session=MyServer')
303                               -> Sum_Things( 8, 6, 7, 5, 3, 0, 9, 183 )
304                               -> result
305
306               The body will look like this:
307                       $VAR1 = {
308                               'c-gensym17' => '183',
309                               'c-gensym5' => '6',
310                               'c-gensym13' => '0',
311                               'c-gensym11' => '3',
312                               'c-gensym15' => '9',
313                               'c-gensym9' => '5',
314                               'c-gensym3' => '8',
315                               'c-gensym7' => '7'
316                       };
317
318                       NOTE: The original array ordering can be received by sorting on the keys.
319
320               Calling a SOAP method with an arrayref
321                       print SOAP::Lite
322                               -> uri('http://localhost:32080/')
323                               -> proxy('http://localhost:32080/?session=MyServer')
324                               -> Sum_Things(
325                                       [ 8, 6, 7, 5, 3, 0, 9, 183 ]
326                                       )
327                               -> result
328
329               The body will look like this:
330                       $VAR1 = {
331                               'Array' => [
332                                       '8',
333                                       '6',
334                                       '7',
335                                       '5',
336                                       '3',
337                                       '0',
338                                       '9',
339                                       '183'
340                               ]
341                       };
342
343               Calling a SOAP method with a hash:
344                       print SOAP::Lite
345                               -> uri('http://localhost:32080/')
346                               -> proxy('http://localhost:32080/?session=MyServer')
347                               -> Sum_Things(  {
348                                       'FOO'   =>      'bax',
349                                       'Hello' =>      'World!',
350                               }       )
351                               -> result
352
353               The body will look like this:
354                       $VAR1 = {
355                               'c-gensym21' => {
356                                       'Hello' => 'World!',
357                                       'FOO' => 'bax',
358                               }
359                       };
360
361               Calling a SOAP method using SOAP::Data methods:
362                       print SOAP::Lite
363                               -> uri('http://localhost:32080/')
364                               -> proxy('http://localhost:32080/?session=MyServer')
365                               -> Sum_Things(
366                                       SOAP::Data->name( 'Foo', 'harz' ),
367                                       SOAP::Data->name( 'Param', 'value' ),
368                               )-> result
369
370               The body will look like this:
371                       $VAR1 = {
372                               'Param' => 'value',
373                               'Foo' => 'harz'
374                       };
375
376       Simply experiment using Data::Dumper and you'll quickly get the hang of
377       it!
378
379       When you're done with the SOAP request, stuff whatever output you have
380       into the content of the response object.
381
382               $response->content( 'The result is ... ' );
383
384       The only thing left to do is send it off to the DONE event :)
385
386               $_[KERNEL]->post( 'MySOAP', 'DONE', $response );
387
388       If there's an error, you can send it to the FAULT event, which will
389       convert it into a SOAP fault.
390
391               # See this website for more details about what "SOAP Fault" is :)
392               # http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383507
393
394               $_[KERNEL]->post( 'MySOAP', 'FAULT', $response, 'Client.Authentication', 'Invalid password' );
395
396   Server::SOAP Notes
397       This module is very picky about capitalization!
398
399       All of the options are uppercase, to avoid confusion.
400
401       You can enable debugging mode by doing this:
402
403               sub POE::Component::Server::SOAP::DEBUG () { 1 }
404               use POE::Component::Server::SOAP;
405
406       In the case you want to see the raw xml being received/sent to the
407       client, set DEBUG to 2.
408
409       Yes, I broke a lot of things in the release ( 1.01 ), but Rocco agreed
410       that it's best to break things as early as possible, so that
411       development can move on instead of being stuck on legacy issues.
412
413   Using SSL
414       So you want to use SSL in Server::SOAP? Here's a example on how to do
415       it:
416
417               POE::Component::Server::SOAP->new(
418                       ...
419                       'SIMPLEHTTP'    =>      {
420                               'SSLKEYCERT'    =>      [ 'public-key.pem', 'public-cert.pem' ],
421                       },
422               );
423
424               # And that's it provided you've already created the necessary key + certificate file :)
425
426       Ah, to use SSL in SOAP::Lite, simply use https://blah.com instead of
427       http://blah.com
428

SUPPORT

430       You can find documentation for this module with the perldoc command.
431
432           perldoc POE::Component::Server::SOAP
433
434   Websites
435       •   AnnoCPAN: Annotated CPAN documentation
436
437           <http://annocpan.org/dist/POE-Component-Server-SOAP>
438
439       •   CPAN Ratings
440
441           <http://cpanratings.perl.org/d/POE-Component-Server-SOAP>
442
443       •   RT: CPAN's request tracker
444
445           <http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Component-Server-SOAP>
446
447       •   Search CPAN
448
449           <http://search.cpan.org/dist/POE-Component-Server-SOAP>
450
451   Bugs
452       Please report any bugs or feature requests to
453       "bug-poe-component-server-soap at rt.cpan.org", or through the web
454       interface at
455       <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Component-Server-SOAP>.
456       I will be notified, and then you'll automatically be notified of
457       progress on your bug as I make changes.
458

SEE ALSO

460       The examples directory that came with this component.
461
462       POE
463
464       HTTP::Response
465
466       HTTP::Request
467
468       POE::Component::Server::SOAP::Response
469
470       POE::Component::Server::SimpleHTTP
471
472       SOAP::Lite
473
474       POE::Component::SSLify
475

AUTHOR

477       Apocalypse <apocal@cpan.org>
478
479       I took over this module from Rocco Caputo. Here is his stuff:
480
481               POE::Component::Server::SOAP is Copyright 2002 by Rocco Caputo.  All
482               rights are reserved.  POE::Component::Server::SOAP is free software;
483               you may redistribute it and/or modify it under the same terms as Perl
484               itself.
485
486               Rocco may be contacted by e-mail via rcaputo@cpan.org.
487
489       Copyright 2009 by Apocalypse
490
491       This library is free software; you can redistribute it and/or modify it
492       under the same terms as Perl itself.
493
494
495
496perl v5.34.0                      2021-07-22   POE::Component::Server::SOAP(3)
Impressum