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

I have a CGI file that dispatches requests to a PERL module using SOAP::Lite. I read (http://cookbook.soaplite.com/#soap%20faults) that if I use "die" from the PERL module, SOAP::Lite will package the string given to "die" as the SOAP faultstring and return it to the client. I know that my PERL module is returning the string because I have tested the module on the server side. However, something goes wrong after the module returns its output such that my client gets the following error message (if I add print "Content-type..." in the CGI file) minus the delimiting "**********":

**********

not well-formed (invalid token) at line 1, column 581, byte 581 at /us +r/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi/XML/Parser.pm l +ine 185 Status: 500 Internal Server Error Content-Length: 747 Content-Type: text/xml; charset=utf-8 SOAPServer: SOAP::Lite/Perl/0.60 <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instanc +e" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:S +OAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http:/ +/www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xm +lsoap.org/soap/encoding/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring>ghrccatsvcs.cgi:GhrcCatSvcs:GhrcCatTableFields: ***Failed + to prepare SQL statement: ORA-00942: table or view does not exist ( +DBD ERROR: error possibly near <*> indicator at char 14 in 'SELECT * +FROM <*>amsu_sub_in WHERE 1 = 0') at GhrcCatSvcs.pm line 216. </faultstring> </SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope> at dbq_client_fi +elds line 51

*********

You can clearly see the "Failed to prepare SQL statement" faultstring embedded in the SOAP response, but all my client usually returns is "500 Internal Server Error at dbq_client_fields line 51. What am I doing wrong? Many thanks!

Replies are listed 'Best First'.
Re: Client-side error Handling (SOAP,CGI)
by jhourcle (Prior) on Jan 25, 2006 at 02:31 UTC

    From the looks of things, the error message in question isn't being escaped, and so XML::Parser is trying to read some of the items in the string as XML elements. (<*>).

    That's your bigger problem ... the SQL error is a problem, but it shouldn't cause the whole system to choke -- just throw an error (SOAP fault).

    So ... the problem isn't anything on the client side ... it's the server writing a bad SOAP message. If you want the client to be able to recover from transport errors (ie, HTTP 500), see SOAP::Lite's on_fault() method.

Re: Client-side error Handling (SOAP,CGI)
by ikegami (Patriarch) on Jan 24, 2006 at 23:36 UTC
    If you look at the error message, it indicates the service is trying to query the database table or view amsu_sub_in, but it does not exist. You have some kind of database problem.
Re: Client-side error Handling (SOAP,CGI)
by kwaping (Priest) on Jan 25, 2006 at 00:02 UTC
    My guess is that your client is paying attention only to the HTTP status header and not the content of the message itself. I can't say much more without further details being provided.
Re: Client-side error Handling (SOAP,CGI)
by Anonymous Monk on Jan 26, 2006 at 18:14 UTC
    I figured it out! The reason the XML parser was choking was due to the "<*>" tokens in $DBI:errstr. So, I set up a simple substitution on the DBI error string to replace "<" with "" and ">" with "". Then everything works fine. Thanks to all for pointing me in the right direction.
Re: Client-side error Handling (SOAP,CGI)
by Anonymous Monk on Jan 25, 2006 at 16:45 UTC
    Thanks for the replies so far. I am purposely creating the SQL/database error because I'm trying to work out error handling protocol via SOAP. I would be happy to provide more details, but I'm new to SOAP/CGI and not sure what's relevant. jhourcle, would you mind saying more about "escaping" the error message? If I just run a test case within the module itself, the following string is output:

    GhrcCatSvcs.pm:GhrcCatSvcs:GhrcCatTableFields: ***Failed to prepare SQL statement: ORA-00942: table or view does not exist (DBD ERROR: error possibly near <*> indicator at char 14 in 'SELECT * FROM <*>amsu_sub WHERE 1 = 0') at GhrcCatSvcs.pm line 216.

    Should I be encapsulating that in XML tags somehow?
Re: Client-side error Handling (SOAP,CGI)
by Anonymous Monk on Jan 26, 2006 at 18:16 UTC
    I figured it out! The reason the XML parser was choking was due to the "<*>" tokens in $DBI:errstr. So, I set up a simple substitution on the DBI error string to replace "<" with "[" and ">" with "]". Then everything works fine. Thanks to all for pointing me in the right direction.