Forum Discussion
Michel_van_der_
Nimbostratus
May 30, 2003SOAP::Lite expertise needed.
I want to get access to the ITCMCommon.OperationFailed parameters (primary_error_code,
secondary_error_code and error_string), but, not being much of a SOAP expert, I can't see
where the error gets encapsulated. E.g. the examples code shows:
if ( $soap_response->fault ) {
print $soap_response->faultcode, "(faultstring) ", $soap_response->faultstring, "\n";
print $soap_response->faultcode, "(faultdetail) ", $soap_response->faultdetail, "\n";
}
Which will give something like this:
SOAP-ENV:Server(faultstring) ITCMCommon::OperationFailed Exception caught on ITCMLocalLB::Monitor::get_node_monitor().
primary_error_code : 132
secondary_error_code: 0
error_string : Monitor template not found
SOAP-ENV:Server(faultdetail)
I don't know how to get this back as some sort of perl structure.
Anyone here now?
- Michel_van_der_
Nimbostratus
No worry, after getting SOAP::Lite to show me the trace, that all became clear to me. I'm - As promised here are some perl subroutines to do the dirty work.
Calling code ... if ( $soapResponse->fault ) { &printFault($soapResponse->faultcode, $soapResponse->faultstring); } ---------------------------------------------------------------------------- Print out a soap fault ---------------------------------------------------------------------------- sub printFault() { my ($faultCode, $faultString) = @_; my ($primary, $secondary, $str) = &getFaultDetails($faultString); print "Fault Code: $faultCode\n"; print "Fault Details:\n"; print " Primary Error Code: $primary\n"; print " Secondary Error Code: $secondary\n"; print " Error String: $str\n"; } ---------------------------------------------------------------------------- Extract the primary error code, secondary error code, and error string ---------------------------------------------------------------------------- sub getFaultDetails() { my ($faultString) = @_; my $primary_error_code; my $secondary_error_code; my $error_string; Split details into lines @lines = split("\n", $faultString); foreach $line (@lines) { split line into name : value pairs and trim strings @parts = split(":", $line); $name = &trimString(@parts[0]); $value = &trimString(@parts[1]); set values depending on detail element names. if ( "$name" eq "primary_error_code" ) { $primary_error_code = $value; } elsif ( "$name" eq "secondary_error_code" ) { $secondary_error_code = $value; } elsif ( $name eq "error_string" ) { $error_string = $value; } } return ($primary_error_code, $secondary_error_code, $error_string); } ---------------------------------------------------------------------------- Helper to trim leading and tailing whitespace from a string ---------------------------------------------------------------------------- sub trimString() { my ($str) = @_; $str =~ s/^ |\t|\n//; $str =~ s/\s*$//; return $str; }
- Currently the exceptions are returned in the content of the faultdetail. You will need to do perl string searches to extract the relevant codes. We were limited with the SOAPv1.1 schema in how we could include detail in the faults so we segmented them on separate lines in the faultdetail so line greps code be done for the exception elements (primary_error_code, secondary_error_code, error_string), then the string can be cut at the ":" for the relevant data. I will look into getting some perl code to do this later today and post it as a reponse to this thread.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects