Forum Discussion

Michel_van_der_'s avatar
Icon for Nimbostratus rankNimbostratus
May 30, 2003

SOAP::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 



I don't know how to get this back as some sort of perl structure.



Anyone here now?

3 Replies

  • No worry, after getting SOAP::Lite to show me the trace, that all became clear to me. I'm


    already doing exactly what you suggested.



    I've made more progress in the last 1.5 days than I did for 2 weeks when I first started


    to look at iControl 2.1.



    Can't say enough times how useful this forum is for me.
  • 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; 



    You should be able to adapt this to suit your needs.



  • 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.



    BTW, With the upcoming SOAP v1.2 faults, more detail will be able to be included in the soapfault elements!