You are here iC Home > Perl > SOAP > SOAP Error Handling

Perl

5.3.1 SOAP Error Handling

11.05.2008
5.3 SOAP [  up  ] - [ a - z ] - [ search PC ] - [ top ] 5.3.2 SOAP Basic Authorization

5.1   RSS 2.0
5.2   XML RPC
 5.2.1  XML::Parser
5.3   SOAP
 5.3.1  SOAP Error Handling
 5.3.2  SOAP Basic Authorization
 5.3.3  SOAP Array
 5.3.4  Google SOAP
 5.3.5  SOAP Examples
5.4   eBay API
 5.4.1  Example: get Ebay Time

SOAP::Lite

SOAP::Fault -- Provides support for Faults on server side

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.

Client

This client calls the faulthandler method and dies with following message:
*** SOAP Fault: Sorry. I died in server method foo at ./client_soap_array.pl line 27.
if the first element of array «arr» is 100.

Download files/soap/err handling client pl.txt
#!/usr/bin/perl -w

# -- Client

use SOAP::Lite
	on_fault => \&faulthandler;

print "Content-type: text/html\n\n";

my @arr = qw(107 foo 101 bar 102 more);

my $result = SOAP::Lite
  -> uri('http://sunri1.example.net/HelloSOAPArray')
  # -> proxy('http://localhost:7890')
  -> proxy('http://sunri1.example.net/cgi-bin/soap/server_soap_array.cgi')
  -> doFuncFoo(1000, 'Hans', 'Muster', \@arr)
  -> result;

print "<h3>Result is:</h3>\n";

foreach (@{$result}) {
	print "- $_<br>\n";
}

sub faulthandler {
  my ($soap, $res) = @_;
  die("*** SOAP Fault: " . $res->faultstring);
}

Server

Download files/soap/err handling server cgi.txt
#!/usr/bin/perl -w
use strict;

# -- Server
# -- SOAP::Lite

use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI
  -> dispatch_to('HelloSOAPArray')
  -> handle;

package HelloSOAPArray;

sub doFuncFoo(%) {
	my ($class, $id, $first, $last, $in_arr) = @_;

	my $res = "ID: $id / $first $last ";

	foreach (@{$in_arr}) {
		$res .= "[$_] ";
	}

	if ($in_arr->[0] == 100) {
		die SOAP::Fault
			->faultcode('Server.Custom') # will be qualified
                 	->faultstring('Sorry. I died in server method foo')
                 	->faultdetail(bless {code => 1} => 'BadError')
                 	->faultactor('http://www.soaplite.com/custom');
	}

	my @arr = qw();

	$arr[0] = 200;
	$arr[1] = $res;

	return \@arr;
}

__END__

Failed to access class (HelloSOAP): Can't locate HelloSOAP.pm in @INC (@INC contains:) at (eval 93) line 3.



See also:



Advanced search tips
5.3 SOAP [  up  ] - [ top ] 5.3.2 SOAP Basic Authorization



[ home ] - [ search ] - [ feedback ]

copyright by reto - created with mytexi