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"
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";
System.out.println(workitemUrl);
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
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:resource": "https://qa-clm.pw.ge.com/ccm/resource/itemOid/com.ibm.team.workitem.Category/_TujlcM56EeukGqngl0HZyA",
"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:resource": "https://qa-clm.pw.ge.com/ccm/oslc/workflows/_JSWgwaSqEeqGIaAO2lNttQ/states/releaseschedule/releaseschedule.state.s3",
"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)
|
Accepted answer
David Honey (1.8k●1●7)
| 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
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
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.
Comments
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.
Hi Ralph,
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.
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).