It's all about the answers!

Ask a question

How to return data in JSON format in Eclipse, while using HTTP Client Query method ?


Y Deepak (713) | asked Jan 04 '23, 2:59 a.m.

The application version is 6.0.6.1 with iFix027.


We are trying to get a custom workitem type named Release Schedule and it's attributes details using HTTP Client Query method and the headers are "Content-Type", "application/json", "OSLC-Core-Version", "2.0", "Accept", "application/json"

This is the query we are using in the code :  String workitemUrl = cnfprop.getWebContextUrl() + "/oslc/contexts/_JSWgwaSqEeqGIaAO2lNttQ/workitems?"
+"oslc.where=rtc_cm:type=%22com.ibm.team.workitem.workItemType.p6%22&oslc.select=dcterms:identifier,dcterms:type,dcterms:title,rtc_cm:state,rtc_cm:plannedFor,rtc_cm:ownedBy,rtc_cm:filedAgainst";


We are hitting this URL in Boomerang and got the data in json format as seen below:

 "oslc:results": [
        {
            "rtc_cm:plannedFor": {
                "rdf:type": [
                    {
                        "rdf:resource": "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/Iteration"
                    }
                ]
            },
            "rtc_cm:filedAgainst": {
                "rdf:type": [
                    {
                        "rdf:resource": "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/Category"
                    }
                ]
            },
            "dcterms:identifier": "385206",
            "dcterms:type": "Release Schedule",
            "rtc_cm:state": {
                "rdf:type": [
                    {
                        "rdf:resource": "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/Status"
                    }
                ]

Where as in eclipse we are getting errors as shown below:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
org.apache.wink.json4j.JSONException: Expecting '{' on line 1, column 29 instead, obtained token: 'Token: String - 'java.io.BufferedReader@8bf312''
at org.apache.wink.json4j.internal.Parser.parseObject(Parser.java:193)
at org.apache.wink.json4j.internal.Parser.parse(Parser.java:130)
at org.apache.wink.json4j.internal.Parser.parse(Parser.java:95)
at org.apache.wink.json4j.JSONObject.<init>(JSONObject.java:138)
null
at com.test.Query.getWorkitemDetails(Query.java:214)
at com.test.Query.main(Query.java:55)



Comments
Ralph Schoon commented Jan 04 '23, 3:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

What does "In Eclipse" mean? What framework are you using? If you get this parsing error, I would assume that you get XML (or HTTML? ) back. So what do you get back? Log the response content, if possible, check if you are authenticated, make sure the headers are sent.  


Y Deepak commented Jan 13 '23, 1:13 a.m.

 Hi Ralph,

we are using Eclipse Version: Mars.2 Release (4.5.2) and we are using Spring MVC framework and we got HTML response back, and we are authenticated, also we are sure headers also sent. But the same parser error only we are getting. 

What could be the possible reasons for this type of issue. Was it due to any library files missing or any jars or missing? 

Thank you.




Ralph Schoon commented Jan 13 '23, 3:55 a.m. | edited Jan 13 '23, 7:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Maybe I am naive, but the error message suggests that the JSON received would start with a bracket { and the result you show does not. 


Try to make sure the JSON parser agrees with the response format? Add the brackets before parsing? Consider using RDF+XML? Not sure.


David Honey commented Jan 13 '23, 8:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

See my post below. You should not be using JSON for OSLC query capabilities since this is not an RDF media type, and the format of the returned data will not be defined by OSLC. Only JSON-LD is, and few, if any, of the OSLC query capabilities in ELM support JSON-LD. Instead, request a supported RDF media type (such as application/rdf+xml , application/turtle , text/turtle ) and process that returned RDF content (which won't be JSON).

Accepted answer


permanent link
David Honey (1.8k17) | answered Jan 04 '23, 4:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I hope that you're using discovery to determine the URI of an appropriate OSLC query capability rather than hardcoding or manually constructing such URIs. You should start with the with rootservices document to discover the URI of the OSLC Service Provider Catalog.

For example, from https://jazz.net/jazz/rootservices the response includes:

  <jd:oslcCatalogs>
        <oslc:ServiceProviderCatalog rdf:about="https://jazz.net/jazz/oslc/workitems/catalog">
            <oslc:domain rdf:resource="http://open-services.net/ns/cm#"/>
        </oslc:ServiceProviderCatalog>
  </jd:oslcCatalogs>
A GET on https://jazz.net/jazz/oslc/workitems/catalog (the OSLC Service Provider Catalog) with Oslc-Core-Version=2.0, Accept=application/rdf+xml returns the OSLC Service Provider catalog for EWM Change Management. This includes multiple OSLC service providers - one for each project area. So you have to discover which is the service provider for the project area of interest. For example, the service provider for the "Jazz Reporting Service" project area (expressed in Turtle) is:
 <https://jazz.net/jazz/oslc/contexts/_wWBVEBErEeWivdxTwnA1kg/workitems/services.xml>
        a                          oslc:ServiceProvider ;
        jazz_disc:messageReceiver  <https://jazz.net/jazz/web/com/ibm/team/workitem/web/EWMWorkitemsCopyHandler.html> ;
        jfs_proc:consumerRegistry  <https://jazz.net/jazz/process/project-areas/_wWBVEBErEeWivdxTwnA1kg/links> ;
        jfs_proc:globalConfigurationAware "compatible"^^rdf:XMLLiteral ;
        jfs_proc:supportContributionsToLinkIndexProvider "true"^^rdf:XMLLiteral ;
        jfs_proc:supportLinkDiscoveryViaLinkIndexProvider "false"^^rdf:XMLLiteral ;
        oslc:details               <https://jazz.net/jazz/process/project-areas/_wWBVEBErEeWivdxTwnA1kg> ;
        dcterms:title              "Jazz Reporting Service"^^rdf:XMLLiteral .
A GET on https://jazz.net/jazz/oslc/contexts/_wWBVEBErEeWivdxTwnA1kg/workitems/services.xml with Oslc-Core-Version=2.0, Accept=application/rdf+xml returns the details of that service provider. That service provider defines an OSLC service which declares the following OSLC query capability (expressed in Turtle):
        oslc:queryCapability
           [ 
            a                   oslc:QueryCapability ;
            oslc:queryBase      <https://jazz.net/jazz/oslc/contexts/_wWBVEBErEeWivdxTwnA1kg/workitems> ;
            oslc:resourceShape  <https://jazz.net/jazz/oslc/context/_wWBVEBErEeWivdxTwnA1kg/trs/shapes/workitems/query> ;
            oslc:resourceType   <http://open-services.net/ns/cm#ChangeRequest> ;
            oslc:usage          oslc:default ;
            dcterms:title       "Change request queries"^^rdf:XMLLiteral
            ] ;
You can find information about OSLC discovery in OSLC Core Version 3.0: Part 2: Discovery.

A GET on that base URI with Oslc-Core-Version=2.0, Accept=text/turtle returns a query response in Turtle. You can choose application/rdf+xml or other supported RDF media types.

Note that since OSLC is a set of RDF-based specifications, you should be asking for RDF content in your Accept header. While some OSLC endpoints might accept application/json , this is not an RDF representation is therefore not defined by OSLC. The EWM query base shown above will accept Accept=application/json and return JSON, but the format of this is not defined by any OSLC specifications. Some endpoints might not accept application/json . There is a media type for RDF expressed as JSON: application/ld+json . However, not all REST endpoints might accept it. For example, the EWM query base above does not. OSLC clients should therefore ask for RDF content by specifying a supported RDF media type in the Accept header, and then parse the RDF in the response body.

The best way to debug things like this is to use a web browser plugin such as RESTED, Postman etc. Get that working first. Then if your Java client code is doing something different, you will have to debug your Java code.

Ralph Schoon selected this answer as the correct answer

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.