It's all about the answers!

Ask a question

Is it possible to use OSLC API's programmatically for RQM?


vijayakumar ramesh (105645) | asked Sep 03 '15, 7:56 a.m.
edited Sep 03 '15, 9:03 a.m.
I have a test case URI, need to fetch other details of it using OSLC API's of RQM.
I did it through REST client of fire fox manually it worked but programmatically I m facing issues. Want to know is it possible programmatically .Please mention if you have sample code.
 Code which I used
public static void main(String[] args) {
        //============== Code to adapt to your own configuration =============//
        String server = "https://local:host:9443/qm";        // Set the Public URI of your RRC server
        String JTS_Server = "https://local:host:9443/jts"; //Set the public URI of your JTS server
        String login = "admin";                                    // Set the user login
        String password = "admin;                                // Set the associated password
        //============== -------------------------------------- =============//
       
        String rootServices = server + "/rootservices";
        String catalogXPath = "/rdf:Description/oslc_qm:qmServiceProviders/@rdf:resource";
        String serviceProviderTitleXPath = "//oslc:ServiceProvider/dcterms:title";
       
        System.out.println(">> ExampleRQM02: Print out the content of the Service Providers catalog");
        System.out.println("    - Root Services URI: "+rootServices);
        System.out.println("    - Service Providers catalog XPath expression: "+catalogXPath);
        System.out.println("    - Service Provider title XPath expression: "+serviceProviderTitleXPath);
        System.out.println("    - Login: "+login);
    //    System.out.println("    - Password: "+password);

        // Setup the HttClient
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpUtils.setupLazySSLSupport(httpclient);
       
        // Setup the rootServices request
        HttpGet rootServiceDoc = new HttpGet(rootServices);
        rootServiceDoc.addHeader("Accept", "application/rdf+xml");
        rootServiceDoc.addHeader("OSLC-Core-Version", "2.0");
       
        try {
            // Request the Root Services document
            HttpResponse rootServicesResponse = HttpUtils.sendGetForSecureDocument(
                                                    server, rootServiceDoc, login, password, httpclient,JTS_Server);
           
            if (rootServicesResponse.getStatusLine().getStatusCode() == 200) {
                // Define the XPath evaluation environment
                XPathFactory factory = XPathFactory.newInstance();
                XPath xpath = factory.newXPath();
                xpath.setNamespaceContext(
                        new NamespaceContextMap(new String[]
                                {    "rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
                                    "oslc_qm","http://open-services.net/xmlns/qm/1.0/"}));

                // Parse the response body to retrieve the catalog URI
                InputSource source = new InputSource(rootServicesResponse.getEntity().getContent());
                Node attribute = (Node) (xpath.evaluate(catalogXPath, source, XPathConstants.NODE));
                String serviceProvidersCatalog = attribute.getTextContent();
                rootServicesResponse.getEntity().consumeContent();

                // Setup the catalog request
                HttpGet catalogDoc = new HttpGet(serviceProvidersCatalog);
                catalogDoc.addHeader("Accept", "application/xml");
                catalogDoc.addHeader("OSLC-Core-Version", "2.0");
               
                // Access to the Service Providers catalog
                HttpResponse catalogResponse = HttpUtils.sendGetForSecureDocument(
                                                            server, catalogDoc, login, password, httpclient,JTS_Server);
                if (catalogResponse.getStatusLine().getStatusCode() == 200) {
                    // Define the XPath evaluation environment
                    XPath xpath2 = factory.newXPath();
                    xpath2.setNamespaceContext(
                            new NamespaceContextMap(new String[]
                                    {    "oslc", "http://open-services.net/ns/core#",
                                        "dcterms","http://purl.org/dc/terms/"}));

                    // Parse the response body to retrieve the Service Provider
                    source = new InputSource(catalogResponse.getEntity().getContent());
                    NodeList titleNodes = (NodeList) (xpath2.evaluate(serviceProviderTitleXPath, source, XPathConstants.NODESET));
                   
                    // Print out the title of each Service Provider
                    int length = titleNodes.getLength();
                    System.out.println(">> Project Areas:");
                    for (int i = 0; i < length; i++) {
                        System.out.println(">> \t - "+ titleNodes.item(i).getTextContent());
                    }
                }
            }
            rootServicesResponse.getEntity().consumeContent();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XPathExpressionException e) {
            e.printStackTrace();
        } catch (InvalidCredentialsException e) {
            e.printStackTrace();
        } finally {
            // Shutdown the HTTP connection
            httpclient.getConnectionManager().shutdown();
        }
    }

Ouput:
Example03: Print out the content of the Service Providers catalog
    - Root Services URI: https://local:host:9443/qm/rootservices
    - Service Providers catalog XPath expression: /rdf:Description/oslc_qm:qmServiceProviders/@rdf:resource
    - Service Provider title XPath expression: //oslc:ServiceProvider/dcterms:title
    - Login: rak6si
