Reputation: 410
I need to provide a number of web services to supply data from a Notes application to an external website.
I have created an XAgent with multiple custom REST service controls. Each control has its own "pathInfo" property and code defined in "doGet" to return a JSON object containing the relevant data required by the website.
This all works well and the correct data is returned by calls to each web service. However, having added some debug messages to each "doGet" I see that all services on the XPage are being triggered by a call to any one of them.
I have a couple of additional REST service controls on the same XPage with code defined in "doPost", used by the website to create records in the Notes database. This also works well with the desired results, but the debug messages show that when a call to one of these services is made all of the "get" services are also triggered.
Any idea what is going on here? I could create a separate XAgent for each REST service control, but it seems overkill if it's not necessary.
UPDATE
Here is a cut down version of the XPage with just two of the "get" services. It doesn't matter which of these services is called, the log messages show that getHospitals is triggered first followed by getCustomerTypes. However, the correct resultset is always returned.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex"
rendered="false">
<xp:this.beforePageLoad><![CDATA[#{javascript:var vwSettings:NotesView = database.getView("vwSettings");
var docSettings:NotesDocument = vwSettings.getFirstDocument();
sessionScope.put("App_DbPath", docSettings.getItemValueString("App_DbPath"));
sessionScope.put("WR_DbPath", docSettings.getItemValueString("WR_DbPath"));
sessionScope.put("logActivity", true);}]]></xp:this.beforePageLoad>
<xp:this.resources>
<xp:script src="/Utils.jss" clientSide="false"></xp:script>
<xp:script src="/OpenLogXPages.jss" clientSide="false"></xp:script>
</xp:this.resources>
<xe:restService id="restService1" pathInfo="getHospitals">
<xe:this.service>
<xe:customRestService contentType="application/json"
requestContentType="application/json" requestVar="hospital">
<xe:this.doGet><![CDATA[${javascript:try {
if (sessionScope.logActivity == true) {
log.logEvent("getHospitals");
}
var dbApp:NotesDatabase = sessionAsSigner.getDatabase(database.getServer(), sessionScope.App_DbPath);
var vwHospitals:NotesView = dbApp.getView("vhospitals.by.name");
var vecHospitals:NotesViewEntryCollection = vwHospitals.getAllEntries();
var eHospital:NotesViewEntry = vecHospitals.getFirstEntry()
var arrHospitals = new Array();
while (eHospital != null) {
var hospital = {};
hospital["Name"] = eHospital.getColumnValues()[0];
hospital["HCode"] = eHospital.getColumnValues()[1];
arrHospitals.push(hospital);
eHospital = vecHospitals.getNextEntry(eHospital);
}
log.logEvent("getHospitals - END");
return toJson(arrHospitals);
} catch(e) {
log.logError(e.toString());
}}]]></xe:this.doGet>
</xe:customRestService>
</xe:this.service>
</xe:restService>
<xe:restService id="restService2" pathInfo="getCustomerTypes">
<xe:this.service>
<xe:customRestService contentType="application/json"
requestContentType="application/json">
<xe:this.doGet><![CDATA[${javascript:try {
if (sessionScope.logActivity == true) {
log.logEvent("getCustomerTypes");
}
var dbApp:NotesDatabase = sessionAsSigner.getDatabase(database.getServer(), sessionScope.App_DbPath);
var vw:NotesView = dbApp.getView("vkeywords");
var vec:NotesViewEntryCollection = vw.getAllEntriesByKey("Customer Type");
var e:NotesViewEntry = vec.getFirstEntry()
var arrItems = new Array();
while (e != null) {
var item = {};
item["CustomerType"] = e.getColumnValues()[1];
arrItems.push(item);
e = vec.getNextEntry(e);
}
log.logEvent("getCustomerTypes - END");
return toJson(arrItems);
} catch(e) {
log.logError(e.toString());
}}]]></xe:this.doGet>
</xe:customRestService>
</xe:this.service>
</xe:restService>
And the services are called using
https://<<domain name>>/<<path name>>/ws.nsf/test.xsp/getHospitals
and
https://<<domain name>>/<<path name>>/ws.nsf/test.xsp/getCustomerTypes
Upvotes: 0
Views: 407
Reputation: 410
The problem was that the "doGet" properties were set to "compute on page load" rather than "compute dynamically". Not sure how that crept in - probably a copy and paste error.
Upvotes: 1