• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Invoking Rest with Jersey Client

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Experts,

I am trying to invoke Rest service through Jersey Client, that expect custom mime type or media type "application/vnd.com.oracle.oracloud.datagrid.Service+json". I get the below error


Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl, and MIME media type, application/vnd.com.oracle.oracloud.datagrid.Service+json, was not found
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:155)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
at com.oracle.demo.OracleCloudControllerAPIs.OracleCloudAPIs.addCoherenceDataTierCluster(OracleCloudAPIs.java:112)
at com.oracle.demo.OracleCloudControllerAPIs.OracleCloudAPIs.main(OracleCloudAPIs.java:129)
Caused by: com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class com.sun.jersey.core.util.MultivaluedMapImpl, and MIME media type, application/vnd.com.oracle.oracloud.datagrid.Service+json, was not found
at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:288)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:217)
at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:153)
... 6 more



The code which I have is below. The below code works for the rest services which expects JSON or XML as mime type.


I am trying to programatically invoke this REST API

I have never come across custom mime type. The code works for all other mime types. Is there any other configuration which one has to make?
 
Author
Posts: 297
12
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really have to send that mime type? It seems like an excuse for "applicatin/json". Have you tried sending it as such?

If you cannot, then I think what you'll need to do is to create a class that implements MessageBodyReader and MessageBodyWriter, dive into the infrastructure and find the Provider class that's already installed that handles application/json, and proxy to that, converting the type blah-blah-oracle-blah/json into application/json and back accordingly, so that the "real" handler doesn't get it's knickers in a twist.

This:

https://jersey.java.net/documentation/latest/message-body-workers.html#d0e6814

gives an overview of the MessageBodyReader/Writer process; it's not hard really, thought.

HTH
Simon
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried with application/json, but it replied with error "Not Supported Content Type", i am not even able to invoke this from other rest clients like Chrome rest client, I don't see any option of setthign this mime type.

Can someone explain me, why one would have used custom mime type?

Thanks
 
Simon Roberts
Author
Posts: 297
12
Scala IntelliJ IDE Netbeans IDE Python Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, there might be more to it that just JSON, but that would seem odd. Perhaps it's certain pre-agreed elements in the JSON. Does seem a little odd though.
 
Marshal
Posts: 4542
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
application/vnd.com.oracle.oracloud.datagrid.Service+json specifies the json-formatted schema for the representations exchanged between the server and clients. In your code you are performing a GET, so the it should probably be specified in an Accept header, rather than a Content-Type header.

There are some curl examples here.
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In your code you are performing a GET, so the it should probably be specified in an Accept header, rather than a Content-Type header.


Agreed, you can check Jersey client examples here.
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to perform post.



I still get "Content Not Supported Error". I am able to invoke this from Chrome Client (Attached Screen Shot)

I set the body as Raw & sent the json request.

 
Ron McLeod
Marshal
Posts: 4542
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My comment regarding Accept was for the code that you had originally posted, which was doing a GET operation. The example that you have now is doing a POST operation. For POST you do need Content-Type set to application/vnd.com.oracle.oracloud.datagrid.Service+json.

Are you trying to do a GET or POST?
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nikhil Jain, I have removed your screen shot from your post. Not only is it a poor way to show text information (please post text as text, and UseCodeTags to preserve formatting), but also it revealed your login credentials to anyone who could see the post. I'm sure that that was not your intention.
 
Nikhil Jain
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apologies for attaching screen shot. Just wanted to convey the configuration on my rest client. Thanks for removing it.

I am trying to do POST operation.
 
Saloon Keeper
Posts: 27889
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jersey works with plug-in converters that accept the request inputstream and convert it to javabean parameters. There are a number of options available. I've used MoXy, myself.

https://jersey.java.net/documentation/latest/media.html

application/json won't work (be accepted) without one of the JSON converters being wired in.
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic