Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

missing soap:fault when using eval{}

by Pickwick (Beadle)
on Jun 22, 2010 at 10:00 UTC ( [id://845868]=perlquestion: print w/replies, xml ) Need Help??

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

Hello all,

I have some missing SOAP-Faults with Soap:Lite 0.710.08 on Windows Server 2003 R2 SP2 32 Bit with ActivePerl-5.10.1.1007-MSWin32-x86-291969.msi. We have two simple webservices provided through SOAP::Transport::HTTP::CGI with each having it's own dispatcher CGI-script, it's own classes etc. Soap-Lite dispatches the requests using a class instance provided with dipsatch_with and this class instance create a new class instance with the real webservice logic, for example accessing the database and doing some stuff.

I recently found that under some circumstances when the logic implementing class dies, the execution stops as expected but the error message does not reach the client. In those circumstances Soap-Lite seems to generate and empty response from the called function, which is not what I need, of course. The first time I recognized this behaviour I hunted it down to the DESTROY method of the class with the logic which used an eval{} to catch errors from the method disconnecting from the database. I played a little bit and it seemd that only the existance of an eval{} with no code in it or elswhere in DESTROY made the difference: If the eval was present and I died somewhere in the class, Saop-Lite didn't generate a saup:Faul but an empty response from the called method. Without the eval{} Soap-Lite responded with a soap-Fault, as needed. I just deleted that eval{} because I didn't need it anymore.

Now I have the problem again and hunted it down to an eval{} in the Package DBIx::Log4perl::db. If this eval is present and my method dies after initiating the database connection using DBIx::Log4perl, SOAP-Lite again just generates empty method call responses. dieing before the database initialisation and therefore don't using DBIx::Log4perl generates a soap:Fault, as expected. Don't using DBIx::Log4perl but normally calling DBI->connect(...) does generate a soap:Fault even with establashing the database connection. But of course I want to use DBIx::Log4perl. I don't think it has something to do with DBIx::Log4perl directly because my second webservice does establish the database connection using DBIx::Log4perl and dieing in that webservice after connecting does produce a soap:Fault.

It seems it has something to do with the eval{} in some specific caller depth or stuff likie that, but I'm really stuck here. Do you have any idea under which circumstances SOAP-Lite may not be able to recognize a die properly or can't get the error message to produce a soap:Fault? Thanks for any hints!

One example response how it should be:

<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s +oapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:// +www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soa +p/envelope/"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>test2 at D:/Benutzer/tschoening/Eigene Dateien/E +clipse/Perl-Bibliotheken/stmodul/elrev_dotnet.pm line 5906.</faultstr +ing> </soap:Fault> </soap:Body> </soap:Envelope>

...and how it is with eval{} in DBIx::Log4perl::db present:

<soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s +oapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:// +www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soa +p/envelope/"> <soap:Body> <elrev_SchreibeLabelResponse xsi:nil="true" xmlns="http://localh +ost/elrev_dotnet"/> </soap:Body> </soap:Envelope>

Replies are listed 'Best First'.
Re: missing soap:fault when using eval{}
by Pickwick (Beadle) on Jun 22, 2010 at 12:06 UTC

    I've tested my code again and it seems I have this problem:

    http://search.cpan.org/~elliotjs/Perl-Critic-1.106/lib/Perl/Critic/Policy/ErrorHandling/RequireCheckingReturnValueOfEval.pm

    I do have DESTROY which is always called and calls DBIx::Log4perl::db::disconnect indirectly while disocnnecting from the database. In this function eval is used successfully, which resets $@ and SOAP-Lite can't detect the former die anymore, which let the code stop because of an error.

    What I don't understand is, if I do a eval{} myself to catch the exception and save $@ in a variable, $@ doesn't seem to be reset. If I die directly in that eval again, no matter if I die with $@ or something else, SOAP-Lite sends an empty response again.

    Won't work:

    eval { someClass->new()->someMethod(); } or die 'test';

    Does work:

    my $retVal = undef; eval { someClass->new()->someMethod(); } or $retVal = SOAP::Fault->new(faultstring => $@); die $retVal;

    $retVal will have the proper message from $@ from the die in someMethod. I would have expected that $@ is always cleared because of DESTROY is always called in the eval above.

Re: missing soap:fault when using eval{}
by Pickwick (Beadle) on Jun 23, 2010 at 13:45 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2024-03-19 07:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found