I’m trying — and failing — to write a simple test app using SOAP::LITE to access an HP Service Manager site. (I’ve also tried SOAP::WSDL, but further reading made me believe that it really isn’t required for what I want to do.)
I’m new to SOAP, new to these packages, and new to what I’m trying to do, so I don’t know how many things I’m doing wrong, but I think I’ve distilled it down to a few lines of code that seem to me should work. I think the essential problem is in authentication, but I’ve also given some thought that it may be the way I’m trying to call the service manager routine via SOAP.
Here’s the first method I found:
#!/usr/local/perl5/bin/perl
use SOAP::Lite+trace => 'all';
$USER = "working_user_name";
$PASS = "working_password";
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
print "###\n";
print "###\n";
print "### Authenticating...\n";
print "###\n";
print "###\n";
return $USER => $PASS;
}
my $soap = SOAP::Lite->new(proxy => 'http://<hp_service_manager>:13080/SM/7/ws');
$soap->default_ns('http://schemas.hp.com/SM/7');
my $som = $soap->call('RetrieveList');
die $som->faultstring if ($som->fault);
print $som->result, "\n";
And the LWP method I tried:
#!/usr/local/perl5/bin/perl
use SOAP::Lite+trace => 'all';
use LWP::UserAgent;
use LWP::Debug;
LWP::Debug::level('+');
$USER = "working_user_name";
$PASS = "working_password";
my @ua_args = (keep_alive => 1);
my @credentials = ($SERVICE_NS, "", $USER, $PASS);
my $schema_ua = LWP::UserAgent->new(@ua_args);
$schema_ua->credentials(@credentials);
my $soap = SOAP::Lite->new(proxy => 'http://<hp_service_manager>:13080/SM/7/ws', @ua_args, credentials => \@credentials);
$soap->default_ns('http://schemas.hp.com/SM/7');
my $som = $soap->call('RetrieveList');
die $som->faultstring if ($som->fault);
print $som->result, "\n";
The issue is that no matter what I do I get a “not authorized” return. It’s an HP Service Manager installation. I’ll provide the WSDL entry for what I’m trying to do. I doubt it’s useful.
<soap:operation soapAction="RetrieveList" style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
While there is a lot more where this came from, this is the pertinent output, I believe:
SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH(0x845c630)
SOAP::Transport::HTTP::Client::send_receive: POST http://<service_manager>:13080/SM/7/ws HTTP/1.1
Accept: text/xml
Accept: multipart/*
Content-Length: 488
Content-Type: text/xml; charset=utf-8
SOAPAction: "#default_ns"
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><default_ns><c-gensym3 xsi:type="xsd:string">http://schemas.hp.com/SM/7</c-gensym3></default_ns></SOAP-ENV:Body></SOAP-ENV:Envelope>
SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH(0x8597238)
SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 401 Unauthorized
Connection: close
Date: Fri, 15 Feb 2013 19:42:06 GMT
Server: Apache-Coyote/1.1
WWW-Authenticate: Basic realm="CASM"
Content-Length: 40
Content-Type: text/html;charset=utf-8
Client-Date: Fri, 15 Feb 2013 19:42:07 GMT
Client-Peer: nnn.nn.nn.nn:13080
Client-Response-Num: 1
<HTML><BODY>Not Authorized</BODY></HTML>
Can anyone help? I’ve tried pretty much every example I’ve been able to find, and then tried variations of those examples, and I’ve never managed to get any futher. In every case I get a “Not Authorized” return.
Thanks,
Sean.
Don’t be mislead: SOAP::Lite’s debugging output doesn’t show the Authorization header (for some reason?).
The “overriding get_basic_credentials”-method globally sets the username/password, regardless of domain and realm. Which is actually a bad thing…
This (tested) piece of code should fix your issue:
Where “
<yourrealm>” should be set to “CASM”, “<yourpath>” should be set to “/SM/7/ws”, “<yourport>” should be set to “13080”.Old reply: Try doing it like this instead (note the extra asterisk):