| 1 | # Copyrights 2007-2021 by [Mark Overmeer <markov@cpan.org>]. | ||
| 2 | # For other contributors see ChangeLog. | ||
| 3 | # See the manual pages for details on the licensing terms. | ||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||
| 5 | # This code is part of distribution XML-Compile-SOAP. Meta-POD processed | ||
| 6 | # with OODoc into POD and HTML manual-pages. See README.md | ||
| 7 | # Copyright Mark Overmeer. Licensed under the same terms as Perl itself. | ||
| 8 | |||
| 9 | package XML::Compile::SOAP::Operation; | ||
| 10 | use vars '$VERSION'; | ||
| 11 | $VERSION = '3.27'; | ||
| 12 | |||
| 13 | |||
| 14 | use warnings; | ||
| 15 | use strict; | ||
| 16 | |||
| 17 | use Log::Report 'xml-report-soap'; | ||
| 18 | |||
| 19 | use XML::Compile::Util qw/pack_type unpack_type/; | ||
| 20 | use XML::Compile::SOAP::Util qw/:wsdl11/; | ||
| 21 | |||
| 22 | use File::Spec (); | ||
| 23 | use List::Util qw(first); | ||
| 24 | use File::Basename qw(dirname); | ||
| 25 | |||
| 26 | my %servers = | ||
| 27 | ( 'XML::Compile::Daemon' => # my own server implementation | ||
| 28 | { xsddir => 'xcdaemon' | ||
| 29 | , xsds => [ qw(xcdaemon.xsd) ] | ||
| 30 | } | ||
| 31 | # more in XML::Compile::Licensed | ||
| 32 | ); | ||
| 33 | |||
| 34 | |||
| 35 | sub new(@) { my $class = shift; (bless {}, $class)->init( {@_} ) } | ||
| 36 | |||
| 37 | sub init($) | ||
| 38 | { my ($self, $args) = @_; | ||
| 39 | $self->{kind} = $args->{kind} or panic; | ||
| 40 | $self->{name} = $args->{name} or panic; | ||
| 41 | $self->{schemas} = $args->{schemas} or panic; | ||
| 42 | $self->_server_type($args->{server_type}); | ||
| 43 | |||
| 44 | $self->{transport} = $args->{transport}; | ||
| 45 | $self->{action} = $args->{action}; | ||
| 46 | |||
| 47 | my $ep = $args->{endpoints} || []; | ||
| 48 | my @ep = ref $ep eq 'ARRAY' ? @$ep : $ep; | ||
| 49 | $self->{endpoints} = \@ep; | ||
| 50 | |||
| 51 | # undocumented, because not for end-user | ||
| 52 | if(my $binding = $args->{binding}) { $self->{bindname} = $binding->{name} } | ||
| 53 | if(my $service = $args->{service}) { $self->{servname} = $service->{name} } | ||
| 54 | if(my $port = $args->{serv_port}){ $self->{portname} = $port->{name} } | ||
| 55 | if(my $port_type= $args->{portType}){ $self->{porttypename} = $port_type->{name} } | ||
| 56 | |||
| 57 | $self; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub registered | ||
| 61 | { # This cannot be resolved via dependencies, because that causes | ||
| 62 | # a dependency cycle which CPAN.pm cannot handle. This method was | ||
| 63 | # always called in <3.00 and moved to ::SOAP in >= 3.00 | ||
| 64 | error "You need to upgrade XML::Compile::WSDL11 to at least 3.00"; | ||
| 65 | } | ||
| 66 | |||
| 67 | sub _server_type($) | ||
| 68 | { my ($self, $type) = @_; | ||
| 69 | $type or return; | ||
| 70 | |||
| 71 | my $schemas = $self->schemas; | ||
| 72 | return if $schemas->{"did_init_server_$type"}++; | ||
| 73 | |||
| 74 | my ($def, $xsddir); | ||
| 75 | if($def = $servers{$type}) | ||
| 76 | { $xsddir = File::Spec->catdir(dirname(__FILE__), 'xsd', $def->{xsddir}); | ||
| 77 | } | ||
| 78 | else | ||
| 79 | { eval "require XML::Compile::Licensed"; | ||
| 80 | if($@) | ||
| 81 | { error __x"soap server type `{type}' is not supported (yet); installing XML::Compile::Licensed may help" | ||
| 82 | , type => $type; | ||
| 83 | } | ||
| 84 | ($xsddir, $def) = XML::Compile::Licensed->soapServer($type) | ||
| 85 | or error __x"soap server type `{type}' is not supported (yet)" | ||
| 86 | , type => $type; | ||
| 87 | } | ||
| 88 | |||
| 89 | $schemas->importDefinitions(File::Spec->catfile($xsddir, $_)) | ||
| 90 | for @{$def->{xsds}}; | ||
| 91 | } | ||
| 92 | |||
| 93 | #---------------- | ||
| 94 | |||
| 95 | sub schemas() {shift->{schemas}} | ||
| 96 | sub kind() {shift->{kind}} | ||
| 97 | sub name() {shift->{name}} | ||
| 98 | sub style() {shift->{style}} | ||
| 99 | sub transport() {shift->{transport}} | ||
| 100 | sub version() {panic} | ||
| 101 | |||
| 102 | sub bindingName() {shift->{bindname}} | ||
| 103 | sub serviceName() {shift->{servname}} | ||
| 104 | sub portName() {shift->{portname}} | ||
| 105 | sub portTypeName(){shift->{porttypename}} | ||
| 106 | |||
| 107 | |||
| 108 | sub soapAction {shift->{action}} | ||
| 109 | sub action() {shift->{action}} # deprecated | ||
| 110 | |||
| 111 | # wsaAction is implement in XML::Compile::SOAP::WSA | ||
| 112 | |||
| 113 | |||
| 114 | sub serverClass {panic} | ||
| 115 | sub clientClass {panic} | ||
| 116 | |||
| 117 | |||
| 118 | sub endPoints() { @{shift->{endpoints}} } | ||
| 119 | |||
| 120 | |||
| 121 | sub longName() | ||
| 122 | { my $self = shift; | ||
| 123 | ($self->serviceName // '') . '#' . $self->name; | ||
| 124 | } | ||
| 125 | |||
| 126 | #------------------------------------------- | ||
| 127 | |||
| 128 | |||
| 129 | sub compileTransporter(@) | ||
| 130 | { my ($self, %args) = @_; | ||
| 131 | |||
| 132 | my $transp = delete $args{transporter} || delete $args{transport}; | ||
| 133 | return $transp if ref $transp eq 'CODE'; | ||
| 134 | |||
| 135 | my $proto = $self->transport; | ||
| 136 | my @endpoints; | ||
| 137 | if(my $endpoints = $args{endpoint}) | ||
| 138 | { @endpoints = ref $endpoints eq 'ARRAY' ? @$endpoints : $endpoints; | ||
| 139 | } | ||
| 140 | unless(@endpoints) | ||
| 141 | { @endpoints = $self->endPoints; | ||
| 142 | if(my $s = $args{server}) | ||
| 143 | { s#^(\w+)://([^/]+)#$1://$s# for @endpoints; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | my $id = join ';', sort @endpoints; | ||
| 148 | my $send = $self->{transp_cache}{$proto}{$id}; | ||
| 149 | return $send if $send; | ||
| 150 | |||
| 151 | unless($transp) | ||
| 152 | { my $type = XML::Compile::Transport->plugin($proto) | ||
| 153 | or error __x"transporter type {proto} not supported (add 'use {pkg}'?)" | ||
| 154 | , proto => $proto, pkg => 'XML::Compile::Transport::SOAPHTTP'; | ||
| 155 | $transp = $type->new(address => \@endpoints, %args); | ||
| 156 | } | ||
| 157 | |||
| 158 | my $transport = $self->{transp_cache}{$proto}{$id} = $transp; | ||
| 159 | |||
| 160 | $transport->compileClient | ||
| 161 | ( name => $self->name | ||
| 162 | , kind => $self->kind | ||
| 163 | , action => $self->action | ||
| 164 | , hook => $args{transport_hook} | ||
| 165 | , %args | ||
| 166 | ); | ||
| 167 | } | ||
| 168 | |||
| 169 | |||
| 170 | sub compileClient(@) { panic "not implemented" } | ||
| 171 | sub compileHandler(@) { panic "not implemented" } | ||
| 172 | |||
| 173 | #--------------- | ||
| 174 | |||
| 175 | sub explain($$$@) | ||
| 176 | { my ($self, $wsdl, $format, $dir, %args) = @_; | ||
| 177 | panic "not implemented for ".ref $self; | ||
| 178 | } | ||
| 179 | |||
| 180 | |||
| 181 | sub parsedWSDL(%) | ||
| 182 | { my $self = shift; | ||
| 183 | panic "not implemented for ".ref $self; | ||
| 184 | } | ||
| 185 | |||
| 186 | 1; |