| 1 | package SOAP::WSDL::Server::Mod_Perl2; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw(SOAP::WSDL::Server); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use HTTP::Request (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Apache2::RequestIO (); # $r->read() | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Apache2::RequestRec (); # $r->headers_in | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Apache2::RequestUtil(); # $r->dir_config() | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use APR::Table (); # $r->headers_in->get() | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Apache2::Log (); # $r->log | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Apache2::Const -compile => qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | OK | ||||||||||||||||||||||||||||
| 15 | SERVER_ERROR | ||||||||||||||||||||||||||||
| 16 | HTTP_LENGTH_REQUIRED | ||||||||||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | our $VERSION = 3.004; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | my %LOADED_OF = (); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 11 | ▶ | sub handler { | ||||||||||||||||||||||||||
|
Subroutine
handler: called CC=11 SCAR=32.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 11 | my $r = shift; | |||||||||||||||||||||||||||
| 25 | 11 | my $rlog = $r->log(); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||
| 28 | # Set up section; import requested modules, throwing errors if we're | ||||||||||||||||||||||||||||
| 29 | # unable to do so. For maximum performance, this should be re-worked | ||||||||||||||||||||||||||||
| 30 | # to use perl-based Apache directives rather than dir_config(), since | ||||||||||||||||||||||||||||
| 31 | # the former happens at startup time and the latter at request time. | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||
| 34 | # dispatch_to | ||||||||||||||||||||||||||||
| 35 | 11 | my $dispatch_to = $r->dir_config('dispatch_to'); | |||||||||||||||||||||||||||
| 36 | 11 | ▶ | if (! $dispatch_to) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 1 | $rlog->error("No 'dispatch_to' variable set in httpd.conf"); | |||||||||||||||||||||||||||
| 38 | 1 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 10 | ▶ | if (! exists $LOADED_OF{$dispatch_to}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 2 | eval "require $dispatch_to"; | |||||||||||||||||||||||||||
| 43 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 1 | $rlog->error("Failed to require [$dispatch_to]: $@"); | |||||||||||||||||||||||||||
| 45 | 1 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 1 | $LOADED_OF{$dispatch_to} = undef; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # | ||||||||||||||||||||||||||||
| 51 | # SOAP service | ||||||||||||||||||||||||||||
| 52 | 9 | my $soap_service_package = $r->dir_config('soap_service'); | |||||||||||||||||||||||||||
| 53 | 9 | ▶ | if (! $soap_service_package) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 1 | $rlog->error("No 'soap_service' variable set in httpd.conf"); | |||||||||||||||||||||||||||
| 55 | 1 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 8 | ▶ | if (! exists $LOADED_OF{$soap_service_package}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 8 | eval "require $soap_service_package"; | |||||||||||||||||||||||||||
| 60 | 8 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 8 | $rlog->error("Failed to require [$soap_service_package]: $@"); | |||||||||||||||||||||||||||
| 62 | 8 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | $LOADED_OF{$soap_service_package} = undef; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # | ||||||||||||||||||||||||||||
| 68 | # transport_class (optional) | ||||||||||||||||||||||||||||
| 69 | 0 | my $transport_class = $r->dir_config('transport_class'); | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($transport_class) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | eval "require $transport_class"; | |||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $rlog->error("Failed to require [$transport_class]: $@"); | |||||||||||||||||||||||||||
| 74 | 0 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||
| 78 | # | ||||||||||||||||||||||||||||
| 79 | # if no transport class was specified, use this package's handle() | ||||||||||||||||||||||||||||
| 80 | # method | ||||||||||||||||||||||||||||
| 81 | 0 | $transport_class = __PACKAGE__; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # | ||||||||||||||||||||||||||||
| 85 | # instantiate SOAP server object | ||||||||||||||||||||||||||||
| 86 | 0 | my $server = $soap_service_package->new({ | |||||||||||||||||||||||||||
| 87 | dispatch_to => $dispatch_to, # methods | ||||||||||||||||||||||||||||
| 88 | transport_class => $transport_class, # handle() call | ||||||||||||||||||||||||||||
| 89 | }); | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | my $response_msg = $server->handle($r); | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($response_msg =~ /^\d{3}$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | # | ||||||||||||||||||||||||||||
| 94 | # a 3-digit number is presumed to be an HTTP return status; since | ||||||||||||||||||||||||||||
| 95 | # we got this and not a SOAP response, it's presumed to be an | ||||||||||||||||||||||||||||
| 96 | # error; pass it back to the client as-is | ||||||||||||||||||||||||||||
| 97 | 0 | $rlog->error("Dispatcher returned HTTP $response_msg"); | |||||||||||||||||||||||||||
| 98 | 0 | return $response_msg; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | if ($response_msg) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | $r->content_type('text/xml; charset="utf-8"'); | |||||||||||||||||||||||||||
| 103 | 0 | $r->print($response_msg); | |||||||||||||||||||||||||||
| 104 | 0 | return Apache2::Const::OK; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | else { | ||||||||||||||||||||||||||||
| 107 | 0 | $rlog->error("No response returned from dispatcher"); | |||||||||||||||||||||||||||
| 108 | 0 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub handle { | ||||||||||||||||||||||||||
|
Subroutine
handle: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 113 | 0 | my ($self, $r) = @_; | |||||||||||||||||||||||||||
| 114 | 0 | my $rlog = $r->log(); | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | my $length = $r->headers_in->get('content-length'); | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (! $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | $rlog->error("No content-length provided"); | |||||||||||||||||||||||||||
| 119 | # TODO maybe throw instead of returning a HTTP code? | ||||||||||||||||||||||||||||
| 120 | # ... it's an exception, anyway... | ||||||||||||||||||||||||||||
| 121 | 0 | return Apache2::Const::HTTP_LENGTH_REQUIRED; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | # read may return less than requested - read until there's no more... | ||||||||||||||||||||||||||||
| 125 | # TODO: We should note that LimitRequestBody is a must in apache config | ||||||||||||||||||||||||||||
| 126 | 0 | my ($buffer, $read_length); | |||||||||||||||||||||||||||
| 127 | 0 | my $content = q{}; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | while ($read_length = $r->read($buffer, $length)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | $content .= $buffer; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($length != length $content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | 0 | $rlog->error("Read length mismatch; read [" . length($content) . "] bytes but received [$length] bytes"); | |||||||||||||||||||||||||||
| 134 | 0 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # Shamelessly copied (with mild tweaks) from SOAP::WSDL::Server::CGI | ||||||||||||||||||||||||||||
| 138 | # ... which was as shamelessly copied from SOAP::Transport::HTTP... | ||||||||||||||||||||||||||||
| 139 | 0 | my $request = HTTP::Request->new( | |||||||||||||||||||||||||||
| 140 | $r->method => $r->uri, | ||||||||||||||||||||||||||||
| 141 | HTTP::Headers->new( | ||||||||||||||||||||||||||||
| 142 | SOAPAction => $r->headers_in()->get('SOAPAction'), | ||||||||||||||||||||||||||||
| 143 | ), | ||||||||||||||||||||||||||||
| 144 | $content, | ||||||||||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 0 | my $response_message = eval { $self->SUPER::handle($request) }; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # TODO return response if @$ is a SOAP::WSDL::XSD::Typelib::Builtin::anyType object | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($@ || blessed($@)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or builtin::blessed($@)
MC/DC0%0/2
$@ or builtin::blessed($@)
$@
builtin::blessed($@)
Truth table0%0/3
A or B
A= $@B= builtin::blessed($@)
| |||||||||||||||||||||||||||||
| 151 | 0 | $rlog->error("Failed to handle request: $@"); | |||||||||||||||||||||||||||
| 152 | 0 | return Apache2::Const::SERVER_ERROR; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | else { | ||||||||||||||||||||||||||||
| 155 | 0 | return $response_message; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 1 | 1; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||