>> GET(1) https://local:host:9443/qm/rootservices
>> Response Headers:
    - X-Powered-By: Servlet/3.0
    - ETag: "2QDRDqDuCTaRnsLnKGvDrhVzqVs="
    - Date: Fri, 28 Aug 2015 07:52:06 GMT
    - Expires: Fri, 28 Aug 2015 07:57:06 GMT
    - Cache-Control: public
    - Content-Type: application/rdf+xml; charset=UTF-8
    - Content-Language: en-US
    - Transfer-Encoding: chunked
>> GET(1) https://local:host:9443/qm/oslc_qm/catalog
>> Response Headers:
    - X-Powered-By: Servlet/3.0
    - X-com-ibm-team-repository-web-auth-msg: authrequired
    - Content-Type: text/html; charset=UTF-8
    - Content-Language: en-US
    - Set-Cookie: JazzFormAuth=Form; Path=/qm; Secure
    - Set-Cookie: x-com-ibm-team-scenario=71306067-db4b-4a0d-b786-b41c4d60b9b9%3Bname%3DInitial+Page+Load%3Bextras%3D%2Fqm%2Fauth%2Fauthrequired%2C1440748327005; Path=/
    - Transfer-Encoding: chunked
    - Date: Fri, 28 Aug 2015 07:52:06 GMT
    - Expires: Thu, 01 Dec 1994 16:00:00 GMT
    - Cache-Control: no-cache="set-cookie, set-cookie2"
[Fatal Error] :21:77: Der Verweis auf Entität "etag" muss mit dem Begrenzer ';' enden.
org.xml.sax.SAXParseException: Der Verweis auf Entität "etag" muss mit dem Begrenzer ';' enden.
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(Unknown Source)
    at org.apache.xpath.jaxp.XPathImpl.evaluate(Unknown Source)
    at net.jazz.oslc.consumer.examples.ExampleRQM02.main(ExampleRQM02.java:104)
------------------------------------------
javax.xml.xpath.XPathExpressionException: org.xml.sax.SAXParseException: Der Verweis auf Entität "etag" muss mit dem Begrenzer ';' enden.
    at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(Unknown Source)
    at org.apache.xpath.jaxp.XPathImpl.evaluate(Unknown Source)
    at net.jazz.oslc.consumer.examples.ExampleRQM02.main(ExampleRQM02.java:104)
Caused by: org.xml.sax.SAXParseException: Der Verweis auf Entität "etag" muss mit dem Begrenzer ';' enden.
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    ... 3 more 

Accepted answer


permanent link
Donald Nong (14.4k213) | answered Sep 04 '15, 2:42 a.m.
Your question should have been "what's wrong with my code".

If you check the response headers for the last GET request, you should understand what happened.
   - X-com-ibm-team-repository-web-auth-msg: authrequired
   - Content-Type: text/html; charset=UTF-8
You are not logged on when trying to accessing the second URL which is a secure one.

I believe you are using the sample code downloaded from jazz.net, and it does not handle newer versions of CLM correctly - the header "X-jazz-web-oauth-url" is not necessarily returned, while the header "X-com-ibm-team-repository-web-auth-msg" can contain the value "authrequired" to indicate the same thing. This is the same issue addressed in Bugzilla 389153.

You can modify the Java code (HttpUtils.java) similar to what has been changed for the said bug. Or find other sample codes (with form based authentication) that has been verified to work with your version of CLM as your starting point.
vijayakumar ramesh selected this answer as the correct answer

Comments
vijayakumar ramesh commented Sep 07 '15, 7:30 a.m.


// Access to the Service Providers catalog
                HttpResponse catalogResponse = HttpUtils.sendGetForSecureDocument(
                                                            server, catalogDoc, login, password, httpclient,JTS_Server);
I used above method which is used in sample program for RM, later when I use HttpResponse response = HttpUtils.sendGetForSecureDocument(
                server, catalogDoc, login, password, httpclient); of CM sample it will work fine. With this it passes security and works fine to access RQM server data.
Thanks for the support Guys :)

One other answer



permanent link
Ralph Schoon (56.0k23642) | answered Sep 03 '15, 8:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is definitely possible. RTC does it and there is code in the SDK. Eclipse Lyo does it as well.

I believe that there have been samples here in the forums. Searching for examples using Google could be a good idea.

Comments
vijayakumar ramesh commented Sep 03 '15, 9:02 a.m. | edited Sep 03 '15, 9:09 a.m.

 @Ralph Schoon 


I am sorry forgot to mention that I am trying it for RQM , is it possible for RQM through OSLC API's programmatically.


Ralph Schoon commented Sep 03 '15, 9:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

OSLC is a HTTP/HTTPS/REST based API and it does not matter what the provider is, it can be accessed programmatically using e.g. the Apache libraries. The answer above holds true.

Your answer


Register or to post your answer.