SOAP-Clean
view release on metacpan or search on metacpan
lib/SOAP/Clean/Client.pm view on Meta::CPAN
}
}
return $results;
}
########################################################################
sub AUTOLOAD {
my $self = shift;
my $method_name;
if ( $AUTOLOAD =~ '.*::([^:]+)$' ) {
$method_name = $1;
} else {
$method_name = $AUTOLOAD;
}
return $self->invoke($method_name,@_);
}
sub invoke {
my $self = shift;
my $method_name = shift;
my $args = shift;
# $args is either a hash from arg names to values, or the first
# argument of the argument list.
if (ref $args ne "HASH") {
$args = [ $args, @_ ];
}
$self->_ensure_wsdl();
my $port = $self->{port};
my $location = $$port{location};
my $operations = $$port{operations};
my $operation = $$operations{$method_name};
assert(defined($operation),"No such method, $method_name");
# The base envelope
my ($request_method,$d);
if ($$operation{style} eq "rpc") {
($request_method,$d) =
$self->request_rpc($location,$method_name,$operation,$args);
} elsif ($$operation{style} eq "document") {
($request_method,$d) =
$self->request_document($location,$method_name,$operation,$args);
} else {
die;
}
# Encrypt the body and just add it in below, if the enc option was
# specified
if (defined($self->{enc})) {
SOAP::Clean::Security::encrypt_body($d,
$self->{privkeyenc},
$self->{pubkeyenc},
$self->{enctmpl},
$self->{appl});
}
# Sign the envelope
if (defined($self->{dsig})) { $self->_dsign_envelope($d); }
# Send it the request envelope and receive the response envelope
my $request_str = xml_to_string($d,1);
my $response =
$self->_comm($method_name,$location,$request_method,
{ 'Content-Type' => "text/xml",
'SOAPAction' => $$operation{soapAction} },
$request_str);
($response->code == 200)
|| die("SOAP request failed. Response follows:\n".
$response->as_string);
($response->content_type eq "text/xml")
|| die("SOAP response was not XML. Response follows:\n".
$response->as_string);
$d = xml_from_string($response->content);
#### DECRYPTION HERE #########
if (defined($self->{enc})) { $self->_decrypt_body($d); }
# Extract the results from the response
my @raw_results;
if ($$operation{style} eq "rpc") {
@raw_results =
$self->response_rpc($location,$method_name,$operation,$d);
} elsif ($$operation{style} eq "document") {
@raw_results =
$self->response_document($location,$method_name,$operation,$d);
} else {
die;
}
if (ref $args eq "HASH") {
my $results = {};
while ( $#raw_results >= 0 ) {
my $k = shift @raw_results;
my $v = shift @raw_results;
$$results{$k} = $v;
}
return $results;
} else {
my @results = ();
while ( $#raw_results >= 0 ) {
my $k = shift @raw_results;
my $v = shift @raw_results;
push @results,$v;
}
return wantarray ? @results : $results[0] ;
}
}
#########################################################################
sub request_rpc {
my ($self,$location,$method_name,$operation,$args) = @_;
( run in 0.717 second using v1.01-cache-2.11-cpan-71847e10f99 )