jhyland87 has asked for the wisdom of the Perl Monks concerning the following question:

So I have a custom module setup, heres the subroutine within it

sub new { my ($self, $settings) = (@_); die('Server not set for connection settings') if(!$settings->{ +'server'}); die('Username not set for connection settings') if(!$settings->{'u +sername'}); die('Password not set for connection settings') if(!$settings->{'p +assword'}); $settings->{'protocol'} = ($settings->{'protocol'}) ? $setting +s->{'protocol'} : "https"; $settings->{'port'} = ($settings->{'port'}) ? $settings->{' +port'} : "443"; my $proxy_uri = sprintf("https://%s:%s@%s:443/iControl/iControlPor +tal.cgi", $settings->{'username'},$settings->{'password'},$settings-> +{'server'}); $self->debug("Connection Settings:\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> +>>>>>>>>>>\n". Dumper($settings)."<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +<<<<<"); $self->debug("Connection URI: $proxy_uri"); $soap = SOAP::Lite->proxy($proxy_uri); if($soap->fault) { print "\nSoap Fault: ".$soap->faultcode." ".$soap->faultstring +." ".$soap->faultdetail."\n\n"; } return $soap; }

Pretty basic right? Just makes a soap authentication request. Heres the weird part. Notice I didnt make it die() if $soap->fault;, I just let it try to continue. Well, it throws an error, but it actually returns the expected data! Here it is:

Soap Fault: 1 1 1 Members in first pool: $VAR1 = bless( { 'address' => '1.2.3.4', 'port' => '80' }, 'Common::IPPortDefinition' );

So the code, string and detail are all just "1".... not much detail right? Now when I actually do a Data::Dumper on the faultcode, it shows a ton of data, and I found this in it.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode> <faultstring xsi:type="xsd:string">Unknown method &quot;{Unspecified}:faultcode +&quot;</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

Soooo the fault code, is unknown method: faultcode?... Someone make it make sense, lol

Replies are listed 'Best First'.
Re: SOAP::Lite fault seems faulty
by Anonymous Monk on Jan 05, 2012 at 19:48 UTC

    SOAP::Lite fault seems faulty

    Pretty basic right? Just makes a soap authentication request

    Soooo the fault code, is unknown method: faultcode?... Someone make it make sense, lol

    Nope, it is your program which is faulty ;) What is it you're expecting  $soap->fault to do?

     $soap->fault is really  $soap->call( 'fault' ), does your SOAP server have a fault method? faultcode method? faultstring method?

    #!/usr/bin/perl -- use SOAP::Lite; my $soap = SOAP::Lite ->proxy( 'http://localhost/blah/DummyService', timeout => 0.00001, ); $soap->transport->add_handler("request_send", \&pp_dump ); eval { $soap->fault; 1 } or print $@; print '#' x 33, "\n"; eval { $soap->faultcode; 1 } or print $@; print '#' x 33, "\n"; eval { $soap->faultstring; 1 } or print $@; print '#' x 33, "\n"; $soap->call('NONSENSE'); sub pp { use XML::Twig; open my($fh), '>', \my $str; no warnings 'newline'; XML::Twig->new( qw! pretty_print record ! )->parse( @_ )->print( $fh ); return $str; } sub pp_dump { { my $content = $_[0]->content(''); $_[0]->content( pp($content) ); } print $_[0]->as_string,"\n"; return; } __END__ POST http://localhost/blah/DummyService HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap User-Agent: SOAP::Lite/Perl/0.714 Content-Length: 391 Content-Type: text/xml; charset=utf-8 SOAPAction: "#fault" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:/ +/www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSche +ma-instance"> <soap:Body> <fault xsi:nil="true"/> </soap:Body> </soap:Envelope> 500 Can't connect to localhost:80 (timeout) at soap.lite.fault.pl line + 12 ################################# POST http://localhost/blah/DummyService HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap User-Agent: SOAP::Lite/Perl/0.714 Content-Length: 395 Content-Type: text/xml; charset=utf-8 SOAPAction: "#faultcode" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:/ +/www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSche +ma-instance"> <soap:Body> <faultcode xsi:nil="true"/> </soap:Body> </soap:Envelope> 500 Can't connect to localhost:80 (timeout) at soap.lite.fault.pl line + 14 ################################# POST http://localhost/blah/DummyService HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap User-Agent: SOAP::Lite/Perl/0.714 Content-Length: 397 Content-Type: text/xml; charset=utf-8 SOAPAction: "#faultstring" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:/ +/www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSche +ma-instance"> <soap:Body> <faultstring xsi:nil="true"/> </soap:Body> </soap:Envelope> 500 Can't connect to localhost:80 (timeout) at soap.lite.fault.pl line + 16 ################################# POST http://localhost/blah/DummyService HTTP/1.1 Accept: text/xml Accept: multipart/* Accept: application/soap User-Agent: SOAP::Lite/Perl/0.714 Content-Length: 394 Content-Type: text/xml; charset=utf-8 SOAPAction: "#NONSENSE" <?xml version="1.0" encoding="UTF-8"?> <soap:Envelope soap:encodingStyle="http://schemas.xmlsoap.org/soap/enc +oding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns: +soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http:/ +/www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSche +ma-instance"> <soap:Body> <NONSENSE xsi:nil="true"/> </soap:Body> </soap:Envelope> 500 Can't connect to localhost:80 (timeout) at soap.lite.fault.pl line + 18