| 1 |
# Extend SOAP::Transport::HTTP::Server to be able to handle PSGI requests |
| 2 |
|
| 3 |
package Lemonldap::NG::Common::PSGI::SOAPServer; |
| 4 |
|
| 5 |
use bytes; |
| 6 |
use strict; |
| 7 |
use SOAP::Transport::HTTP; |
| 8 |
|
| 9 |
our @ISA = ('SOAP::Transport::HTTP::Server'); |
| 10 |
|
| 11 |
our $VERSION = '2.0.0'; |
| 12 |
|
| 13 |
# Call SOAP::Trace::objects(). |
| 14 |
sub DESTROY { SOAP::Trace::objects('()') } |
| 15 |
|
| 16 |
sub new { |
| 17 |
my $self = shift; |
| 18 |
return $self if ref $self; |
| 19 |
|
| 20 |
my $class = ref($self) || $self; |
| 21 |
$self = $class->SUPER::new(@_); |
| 22 |
SOAP::Trace::objects('()'); |
| 23 |
|
| 24 |
return $self; |
| 25 |
} |
| 26 |
|
| 27 |
# Build SOAP request using $req->content and call |
| 28 |
# SOAP::Transport::HTTP::Server::handle(), then return the result to the client. |
| 29 |
sub handle { |
| 30 |
my $self = shift->new; |
| 31 |
my $req = shift; |
| 32 |
|
| 33 |
unless ( $req->content_length ) { |
| 34 |
return [ 411, [], [] ]; |
| 35 |
} |
| 36 |
$self->request( |
| 37 |
HTTP::Request->new( |
| 38 |
$req->method, $req->uri, $req->headers, |
| 39 |
do { $req->content } |
| 40 |
) |
| 41 |
); |
| 42 |
$self->SUPER::handle(); |
| 43 |
my @headers; |
| 44 |
$self->response->headers->scan( sub { push @headers, @_ } ); |
| 45 |
return [ $self->response->code, \@headers, [ $self->response->content ] ]; |
| 46 |
} |
| 47 |
|
| 48 |
1; |