Access RTC with OSLC using Javascript
Hi,
http://www.ibm.com/developerworks/rational/library/rational-team-concert-oslc/
Below article explains how to connect/authenticate RTC using Java.
I would like to know if there is a way I can convert the above given code to Javascript. Can anybody please assist me with the code.
Thank You.
Regards,
Usman
4 answers
I am not a big fan of such idea. What do you want to do using OSLC within some JavaScript codes? Remember that when you are using JavaScript, you are already dealing with HTTP sessions. Do you want to open new HTTP connections for the OSLC requests? If not, you're probably looking at XHR, but I don't see the RTC JavaScript extension offers such capability (explicitly).
Here's some sample JavaScript code that connects to an OSLC server and gets the service provider catalog, which requires authentication. Note that the authentication challenge may occur at any time, so all requests should be prepared for the challenge.
/** * Connect to the server with the given credentials
*
* @param {string} userName - the user name or authentication ID of the user
* @param {string} password - the user's password credentials
* @param callback(err) - called when the connection is established
*/
OSLCServer.prototype.connect = function(userName, password, callback) {
var _self = this; // needed to refer to this inside nested callback functions
_self.userName = userName;
_self.password = password;
// Get the Jazz rootservices document for OSLC v2
// This does not require authentication
request.get(_self.serverURI+'/rootservices', function gotRootServices(err, response, body) {
if (err || response.statusCode != 200)
return console.error('Failed to read the Jazz rootservices resource '+err);
_self.rootServices = new RootServices(_self.serverURI+'/rootservices', body);
// Now get the ServiceProviderCatalog so that we know what services are provided
var catalogURI = _self.rootServices.serviceProviderCatalogURI(OSLCCM());
//require('request-debug')(request);
// This request will require authentication through FORM based challenge response
request.get(catalogURI, gotServiceProviderCatalog);
});
// Parse the service provider catalog, it will be needed for any other request.
function gotServiceProviderCatalog(err, response, body) {
if (response && response.headers['x-com-ibm-team-repository-web-auth-msg'] === 'authrequired') {
return request.post(_self.serverURI+'/j_security_check?j_username='+_self.userName+'&j_password='+_self.password, gotServiceProviderCatalog);
} else if (!response || response.statusCode != 200) {
return console.error('Failed to read the CM ServiceProviderCatalog '+err);
}
_self.serviceProviderCatalog = new ServiceProviderCatalog(response.request.uri.href, body);
callback(null); // call the callback with no error
}
}
Hi Usman,
I worked the last 6 month with Javascript inside a Open Social Widget.
When you say Javascript do you mean:
* Inside a Browser?
* NodeJS?
I ask because there are some differences you have to think about when you use a Browser:
* CORS
* Async Requests
If you work with a Browser I would recommend Chrome because he has the perfect Dev Tools.
BTW, OSLC isn't the only possibility. Have a look at my Blog clmpractice.org.
My personal opinion is that Javascript is the future because everything runs in the Browser
(except the RTC Client) and most of the other CLM Tools has no Java SDK.
Thx
Stefan
Comments
usman syed ali
Jan 27 '16, 9:59 p.m.Apologies for the late reply. Really overwhelmed to see all the replies.