Skip to content

Commit

Permalink
Increase timeout and retry SOAP calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sanko committed Mar 16, 2012
1 parent 8d1d328 commit 95b306a
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/AnyEvent/MSN.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -887,34 +887,36 @@ has soap_requests => (isa => 'HashRef[AnyEvent::Util::guard]',
); );
sub _soap_request { sub _soap_request {
my ($s, $uri, $headers, $content, $cb) = @_; my ($s, $uri, $headers, $content, $cb, $attempt) = @_;
$attempt //= 1;
return if $attempt++ >= 5; # Give up after a few failed attempts
my %headers = ( my %headers = (
'user-agent' => 'MSNPM 1.0', 'user-agent' => 'MSNPM 1.0',
'content-type' => 'application/soap+xml; charset=utf-8; action=""', 'content-type' => 'application/soap+xml; charset=utf-8; action=""',
'Expect' => '100-continue', 'Expect' => '100-continue',
'connection' => 'Keep-Alive' 'connection' => 'Keep-Alive'
); );
#warn $content;
@headers{keys %$headers} = values %$headers; @headers{keys %$headers} = values %$headers;
$s->_add_soap_request( $s->_add_soap_request(
$uri, $uri,
AnyEvent::HTTP::http_request( AnyEvent::HTTP::http_request(
POST => $uri, POST => $uri,
headers => \%headers, headers => \%headers,
timeout => 15, timeout => 20 * $attempt,
persistent => 1, persistent => 1,
body => $content, body => $content,
sub { sub {
my ($body, $hdr) = @_; my ($body, $hdr) = @_;
# Cheap retry
return $s->_soap_request($uri, $headers, $content, $cb,
$attempt)
if !$body;
my $xml = $s->_parse_xml($body); my $xml = $s->_parse_xml($body);
$s->_del_soap_request($uri); $s->_del_soap_request($uri);
return $cb->($xml) return $cb->($xml)
if $hdr->{Status} =~ /^2/ if $hdr->{Status} =~ /^2/
&& !defined $xml->{'S:Fault'}; && !defined $xml->{'S:Fault'};
#dd $hdr;
#dd $xml;
$s->_trigger_error( $s->_trigger_error(
$xml->{'soap:Body'}{'soap:Fault'}{'soap:Reason'} $xml->{'soap:Body'}{'soap:Fault'}{'soap:Reason'}
{'soap:Text'}{'content'} {'soap:Text'}{'content'}
Expand Down Expand Up @@ -1180,10 +1182,8 @@ sub _parse_xml {
my ($s, $data) = @_; my ($s, $data) = @_;
state $xml_twig //= XML::Twig->new(); state $xml_twig //= XML::Twig->new();
my $xml = {}; my $xml = {};
use Carp;
=begin comment Carp::confess('...') if ! length $data ; # Carp::confess('...') if ! length $data ;
=cut
try { try {
$xml_twig->parse($data); $xml_twig->parse($data);
$xml = $xml_twig->simplify(keyattr => [qw[type id value]]); $xml = $xml_twig->simplify(keyattr => [qw[type id value]]);
Expand Down

0 comments on commit 95b306a

Please sign in to comment.