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 (712) | asked Jan 04 '23, 2:59 a.m.

The application version is 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?"

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": ""
            "rtc_cm:filedAgainst": {
                "rdf:type": [
                        "rdf:resource": ""
            "dcterms:identifier": "385206",
            "dcterms:type": "Release Schedule",
            "rtc_cm:state": {
                "rdf:type": [
                        "rdf:resource": ""

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 for further details.
org.apache.wink.json4j.JSONException: Expecting '{' on line 1, column 29 instead, obtained token: 'Token: String - '''
at org.apache.wink.json4j.internal.Parser.parseObject(
at org.apache.wink.json4j.internal.Parser.parse(
at org.apache.wink.json4j.internal.Parser.parse(
at org.apache.wink.json4j.JSONObject.<init>(
at com.test.Query.getWorkitemDetails(
at com.test.Query.main(

Ralph Schoon commented Jan 04 '23, 3:54 a.m.

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.

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.

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.

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 the response includes:

        <oslc:ServiceProviderCatalog rdf:about="">
            <oslc:domain rdf:resource=""/>
A GET on (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:
        a                          oslc:ServiceProvider ;
        jazz_disc:messageReceiver  <> ;
        jfs_proc:consumerRegistry  <> ;
        jfs_proc:globalConfigurationAware "compatible"^^rdf:XMLLiteral ;
        jfs_proc:supportContributionsToLinkIndexProvider "true"^^rdf:XMLLiteral ;
        jfs_proc:supportLinkDiscoveryViaLinkIndexProvider "false"^^rdf:XMLLiteral ;
        oslc:details               <> ;
        dcterms:title              "Jazz Reporting Service"^^rdf:XMLLiteral .
A GET on 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):
            a                   oslc:QueryCapability ;
            oslc:queryBase      <> ;
            oslc:resourceShape  <> ;
            oslc:resourceType   <> ;
            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.