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

Exception::Class and SOAP::Lite

Expand Messages
  • Chris
    Hi, I m having a strange issue when I try to use Exception::Class and SOAP::Lite 0.55 under mod_perl. I m trying to add some easier error handling code to my
    Message 1 of 1 , Sep 10, 2002
    • 0 Attachment
      Hi,

      I'm having a strange issue when I try to use Exception::Class and
      SOAP::Lite 0.55 under mod_perl.

      I'm trying to add some easier error handling code to my Soap application
      and would like to use the same semantics in the SOAP pacakges as I do in
      the rest of the code.

      I have created a class My::Exceptions that uses Exception::Class to create
      some Exception Objects. I have created a new base Exceptions object
      My::Exceptions::Base that overloads some of the methods in
      Exceptions::Class. This works beautifully from the command line.

      I have created a package My::SOAP::Exceptions that re-defines the Handler
      for My::Error and My::Fault to throw SOAP::Fault objects instead of
      printing to STDERR.

      My problem comes in when calling using the SOAP package. If I throw an
      error in a SOAP method the Error object is re-defined. It is no-longer a
      hash based object but instead what appears to be a scalar based object. It
      appears that something is re-blessing my object after I capture it, which
      leads me to believe the problems lies with SOAP::Lite instead of simply
      mod_perl.

      To add to the complexity, if I use Exceptions::Class directly, and include
      all the method overloading into the SOAP class that's throwing the error
      everything works fine.

      If it helps I've included versions of the scripts below. I'm clueless as to
      what's going on here.

      -Chris

      --------- Begin Scripts ---------

      package My::Exceptions;
      $VERSION = 0.01;
      use strict;

      sub BEGIN {
      no strict;

      sub My::Exceptions::Base::full_message { return $_[0]->description; }
      sub My::Exceptions::Base::handler {
      print join " ", ("Untyped Exception Caught", $_[0]->as_string)
      }
      sub My::Exceptions::Base::details { return $_[0]->message; }
      sub My::Error::handler {
      print "Caught Error: ", '(', $_[0]->details, ')', "\n";
      print $_[0], ;
      }
      sub My::Fault::handler {
      print "Caught Fault:\n";
      print $_[0]->details, "\n";
      print $_[0]->trace()->as_string;
      }

      require Exception::Class;
      Exception::Class->import(
      'Soq::Exceptions::Base'=>{
      description => 'An Utyped Exception Has Occured'
      },
      'Soq::Error'=>{
      description => 'An Unexpected Error Has Occured',
      isa=>'Soq::Exceptions::Base'
      },
      'Soq::Fault'=>{
      description => 'An Unexpected Fault Has Occured',
      isa=>'Soq::Exceptions::Base'},
      'STUPID_USER'=>{
      description=>'Never do that again.'}
      );
      }

      --------Test Script------------

      package Soq::Test::Exception_Stuff;
      use strict;
      use lib 'c:\my\server';
      use My::Exceptions;

      eval {throw STUPID_USER("file does not exist");};
      if ($@) {
      $@= new Soq::Fault($@) unless ref $@;
      $@->handler();
      };

      ---------SOAP Exceptions Package----------

      package My::SOAP::Exceptions;
      $VERSION = 0.01;
      use strict;
      use My::Exceptions;
      use SOAP::Lite;

      sub BEGIN {
      no warnings;
      *My::Error::handler = \&generateSoapError;
      *My::Fault::handler = \&generateSoapFault;
      }

      sub generateSoapError {
      my ($error) = @_;
      use Data::Dumper;
      die SOAP::Fault->faultcode("SoqError:".ref $error)
      ->faultstring($error->as_string)
      ->faultdetail($error->details)
      ->faultactor('http://www.soaplite.com/custom');
      }

      sub generateSoapFault {
      my ($error) = @_;
      die SOAP::Fault->faultcode("SoqFault:".ref $error)
      ->faultstring($error->as_string)
      ->faultdetail($error->details)
      ->faultactor('http://www.soaplite.com/custom');
      }


      ----------Simple SOAP Method--------------

      package Soq::SOAP::Test_Exceptions;
      $VERSION = 0.01;
      use strict;
      use My::SOAP::Exceptions;

      sub throw_error {
      my $e = STUPID_USER->new();
      die $e->as_string;
      }


      package Soq::SOAP::Test_Exceptions2;
      $VERSION = 0.01;
      use strict;

      sub BEGIN {
      sub Test::Base::as_string { return "Test 1,2,3"; }
      sub TEST_ERROR::as_string { return "Test A,B,C"; }
      }

      use Exception::Class(
      'Test::Base',
      'TEST_ERROR'=>{isa=>'Test::Base'},
      'STUPID_USER'=>{isa=>'TEST_ERROR'}
      );

      sub throw_error {
      my $e = STUPID_USER->new();
      die $e->as_string;
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.