line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Compile::SOAP::Daemon::Dancer2::Handler; |
2
|
3
|
|
|
3
|
|
26
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
85
|
|
3
|
3
|
|
|
3
|
|
13
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
68
|
|
4
|
3
|
|
|
3
|
|
10
|
use vars '$VERSION'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
149
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.1'; |
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
383
|
use parent 'XML::Compile::SOAP::Daemon'; |
|
3
|
|
|
|
|
216
|
|
|
3
|
|
|
|
|
19
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Log::Report 'xml-compile-soap-daemon'; |
10
|
|
|
|
|
|
|
use Encode; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use constant |
14
|
|
|
|
|
|
|
{ RC_OK => 200 |
15
|
|
|
|
|
|
|
, RC_METHOD_NOT_ALLOWED => 405 |
16
|
|
|
|
|
|
|
, RC_NOT_ACCEPTABLE => 406 |
17
|
|
|
|
|
|
|
, RC_SERVER_ERROR => 500 |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#-------------------- |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub init($) |
24
|
|
|
|
|
|
|
{ my ($self, $args) = @_; |
25
|
|
|
|
|
|
|
$self->SUPER::init($args); |
26
|
|
|
|
|
|
|
$self->_init($args); |
27
|
|
|
|
|
|
|
$self; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#------------------------------ |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _init($) |
33
|
|
|
|
|
|
|
{ my ($self, $args) = @_; |
34
|
|
|
|
|
|
|
$self->{preprocess} = $args->{preprocess}; |
35
|
|
|
|
|
|
|
$self->{postprocess} = $args->{postprocess}; |
36
|
|
|
|
|
|
|
$self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# PSGI request handler |
41
|
|
|
|
|
|
|
#will be called from the route |
42
|
|
|
|
|
|
|
#sub call($) |
43
|
|
|
|
|
|
|
#{ my ($self, $env) = @_; |
44
|
|
|
|
|
|
|
#my $res = eval { $self->_call($env) }; |
45
|
|
|
|
|
|
|
#$res ||= Plack::Response->new |
46
|
|
|
|
|
|
|
#( RC_SERVER_ERROR |
47
|
|
|
|
|
|
|
#, [Content_Type => 'text/plain'] |
48
|
|
|
|
|
|
|
#, [$@] |
49
|
|
|
|
|
|
|
#); |
50
|
|
|
|
|
|
|
#$res->finalize; |
51
|
|
|
|
|
|
|
#} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub handle($) |
54
|
|
|
|
|
|
|
{ my ($self, $dsl) = @_; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
notice __x"WSA module loaded, but not used" |
57
|
|
|
|
|
|
|
if XML::Compile::SOAP::WSA->can('new') && !keys %{$self->{wsa_input}}; |
58
|
|
|
|
|
|
|
$self->{wsa_input_rev} = +{ reverse %{$self->{wsa_input}} }; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#return $self->sendWsdl($req) |
61
|
|
|
|
|
|
|
#if $req->method eq 'GET' && uc($req->uri->query || '') eq 'WSDL'; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my $method = $dsl->request->method; |
64
|
|
|
|
|
|
|
my $ct = $dsl->request->content_type || 'text/plain'; |
65
|
|
|
|
|
|
|
$ct =~ s/\;\s.*//; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my ($rc, $msg, $err, $content, $mime); |
68
|
|
|
|
|
|
|
if($method ne 'POST' && $method ne 'M-POST') |
69
|
|
|
|
|
|
|
{ ($rc, $msg) = (RC_METHOD_NOT_ALLOWED, 'only POST or M-POST'); |
70
|
|
|
|
|
|
|
$err = 'attempt to connect via GET'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif($ct !~ m/\bxml\b/) |
73
|
|
|
|
|
|
|
{ ($rc, $msg) = (RC_NOT_ACCEPTABLE, 'required is XML'); |
74
|
|
|
|
|
|
|
$err = 'content-type seems to be '.$ct.', must be some XML'; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
else |
77
|
|
|
|
|
|
|
{ my $charset = $dsl->request->headers->content_type_charset || 'ascii'; |
78
|
|
|
|
|
|
|
my $xmlin = decode $charset, $dsl->request->content; |
79
|
|
|
|
|
|
|
my $action = $dsl->request->header('SOAPAction') || ''; |
80
|
|
|
|
|
|
|
$action =~ s/["'\s]//g; # sometimes illegal quoting and blanks " |
81
|
|
|
|
|
|
|
($rc, $msg, my $xmlout) = $self->process(\$xmlin, $dsl, $action); |
82
|
|
|
|
|
|
|
#($rc, $msg, my $xmlout) = (RC_OK, 'blab', XML::LibXML::Document->createDocument() ); |
83
|
|
|
|
|
|
|
#($rc, $msg, my $xmlout) = (RC_OK, 'blab', 'pppp' ); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
if(UNIVERSAL::isa($xmlout, 'XML::LibXML::Document')) |
86
|
|
|
|
|
|
|
{ $content = $xmlout->toString($rc == RC_OK ? 0 : 1); |
87
|
|
|
|
|
|
|
$mime = 'text/xml; charset="utf-8"'; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
$err = $xmlout; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
if( $err ) { |
96
|
|
|
|
|
|
|
$content = $err;# $bytes = "[$rc] $err\n"; |
97
|
|
|
|
|
|
|
$mime = 'text/plain'; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
$dsl->status( $rc ); |
100
|
|
|
|
|
|
|
$dsl->content_type( $mime ); |
101
|
|
|
|
|
|
|
$dsl->header( Warning => "199 $msg" ) if length( $msg ); |
102
|
|
|
|
|
|
|
#$dsl->content_length(length $bytes); |
103
|
|
|
|
|
|
|
return $content; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
#manage from the route itself |
107
|
|
|
|
|
|
|
#sub setWsdlResponse($;$) |
108
|
|
|
|
|
|
|
#{ my ($self, $fn, $ft) = @_; |
109
|
|
|
|
|
|
|
#local *WSDL; |
110
|
|
|
|
|
|
|
#open WSDL, '<:raw', $fn |
111
|
|
|
|
|
|
|
#or fault __x"cannot read WSDL from {file}", file => $fn; |
112
|
|
|
|
|
|
|
#local $/; |
113
|
|
|
|
|
|
|
#$self->{wsdl_data} = ; |
114
|
|
|
|
|
|
|
#$self->{wsdl_type} = $ft || 'application/wsdl+xml'; |
115
|
|
|
|
|
|
|
#close WSDL; |
116
|
|
|
|
|
|
|
#} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#sub sendWsdl($) |
119
|
|
|
|
|
|
|
#{ my ($self, $req) = @_; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#my $res = $req->new_response(RC_OK, |
122
|
|
|
|
|
|
|
#{ Warning => '199 WSDL specification' |
123
|
|
|
|
|
|
|
#, Content_Type => $self->{wsdl_type}.'; charset=utf-8' |
124
|
|
|
|
|
|
|
#, Content_Length => length($self->{wsdl_data}) |
125
|
|
|
|
|
|
|
#}, $self->{wsdl_data}); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#$res; |
128
|
|
|
|
|
|
|
#} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
#----------------------------- |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |