File Coverage

blib/lib/SOAP/WSDL/Server/Simple.pm
Criterion Covered Total %
statement 56 62 90.3
branch 7 8 87.5
condition 3 5 60.0
subroutine 13 13 100.0
pod 1 1 100.0
total 80 89 89.8


line stmt bran cond sub pod time code
1             package SOAP::WSDL::Server::Simple;
2 1     1   817 use strict;
  1         2  
  1         23  
3 1     1   3 use warnings;
  1         1  
  1         14  
4              
5 1     1   418 use Encode;
  1         6002  
  1         49  
6              
7 1     1   344 use HTTP::Request;
  1         10270  
  1         27  
8 1     1   373 use HTTP::Response;
  1         3678  
  1         20  
9 1     1   15 use HTTP::Status;
  1         1  
  1         180  
10 1     1   4 use HTTP::Headers;
  1         1  
  1         28  
11 1     1   2 use Scalar::Util qw(blessed);
  1         1  
  1         39  
12              
13 1     1   3 use Class::Std::Fast::Storable;
  1         1  
  1         7  
14              
15 1     1   108 use base qw(SOAP::WSDL::Server);
  1         1  
  1         227  
16              
17             our $VERSION = 3.003;
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             sub handle {
27 3     3 1 4499 my ($self, $cgi) = @_;
28              
29 3         4 my $response;
30              
31 3         5 my $content = $cgi->param('POSTDATA');
32              
33 72 100       160 my $request = HTTP::Request->new(
    100          
34             $ENV{'REQUEST_METHOD'} || '' => $ENV{'SCRIPT_NAME'},
35             HTTP::Headers->new(
36             map {
37 3   50     50 (/^HTTP_(.+)/i
38             ? ($1=~m/SOAPACTION/)
39             ?('SOAPAction')
40             :($1)
41             : $_
42             ) => $ENV{$_}
43             } keys %ENV),
44             $content,
45             );
46              
47             # we copy the response message around here.
48             # Passing by reference would be much better...
49 3         1764 my $response_message = eval { $self->SUPER::handle($request) };
  3         15  
50              
51             # caveat: SOAP::WSDL::SOAP::Typelib::Fault11 is false in bool context...
52 3 100 66     22 if ($@ || blessed $@) {
53 2         4 my $exception = $@;
54 2         9 $response = HTTP::Response->new(500);
55 2         75 $response->header('Content-type' => 'text/xml; charset="utf-8"');
56 2 50       92 if (blessed($exception)) {
57 0         0 $response->content( $self->get_serializer->serialize({
58             body => $exception
59             })
60             );
61             }
62             else {
63 2         8 $response->content($exception);
64             }
65             }
66             else {
67 1         3 $response = HTTP::Response->new(200);
68 1         25 $response->header('Content-type' => 'text/xml; charset="utf-8"');
69 1         32 $response->content( encode('utf8', $response_message ) );
70             {
71 1     1   4 use bytes;
  1         1  
  1         4  
  1         42  
72 1         3 $response->header('Content-length', length $response_message);
73             }
74             }
75              
76 3         56 $self->_output($response);
77 3         2672 return;
78             }
79              
80             sub _output :PRIVATE {
81 0         0 my ($self, $response) = @_;
82 0         0 my $code = $response->code;
83 0         0 binmode(STDOUT);
84 0         0 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 0         0 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     1   135 }
  1         1  
  1         5  
92              
93             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.
123              
124             SOAP::WSDL::Server::Simple dispatches all calls to appropriately named methods in the
125             class or object set via C.
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 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 Emartin.kutter fen-net.deE
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