Sakai web service gotchas
Sakai web service gotchas
The following are a few tricks I've picked up - I spent ages trying to figure these out and must have gotten a few extra grey hairs along the way. Hoefully these will save your sanity
HTTP vs HTTPS in Using Web Services
I was having difficulties connecting to the SakaiLogin.jws?wsdl file. I was trying to connect through Perl and using the SOAP::Lite module.
This simple fragment of code should have worked:
use SOAP::Lite; my $user = 'admin'; my $password = 'admin'; my $loginURI = "https://myserver/sakai-axis/SakaiLogin.jws?wsdl"; my $loginsoap = SOAP::Lite -> proxy($loginURI) -> uri($loginURI); my $session = $loginsoap->login($user, $password)->result; print "$session\n";
But I was getting a 500 Connect failed: connect: Connection refused; error.
At first I thought it might have been the self-signed certificate that we are using whilst we integrate, so we put in the certificate environment variables into the script as per the SOAP::Lite documentation so that the certificate and key could be found:
use SOAP::Lite; $ENV{'HTTPS_CERT_FILE'} = '/path/to/my/server/certificate.crt'; $ENV{'HTTPS_KEY_FILE'} = '/math/to/my/server/key.key'; ....
but still no luck. Same error.
Note re adding the environment variables
Since we are writing a script to connect to a web service, there is the possibility of having the script on a different machine altogether, but this would be restricted by having the environment variables hard coded into your script, so you should use a more flexible method of connecting over HTTPS to the web service provider.
Also, the certificate and key must be readable by the user executing the script that requires them otherwise you will get an errr saying they cannot be read. Allowing read access to the certificate and key might be an issue of security for you.
We then disabled SSL on the server and tried again, this time with the URL being HTTP instead of HTTPS, but this time I get a 404 Not Found error! The file clearly exists, I can browse to it and get the WSDL XML displayed on screen.
That got me thinking and finally I came up with...
The solution
We have our server setup so that Apache hands off the requests to Tomcat that it needs to, with Apache running on the standard port 80 and Tomcat running on port 8080. When browsing via the web, I access Sakai through port 80, but under the hood, Apache is handing off the requests to Tomcat and connecting through port 8080. Because I wasn't going through Apache with this Perl script, I needed to add the port to the URL to connect directly through Tomcat so the URL becomes: http://myserver:8080/sakai-axis/SakaiLogin.jws?wsdl
After I did that, the requests went through fine.
From Seth Theriault:
All my conns to Tomcat are fronted by Apache. I am using a Perl script with these URIs:
my $loginURI = "https://my.sakai.server/sakai-axis/SakaiLogin.jws?wsdl";
my $scriptURI = "https://my.sakai.server/sakai-axis/SakaiScript.jws?wsdl";
and see no problems.
Thanks Seth. Maybe it was just the UNE server setup that was presenting difficulties for me?!
A caveat with Perl and Web Services
Some of the web services (which are written in Java and implemented through Apache Axis) require boolean data types to be passed to them. However, Perl has no pure boolean datatypes. Sure, there are ways within Perl to signal a true or false value, but this does NOT extend outside of Perl. So the problem arises when you need to pass a boolean data type to a web service written in Java.
The solution is in Perl's SOAP::Lite module, which allows you to create boolean data types:
my $true = SOAP::Data->value('true')->type('boolean'); my $false = SOAP::Data->value('')->type('boolean');
This sets up some boolean typed parameters which can now be securely passed to a function requiring booleans!