Lapas

Thursday 3 December 2009

XPAGES and Domino Web Services

Primary question how to call domino web services from XPAGES with authorization. There is method to do it:
1. Use Apache AXIS API to access and work with web services (API ref: http://ws.apache.org/axis/java/apiDocs/index.html).
2. Create service using
var service:org.apache.axis.client.Service = new org.apache.axis.client.Service();
3. Create call
var call:org.apache.axis.client.Call = service.createCall();
4. For authorization purposes if domino user is logged in:
call.setMaintainSession(true); - !Important
call.setProperty("Cookie","SessionID="+cookie.get("SessionID").getValue()+",DomAuthSessId="+cookie.get("DomAuthSessId").getValue())
5. Then simply call then web service and get your result:
var xmlType = new javax.xml.rpc.encoding.XMLType();
call.setTargetEndpointAddress({webServiceAddress});
call.setOperationName( {operationName} );
call.addParameter("INPUT1", xmlType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter("INPUT2", xmlType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.setReturnType(xmlType.XSD_STRING);
var a = new java.lang.Object[2];
a[0] = "param1";
a[1] = "param2";
var rating = call.invoke(a);

Authorization for SSO based login:
If your server is using basic http authorization, then previous demonstrated code should be modified to support basic http authorization. So we need to copy information from http header and pass it in web service request.
1. use headerValues global variable
2. check if headerValues.AUTHORIZATION or headerValues.containsKey("AUTHORIZATION")
3. set it in call property like call.setProperty("AUTHORIZATION",headerValues.AUTHORIZATION.nextElement()) or call.setProperty("AUTHORIZATION",headerValues.get("AUTHORIZATION").nextElement()).

Why is to use nextElement()? headerValues.get("AUTHORIZATION") returns single value enumeration, so to get string value we need to get element from list.

Problem detected when using apache axis in xpages internal requests (made using ssj - Server Side Javascript) is that sometimes domino server java class loader stop working correcly loading apache axis class org.apache.axis.client.Service() - required restart to work correctly.