Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Sending and Retrieving JSON data from Jersey API

Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to send JSON object to and from a restful webservice implemented through a Jersey API
Here is my code for the service

Here is my code for the client

But this shows the following 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 java.lang.Class, and MIME media type, application/octet-stream, was not found

Can anybody help?Is there any tutorial that explains how to do this?
Ranch Hand
Posts: 491
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While looking for my issue Providers and MessageBodyWriter, I came across this article.
Hope it help if you read it.
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the Server Side Code

public Response createTrackInJSONFormString(String trackName) {
String result = "Track saved : " + trackName;
System.out.println("trackname from the User is : "+ trackName+" and result"+result);
Gson gson = new Gson();
Person person = new Person();
person.setAddress("123 Main Street");
String jsonString = gson.toJson(person);
System.out.println("This is the messagePost from Jersey Service SERVICE_NAME is 333333 /post/withresponse/onlystring");
return Response.status(201).entity(jsonString).build();


Here is the Sample JSP Client
<form id="postFormThree" action="./rest/shade/post/withresponse/onlystring"
<input type="text" name="trackName" value="onlyStringStrackNameONLY">
<input type="submit" name="submitPost" value="submitPost-FORM-postFormThree" />

Both were working when I tested them on Jersey-bundle-1.16
keep an eye out for scorpions and black widows. But the tiny ads are safe.
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic