How to post JSON with the Lyo RestClient? [message #1798637] |
Wed, 21 November 2018 08: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 #1798746 is a reply to message #1798741] |
Fri, 23 November 2018 08: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 08:22] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.05021 seconds