| 1 | package SOAP::WSDL::Server::Simple; | ||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
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 HTTP::Response; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Headers; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Class::Std::Fast::Storable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use base qw(SOAP::WSDL::Server); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = 3.004; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # mostly copied from SOAP::Lite. Unfortunately we can't use SOAP::Lite's CGI | ||||||||||||||||||||||||||||
| 20 | # server directly - we would have to swap out it's base class... | ||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||
| 22 | # This should be a warning for us: We should not handle methods via inheritance, | ||||||||||||||||||||||||||||
| 23 | # but via some plugin mechanism, to allow alternative handlers to be plugged | ||||||||||||||||||||||||||||
| 24 | # in. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 4 | ▶ | sub handle { | ||||||||||||||||||||||||||
|
Subroutine
handle: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 4 | my ($self, $cgi) = @_; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 4 | my $response; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | my $content = $cgi->param('POSTDATA'); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | my $request = HTTP::Request->new( | ||||||||||||||||||||||||||||
| 34 | $ENV{'REQUEST_METHOD'} || '' => $ENV{'SCRIPT_NAME'}, | ||||||||||||||||||||||||||||
| 35 | HTTP::Headers->new( | ||||||||||||||||||||||||||||
| 36 | map { | ||||||||||||||||||||||||||||
| 37 | 4 | ▶ | (/^HTTP_(.+)/i | ||||||||||||||||||||||||||
|
Condition100%2/2
$ENV{'REQUEST_METHOD'} || ''
MC/DC100%1/1
$ENV{'REQUEST_METHOD'} || ''
$ENV{'REQUEST_METHOD'}
Truth table100%2/2
A
A= $ENV{'REQUEST_METHOD'}
| |||||||||||||||||||||||||||||
| 38 | ? ($1=~m/SOAPACTION/) | ||||||||||||||||||||||||||||
| 39 | ?('SOAPAction') | ||||||||||||||||||||||||||||
| 40 | :($1) | ||||||||||||||||||||||||||||
| 41 | : $_ | ||||||||||||||||||||||||||||
| 42 | 142 | ▶ | ) => $ENV{$_} | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 43 | } keys %ENV), | ||||||||||||||||||||||||||||
| 44 | $content, | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # we copy the response message around here. | ||||||||||||||||||||||||||||
| 48 | # Passing by reference would be much better... | ||||||||||||||||||||||||||||
| 49 | 4 | my $response_message = eval { $self->SUPER::handle($request) }; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # caveat: SOAP::WSDL::SOAP::Typelib::Fault11 is false in bool context... | ||||||||||||||||||||||||||||
| 52 | 4 | ▶ | if ($@ || blessed $@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$@ or builtin::blessed($@)
MC/DC50%1/2
$@ or builtin::blessed($@)
$@
builtin::blessed($@)
Truth table66%2/3
A or B
A= $@B= builtin::blessed($@)
| |||||||||||||||||||||||||||||
| 53 | 3 | my $exception = $@; | |||||||||||||||||||||||||||
| 54 | 3 | $response = HTTP::Response->new(500); | |||||||||||||||||||||||||||
| 55 | 3 | $response->header('Content-type' => 'text/xml; charset="utf-8"'); | |||||||||||||||||||||||||||
| 56 | 3 | ▶ | if (blessed($exception)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | $response->content( $self->get_serializer->serialize({ | |||||||||||||||||||||||||||
| 58 | body => $exception | ||||||||||||||||||||||||||||
| 59 | }) | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 3 | $response->content($exception); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||
| 67 | 1 | $response = HTTP::Response->new(200); | |||||||||||||||||||||||||||
| 68 | 1 | $response->header('Content-type' => 'text/xml; charset="utf-8"'); | |||||||||||||||||||||||||||
| 69 | 1 | $response->content( encode('utf8', $response_message ) ); | |||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | 1 | $response->header('Content-length', length $response_message); | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 4 | $self->_output($response); | |||||||||||||||||||||||||||
| 77 | 4 | return; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub _output :PRIVATE { | ||||||||||||||||||||||||||||
| 81 | my ($self, $response) = @_; | ||||||||||||||||||||||||||||
| 82 | my $code = $response->code; | ||||||||||||||||||||||||||||
| 83 | binmode(STDOUT); | ||||||||||||||||||||||||||||
| 84 | print STDOUT "HTTP/1.0 $code ", HTTP::Status::status_message($code) | ||||||||||||||||||||||||||||
| 85 | , "\015\012", $response->headers_as_string("\015\012") | ||||||||||||||||||||||||||||
| 86 | , "\015\012", $response->content; | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | warn "HTTP/1.0 $code ", HTTP::Status::status_message($code) | ||||||||||||||||||||||||||||
| 89 | , "\015\012", $response->headers_as_string("\015\012") | ||||||||||||||||||||||||||||
| 90 | , $response->content, "\n\n"; | ||||||||||||||||||||||||||||
| 91 | 1 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | 1; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =pod | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head1 NAME | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | SOAP::WSDL::Server::Simple - CGI based SOAP server for HTTP::Server::Simple | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | package TestServer; | ||||||||||||||||||||||||||||
| 104 | use base qw(HTTP::Server::Simple::CGI); | ||||||||||||||||||||||||||||
| 105 | use MyServer::TestService::TestPort; | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub handle_request { | ||||||||||||||||||||||||||||
| 108 | my ($self, $cgi) = @_; | ||||||||||||||||||||||||||||
| 109 | my $server = MyServer::TestService::TestPort->new({ | ||||||||||||||||||||||||||||
| 110 | dispatch_to => 'main', | ||||||||||||||||||||||||||||
| 111 | transport_class => 'SOAP::WSDL::Server::Simple', | ||||||||||||||||||||||||||||
| 112 | }); | ||||||||||||||||||||||||||||
| 113 | $server->handle($cgi); | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | my $httpd = __PACKAGE__->new(); | ||||||||||||||||||||||||||||
| 117 | $httpd->run(); | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head1 USAGE | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | To use SOAP::WSDL::Server::Simple efficiently, you should first create a server | ||||||||||||||||||||||||||||
| 122 | interface using L<wsdl2perl.pl|wsdl2perl.pl>. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | SOAP::WSDL::Server::Simple dispatches all calls to appropriately named methods in the | ||||||||||||||||||||||||||||
| 125 | class or object set via C<dispatch_to>. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | See the generated server class on details. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Lightweight SOAP server for use with HTTP::Server::Simple, mainly designed | ||||||||||||||||||||||||||||
| 132 | for testing purposes. It allows one to set up a simple SOAP server without having | ||||||||||||||||||||||||||||
| 133 | to configure CGI or mod_perl stuff. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | SOAP::WSDL::Server::Simple is not recommended for production use. | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | =head1 METHODS | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =head2 handle | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | See synopsis above. | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Copyright 2004-2008 Martin Kutter. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | This file is part of SOAP-WSDL. You may distribute/modify it under the same | ||||||||||||||||||||||||||||
| 148 | terms as perl itself | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | Martin Kutter E<lt>martin.kutter fen-net.deE<gt> | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | =head1 REPOSITORY INFORMATION | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | $Rev: 391 $ | ||||||||||||||||||||||||||||
| 157 | $LastChangedBy: kutterma $ | ||||||||||||||||||||||||||||
| 158 | $Id: Client.pm 391 2007-11-17 21:56:13Z kutterma $ | ||||||||||||||||||||||||||||
| 159 | $HeadURL: https://soap-wsdl.svn.sourceforge.net/svnroot/soap-wsdl/SOAP-WSDL/trunk/lib/SOAP/WSDL/Client.pm $ | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =cut | ||||||||||||||||||||||||||||