How to return data in JSON format in Eclipse, while using HTTP Client Query method ?
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"
The URL we got : https://qa-clm.pw.ge.com/ccm/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
Accepted answer
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.
Comments
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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
Jan 13 '23, 1:13 a.m.Hi Ralph,
Ralph Schoon
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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.
David Honey
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER 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).