Loading ...
Sorry, an error occurred while loading the content.

RE: [soaplite] printing the SOAP Fault detail

Expand Messages
  • Paul Kulchenko
    Hi Brian, ... The returned result is just a hash, so you can handle it using code like this: my $detail = $response- faultdetail(); print
    Message 1 of 5 , Nov 18, 2002
    • 0 Attachment
      Hi Brian,

      > That seemed to get me one level in, but there are more levels.
      The returned result is just a hash, so you can handle it using code
      like this:

      my $detail = $response->faultdetail();
      print $detail->{cmweberr}->{source};
      # and so on

      If you just want to print this information you may use Data::Dumper
      as Duncan described (check the bin\SOAPsh.pl utility for Data::Dumper
      options).

      Best wishes, Paul.

      --- "Brian S. Merson" <brian.merson@...> wrote:
      > Hi Paul,
      >
      > That seemed to get me one level in, but there are more levels.
      > When I
      > added your suggested text, the code looked like:
      >
      > my $response = $login->Login($AppID, $Password);
      > unless ($response->fault) {
      > $SID->value($response->result());
      > print "Login succeeded: SID = ", $SID->value, "\n";
      > } else {
      > print "ERROR: A problem occurred while invoking Login\n";
      > print "\tfaultcode = ", $response->faultcode, "\n";
      > print "\tfaultstring = ", $response->faultstring, "\n";
      > my $detail = $response->faultdetail();
      > print join(': ', $_, $detail->{$_}), "\n" for keys
      > %$detail;
      > die "\nExiting program\n\n";
      > }
      >
      >
      > And the error output from this was:
      >
      > ERROR: A problem occurred while invoking Login
      > faultcode = SOAP-ENV:Client
      > faultstring = Unable to authenticate application.
      > cmweberr: HASH(0x1c51644)
      >
      > Exiting program
      >
      >
      > The pertinent part of the actual SOAP Fault XML looks like:
      >
      > ...
      > <cmf:cmweberr xmlns:cmf="http://www.kodak.com/cmweb/faults>
      > <cmf:source>error source string</cmf:source>
      > <cmf:code>12345678</cmf:code>
      > <cmf:hexcode>abcd0123</cmf:hexcode>
      > <cmf:moderror>12345</cmf:moderror>
      > </cmf:cmweberr>
      > ...
      >
      > As you can see, your suggestion printed out the "cmweberr" node
      > name,
      > but apparently did not go further. I assume that because cmweberr
      > itslef contains a number of nodes, this information is also
      > converted to
      > a hash. Therefore, I assume that what I really need to do is to
      > recursively walk down printing the node name and contents or
      > something
      > along those lines. Does this sound right? Unfortunately, this is
      > beyond my existing Perl expertise. :-) Any help will be
      > appreciated.
      >
      > Regards,
      >
      > Brian
      >
      >
      >
      > -----Original Message-----
      > From: Paul Kulchenko [mailto:paulclinger@...]
      > Sent: Thursday, November 14, 2002 2:55 PM
      > To: brian.merson@...; soaplite@yahoogroups.com
      > Subject: Re: [soaplite] printing the SOAP Fault detail
      >
      >
      > Hi Brian,
      >
      > > The Fault detail should be a string. In this particular case it
      > As far as I remember according to the SOAP spec the Fault detail
      > element
      > cannot be a string (or any other simple type):
      >
      > "All immediate child elements of the detail element are called
      > detail
      > entries and each detail entry is encoded as an independent element
      > within the detail element."
      >
      > Decoding this SOAP::Lite returns a hash in most cases (sometimes
      > object), which is exactly what you have in your code. You may
      > access the
      > content of this hash with this simple code:
      >
      > my $detail = $response->faultdetail();
      > print join(': ', $_, $detail->{$_}), "\n" for keys %$detail;
      >
      > Let me know if that doesn't help.
      >
      > Best wishes, Paul.
      >
      > --- "Brian S. Merson" <brian.merson@...> wrote:
      > > Hi all.
      > >
      > > Let me start by saying that I am in no way a Perl (or SOAP)
      > expert.
      > > :-)
      > > That said, I have a small Perl SOAP client program that seems to
      > be
      > > working. One place I do have a problem is when a SOAP Fault
      > occurs.
      > > By tracing at the server (or client) I can determine that the
      > SOAP
      > > message
      > > is correctly formatted. However, when I try to print the fault
      > > deta
      > > in the client I get something like "HASH(0xnnnnnnn)".
      > >
      > > For example, given the following code....
      > >
      > > # Call Login and check for error
      > > my $response = $login->Login($AppID, $Password);
      > > unless ($response->fault) {
      > > $SID->value($response->result());
      > > print "Login succeeded: SID = ", $SID->value, "\n";
      > > } else {
      > > print "ERROR: A problem occurred while invoking Login\n";
      > > print "\tfaultcode = ", $response->faultcode, "\n";
      > > print "\tfaultstring = ", $response->faultstring, "\n";
      > > print "\tfaultdetail = ", $response->faultdetail, "\n";
      > > die "\nExiting program\n\n";
      > > }
      > >
      > >
      > > I get the following output if I pass in a bogus password (for
      > > instance):
      > >
      > > ERROR: A problem occurred while invoking Login
      > > faultcode = SOAP-ENV:Client
      > > faultstring = Unable to authenticate application.
      > > faultdetail = HASH(0x1c50d78)
      > >
      > > Exiting program
      > >
      > >
      > > The Fault detail should be a string. In this particular case it
      > > happens to be an XML string (not XML-encoded), but I don't think
      > that
      > > that should make any difference. It is properly formatted in the
      > SOAP
      > > message and is available from other clients. My assumption is
      > that
      > > SOAP::Lite is packaging it into some kind of hash and returning
      > > that
      > > hash. However, I have no idea what hash key I would use to
      > > actually get
      > > back the fault string as it appears in the SOAP Fault.
      > >
      > > In short, I'm just trying to find out how to print out the text
      > that
      > > appeared within the SOAP Fault element of the SOAP message.
      > >
      > > This is probably a side-effect of my unfamilarity with Perl.
      > >
      > > Any help that anybody can provide will be appreciated.
      > >
      > > Regards,
      > >
      > > Brian
      > >
      > >
      > >
      > >
      > >
      >
      >
      > __________________________________________________
      > Do you Yahoo!?
      > Yahoo! Web Hosting - Let the expert host your site
      > http://webhosting.yahoo.com
      >
      >


      __________________________________________________
      Do you Yahoo!?
      Yahoo! Web Hosting - Let the expert host your site
      http://webhosting.yahoo.com
    Your message has been successfully submitted and would be delivered to recipients shortly.