Question on calling a service from RTC WebUI
Hi! I'm new to Jazz and RTC and have faced a task of creating a simple plugin.
I have a service plugin providing com.example.hellojazz.common.service.IHelloJazzService (took it from this tutorial)
and a web page com.test.app.ui.web.ui.internal.page.pageTest from here.
When I run the page with contents from the tutorial, it works fine. But when I add some code to call my service, I get Resource does not exist: com.test.app.ui.web.ui.internal.page.pageTest.js exception. The page is in the same place, of cource. Below is the code of the page, bold is the one I added (from here, listing 6-8).
I'll be grateful for any help on this problem.
-------------------
dojo.provide("com.test.app.ui.web.ui.internal.page.pageTest");
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.require("net.jazz.ajax.ui.PlatformUI");
dojo.require("com.ibm.team.repository.web.transport.ServiceRequest");
dojo.require("com.ibm.team.repository.web.transport.ServiceResponseHandler");
dojo.require("com.ibm.team.repository.web.transport.TeamServerClient");
(function(){
var PlatformUI = net.jazz.ajax.ui.PlatformUI;
var hiCount = 0;
dojo.declare("com.test.app.ui.web.ui.internal.page.pageTest", [dijit._Widget, dijit._Templated], {
templateString: "<div><div dojoAttachPoint='hiJazzAttachPoint'>uninitialized</div></div>",
postCreate: function(){
var ActionRegistry = PlatformUI.getWorkbench().getActionRegistry();
ActionRegistry.registerAction("com.test.app.ui.web.testAction", this, "testAction");
},
testAction: function(){
var ServiceRequest = com.ibm.team.repository.web.transport.ServiceRequest;
var ServiceResponseHandler = com.ibm.team.repository.web.transport.ServiceResponseHandler;
var TeamServerClient = com.ibm.team.repository.web.transport.TeamServerClient;
var handler = {
_success: function(done){
console.log("success + done);
}
},
_failure: function(done){
console.log("failure + done);
}
};
var srh = new ServiceResponseHandler(handler, "_success", "_failure");
var reqParms= {
param1: value1,
param2: value2,
};
var serviceRequest =
new ServiceRequest("com.example.hellojazz.common.service.IHelloJazzService",
"test",reqParms );
var cback = TeamServerClient.invokeService(serviceRequest, srh);
hiCount++;
this.hiJazzAttachPoint.removeChild(this.hiJazzAttachPoint.firstChild);
this.hiJazzAttachPoint.appendChild(document.createTextNode("Hi from Jazz!!! (" + hiJazz + ")"));
}
});
})();
Accepted answer
To convert the Hello Jazz service to be a modelled REST service, I think you'll need to do this:
- Change the IHelloJazzService interface to extend the ITeamModelledRestService interface
-
Change the service method name from "sayHello" to something like "getHelloMessage" (must start with "get")
- In the component extension declaration, change the service type from RPC to MODELLED_REST
-
Change your Javascript code to use "getHelloMessage" as the method name
2 other answers
I've altered the service invocation code to look like this:
var self= this;var handlerObject= {
success: function(resultList) {
self._displayResults(resultList);
},
failure: function(errorObj) {
self.handleError(errorObj,"Error getting remote data.");
}
};
var responseHandler= new ServiceResponseHandler(handlerObject, "success", "failure");
var reqParms= {
};
var serviceRequest =
new ServiceRequest("com.example.hellojazz.common.service.IHelloJazzService",
"sayHello",reqParms ); var cback = TeamServerClient.invokeService(serviceRequest, srh);
Now the page loads, but I get a JavaScript error: TypeError: _13.match(_14) is null which comes from
com.ibm.team.repository.web.transport.ServiceRequest._validateMethod=function(_13){ if(!dojo.isString(_13)){ return false; } var _14=/^(get|post)/; var _15=_13.match(_14)[0]; return _15!==null; };
and actually says nothing to me except that something is wrong with my service request.