How to post JSON with the Lyo RestClient? [message #1798637] |
Wed, 21 November 2018 13:41  |
Eclipse User |
|
|
|
Hi, I am trying to send JSON instead of RDF/XML.
JsonObject changeSet = Json.createObjectBuilder().add("name", "Import-Type-System-CS-" + TimeStampUtil.getTimestamp()).add("configurationId", target.getAbout().toString()).build();
ClientResponse response = client.createResource(changesetFactotryURL, changeSet, "application/json");
Unfortunately I get the following error:
A javax.ws.rs.ext.MessageBodyWriter implementation was not found for the class org.glassfish.json.JsonObjectBuilderImpl$JsonObjectImpl type and application/json; charset=UTF-8 media type. Verify that all entity providers are correctly registered. Add a custom javax.ws.rs.ext.MessageBodyWriter provider to handle the type and media type if a JAX-RS entity provider does not currently exist.
I am trying to figure out how to solve the issue. I recognize I have
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.2</version>
</dependency>
in my pom and I am using the libraries to create the JSON data.
I added a different JSON library and the error message change to that.
I have found several hints in the internet, that I was unfortunately not really able to understand.
Are there any examples around sending JSON using the OSLC Client?
Any idea what I could do?
|
|
|
|
Re: How to post JSON with the Lyo RestClient? [message #1798729 is a reply to message #1798637] |
Fri, 23 November 2018 10:43   |
Eclipse User |
|
|
|
Hello Ralph,
May I ask what is your case for using JSON? To follow-up on that, do you know that OSLC v2 servers only support a quite specific kind of JSON and only v3 servers MAY support JSON-LD?
Now onto your next question how to use Lyo Client to send JSON. In any case, to generate conformant data we use special helpers. This means you cannot use a JsonObjectBuilder from Java EE but instead have to follow Jad's example and pass CT_JSON instead of CT_RDF.
Offtopic: it escapes me why do we have two OSLCConstants classes with identical names both in core and client libs.
Does this help you with your question, Ralph?
Finally, we are trying to consolidate all OSLC-related discussion on https://forum.open-services.net/ and you are welcome to post new questions there.
|
|
|
Re: How to post JSON with the Lyo RestClient? [message #1798741 is a reply to message #1798708] |
Fri, 23 November 2018 12:56   |
Eclipse User |
|
|
|
Hi Jad,
I have used the annotations for RDF and understand them now. I was not sure how to translate that to JSON. Maybe just the naive way and enter the data in a similar way. I will try that, thanks!
I have created the JSON object and I am passing it as string at the moment. That definitely also works.
Thanks!
Ralph
[Updated on: Fri, 23 November 2018 12:57] by Moderator Report message to a moderator
|
|
|
Re: How to post JSON with the Lyo RestClient? [message #1798746 is a reply to message #1798741] |
Fri, 23 November 2018 13:21  |
Eclipse User |
|
|
|
Hi Andrii,
the simple truth is, that this is an internal API I was able to find looking at the web browser messages. I have captured the format it uses. I have confirmed with development that there is no OSLC compatible API for this activity.
Since I am using the OSLC4J client, I want to use that for this API as well, if possible. I have found a way and will try to look into a more compatible way with using annotations maybe. At the moment I am passing the JSON as string and read the JSON as inputfile back from the response.
I think, and I think this is going to be common, I am 'abusing' OSLC4J for all my REST calls and not only OSLC. As long as there are plenty of APIS that are not OSLC compliant I have to use, it appears to be a valid approach, if I can make it work.
This mode of working also requires sometimes to sneak in custom headers. I am using an HttpRequestInterceptor to 'massage' the headers and to add custom headers where I can not pass the header directly e.g. in create calls.
Even for some of the RDF data that comes back the resolution does not work (missing type) and I have to parse the RDF model.
I am not complaining, I am glad it works for me so far. I am just learning. I will try to publish what I learn in my blog https://rsjazz.wordpress.com/ or in our articles on Jazz.net. Maybe that helps people to get started.
The answers are definitely helping. The constants are a bit confusing, because there are so many duplicates. 8)
Thanks again!
Ralph
[Updated on: Fri, 23 November 2018 13:22] by Moderator Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02911 seconds