It's all about the answers!

Ask a question

Access RTC with OSLC using Javascript


usman syed ali (1539) | asked Jan 24 '16, 5:09 a.m.
edited Jan 24 '16, 5:09 a.m.
 Hi,

Below article explains how to connect/authenticate RTC using Java. 

http://www.ibm.com/developerworks/rational/library/rational-team-concert-oslc/

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



Comments
usman syed ali commented Jan 27 '16, 3:53 a.m. | edited Jan 27 '16, 9:59 p.m.

Apologies for the late reply. Really overwhelmed to see all the replies.


@Donald. I would like to show RTC work item details on a browser as an extension to RTC. So, I was thinking javascript could be the best way.

@Tamir & @Jim. I had a good look on both the things.

@Stefan, You are right Stefan, when I say javascript I mean inside the browser.







4 answers



permanent link
Tamir Gefen (7827) | answered Jan 24 '16, 10:59 a.m.
 Have you checked this RTC - JS article?

Regards,
Tamir Gefen, ALMtoolbox

permanent link
Donald Nong (14.3k213) | answered Jan 24 '16, 5:48 p.m.
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).

permanent link
Jim Amsden (19336) | answered Jan 25 '16, 10:30 a.m.
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
}
}

permanent link
Stefan Hufnagl (29411619) | answered Jan 26 '16, 10:19 a.m.
 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

Your answer


Register or to post your answer.