SOAP::LIte on_fault 没有覆盖默认的错误处理
SOAP::LIte on_fault not overriding default error handling
森托斯 5 |
Perl 5.10.0 |
SOAP::Lite1.20
阅读了使用 on_fault 替代 SOAP::Lite 的默认错误处理的文档后,我希望以下代码使用回调进行错误处理。但是,我看到的是正在使用默认值
#!/usr/bin/perl
use strict;
use SOAP::Lite;
my $log #calls to Log4Perl
my $soapServer = "http://somelocation/services/GdeWsOpenAPI?wsdl"
my $soap = new SOAP::Lite();
$soap->on_fault( \&soapError );
$soap->service($soapServer);
sub soapError {
my($soap, $res) = @_;
my $message = ref $res ? $res->faultstring : $soap->transport->status;
$log->write( "fatal connection error to server $SoapServer: $message.", 0);
print STDERR "connection error: $message\n";
exit 1;
}
输出为:
无法加载服务描述“http://somelocation/services/GdeWsOpenAPI?wsdl”:500 无法连接到 somelocation:80
预计(由于传输错误):
连接错误:无法加载服务描述“http://somelocation/services/GdeWsOpenAPI?wsdl”:500 无法连接到 somelocation:80
我错过了什么?
故障是服务器发出的一种特殊类型的响应,表示 "something went wrong with your request"。那里发生的事情不是故障,它根本无法连接到服务器。您可能需要为此使用 Try::Tiny。
回调是针对进行 SOAP 调用时出现的问题。你还没到那一步。
my $soap = SOAP::Lite->new();
$soap->on_fault( \&soapError );
eval { $soap->service($soapServer); 1 }
or die("Can't initialize the web service: $@");
森托斯 5 | Perl 5.10.0 | SOAP::Lite1.20
阅读了使用 on_fault 替代 SOAP::Lite 的默认错误处理的文档后,我希望以下代码使用回调进行错误处理。但是,我看到的是正在使用默认值
#!/usr/bin/perl
use strict;
use SOAP::Lite;
my $log #calls to Log4Perl
my $soapServer = "http://somelocation/services/GdeWsOpenAPI?wsdl"
my $soap = new SOAP::Lite();
$soap->on_fault( \&soapError );
$soap->service($soapServer);
sub soapError {
my($soap, $res) = @_;
my $message = ref $res ? $res->faultstring : $soap->transport->status;
$log->write( "fatal connection error to server $SoapServer: $message.", 0);
print STDERR "connection error: $message\n";
exit 1;
}
输出为: 无法加载服务描述“http://somelocation/services/GdeWsOpenAPI?wsdl”:500 无法连接到 somelocation:80
预计(由于传输错误): 连接错误:无法加载服务描述“http://somelocation/services/GdeWsOpenAPI?wsdl”:500 无法连接到 somelocation:80
我错过了什么?
故障是服务器发出的一种特殊类型的响应,表示 "something went wrong with your request"。那里发生的事情不是故障,它根本无法连接到服务器。您可能需要为此使用 Try::Tiny。
回调是针对进行 SOAP 调用时出现的问题。你还没到那一步。
my $soap = SOAP::Lite->new();
$soap->on_fault( \&soapError );
eval { $soap->service($soapServer); 1 }
or die("Can't initialize the web service: $@");