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

SEE ALSO

435               The examples directory that came with this component.
436
437               L<POE>
438
439               L<HTTP::Response>
440
441               L<HTTP::Request>
442
443               L<POE::Component::Server::SOAP::Response>
444
445               L<POE::Component::Server::SimpleHTTP>
446
447               L<SOAP::Lite>
448
449               L<POE::Component::SSLify>
450

AUTHOR

452       Apocalypse <apocal@cpan.org>
453
454       I took over this module from Rocco Caputo. Here is his stuff:
455
456               POE::Component::Server::SOAP is Copyright 2002 by Rocco Caputo.  All
457               rights are reserved.  POE::Component::Server::SOAP is free software;
458               you may redistribute it and/or modify it under the same terms as Perl
459               itself.
460
461               Rocco may be contacted by e-mail via rcaputo@cpan.org.
462
464       Copyright 2007 by Apocalypse
465
466       This library is free software; you can redistribute it and/or modify it
467       under the same terms as Perl itself.
468
469
470
471perl v5.8.8                       2007-05-02   POE::Component::Server::SOAP(3)
Impressum