Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Trapping Network errors in SOAP::Lite

by shreya (Novice)
on Nov 01, 2006 at 18:29 UTC ( [id://581724]=perlquestion: print w/replies, xml ) Need Help??

shreya has asked for the wisdom of the Perl Monks concerning the following question:

SOAP:Lite is causing me nightmares. What I want to do is catch both message erros and network errors while sending a soap message. I have successfully achieve the former by making my soap connection as follows:
$soap = SOAP::Lite -> uri($config{'uri'}) -> on_action(sub {sprintf '"%s%s"', @_}) -> proxy("http://$proxy_to_use/LoadIntraday/LoadIntraDayDa +ta.asmx") -> on_fault( sub {} );
However I am not sucessfully able to trap Network transmission errors. By this I mean when the receiving server craps out halfway while receiving my message, its casusing my program to crash too. I simply want to catch this error and report it instead of exiting the program. I have tried using the eval block but have not succeeded. This is my current non working code
eval { my $elem = SOAP::Data->name('strFile')->value($soapdata)->type('st +ring'); $result = $soap->call(SOAP::Data->name('LoadIntraDaySwap')->attr({ +xmlns => 'https://www.primebroker.com/'}) => $elem ); }; # if eval reported an error if ($@) { #send out a email } else { # so no network error but there could be message errors if ($soap->transport->status =~ /Error/){ print $result->faultcode }else { print "Success" } }

Replies are listed 'Best First'.
Re: Trapping Network errors in SOAP::Lite
by jhourcle (Prior) on Nov 01, 2006 at 19:24 UTC

    You should look at what 'on_fault' does:

    on_fault()

    This lets you specify a handler for on_fault event. The default behavior is to die on an transport error and to do nothing on other error conditions. You may change this behavior globally (see "DEFAULT SETTINGS") or locally, for a particular object.

    So, by setting it to 'sub {}', you told it to ignore transport errors.

      By setting on_fault(sub{}) did not cause my program to ignore transport errors. My program crashed last week because when it was in middle of sending out a message the receiving server crashed. I thought setting on_fault (sub{}) would handle such issues but it apparently is not. Any advice ?

        I guess it's possible that it was thrown in such a way that SOAP::Lite did/could not catch it -- after all, as you said, it caused the program to die horribly.

        Typically with SOAP, transport errors include things such as HTTP errors, or the server not being available for whatever reason. So, by setting on_fault to an empty subroutine, you're suppressing most (maybe not all) transport errors.

        That being said -- are you sure that the SOAP call is what caused the program to crash? Could there have been something else in your program that did it? Can you duplicate the problem, and/or trace it to a specific section of code?

Re: Trapping Network errors in SOAP::Lite
by shreya (Novice) on Nov 02, 2006 at 14:38 UTC
    After a few more hours of rigorous debugging, the error was as expected, something very silly. I must thank jhourcle for sort of pointing it out. Setting on_fault to sub {} does cause the program to ignore all sorts of errors be it transmission or message related. My SOAP call was as follows:
    $result = $soap->call(SOAP::Data->name('LoadIntraDaySwap')->attr({ +xmlns => 'https://www.primebroker.com/'}) => $elem );
    In the event of a transmission error, $result would be set to undef. A statement in my code somewhere down the line said something like
    print $result->fault();
    Now I am trying to call an function for an undefined item. This caused the program to crash. Thanks again everyone for all your help.
Re: Trapping Network errors in SOAP::Lite
by shreya (Novice) on Nov 01, 2006 at 20:03 UTC
    By setting on_fault(sub{}) did not cause my program to ignore transport errors. My program crashed last week because when it was in middle of sending out a message the receiving server crashed. I thought setting on_fault (sub{}) would handle such issues but it apparently is not. Any advice ?
Re: Trapping Network errors in SOAP::Lite
by mda2 (Hermit) on Nov 02, 2006 at 14:08 UTC
    I prefer to think of SOAP::Lite is a great tool for SOAP protocol, and implement a wrapper for trap failures:

    Common faults:

    • Connect fail
    • Timeout on connection
    • Fault on server side

    --
    Marco Antonio
    Rio-PM

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://581724]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2024-04-19 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found