The moose likes Tomcat and the fly likes Tomcat 7 throwing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat 7 throwing "A message body reader for... is not found"" Watch "Tomcat 7 throwing "A message body reader for... is not found"" New topic

Tomcat 7 throwing "A message body reader for... is not found"

Kevin Reynolds

Joined: Mar 07, 2010
Posts: 8
Hi All,

I have sadly been stuck for 10 hours with a problem... I am sure the solution will eventually be the equivalent to telling me I need to put the key into the ignition and turn it in order to start the motor...

At wits end, I must suck it up and expose myself :-)

I have Tomcat 7 and installed Jersey 1.11.

I am calling my webservice from an Android app using the apache HttpPost class. I am trying to use either text/plain or application/json to pass the information to the server... I do not have that code with me right now or i would post it - but I have tried about 20 different iterations of that code from snippets found on the net. I really think the problem isn't there but is rather on my web app...

When I execute the HttpPost, I get a 415 error and the Tomcat server throws the following:
Jan 17, 2012 12:01:34 AM com.sun.jersey.spi.container.ContainerRequest getEntity
SEVERE: A message body reader for Java class java.lang.Object, and
Java type class java.lang.Object, and MIME media type
application/json was not found.
The registered message body readers compatible with the MIME media type are:
application/json ->
*/* ->

I have somehow, somewhere, failed to tell the server how to receive this type of message. Can someone please push me in the right direction?

Thank you VERY much
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17421

JSON is a protocol (technicall, a notation format) for converting binary object to text format so that they may be sent and received over a text-only channel (HTTP or HTTPS).

Tomcat doesn't know anything about JSON. It's just more text. So yes, your problem is in the webapp that should be doing the JSON encoding/decoding.

Unfortunately, I don't think I can tell you anything further without more stack trace information and possibly a snapshot of the offending JSON text.

An IDE is no substitute for an Intelligent Developer.
Kevin Reynolds

Joined: Mar 07, 2010
Posts: 8
Thank you for the quick reply.

The json string is:
{"alertList":[ {"id":1,"categoryGroupId":1,"title":"This is Test
One","description":"Test One Description","userId":1,"startDate":"Dec
30, 2011 12:00:00
GeoCodeGroup 1","active":"T","geoCodeDTOList":[{"geoCodeId":1,"geoCodeGroupId":1,"latitude":-83.00005,"longitude":39.900005,"active":"T"}]}}}
] }

From GET transactions I am able to produce this message on the server side and receive it into the client and "parse" it into the appropriate classes using Gson. However, I believe I am just @producing plain text from that GET - please excuse me for the uncertainty, at this time I do not have access to the code.

From POST transactions I am even getting a very similar error stack from the Tomcat server when I am sending the json string as plain text. Only difference is the list of registered message body readers compatible with the MIME media type.

From the server message above, is it essentially saying, the Server has these tools that can be used to interpret the message
"The registered message body readers compatible with the MIME media type are:
application/json ->

But, my particular Web App has not been told which to use?

I am definitely fine with sending the POST as a plain text and then parsing that using Gson, in fact, "out of the box" is my preference. I'd much prefer not having to write my own ContextResolver and MessageBodyReader. And I already know that Gson can be used to process the plain text into my class files.

Is it a matter of just including the jars containing those listed message body readers in the web app lib? Or is it a reference in the web application's web.xml? Or both?

Thank you for the assistance. I am starting to become sleep deprived :-)
Kevin Reynolds

Joined: Mar 07, 2010
Posts: 8
Turns out I did make a silly oversight. And then I spent 17 hours hunting the non-existing configuration problem...

The problem method:
@Produces({MediaType.TEXT_PLAIN, "application/x-www-form-urlencoded"})
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, "application/x-www-form-urlencoded"})
public String addAlert(Object obj){

The fixed method:
@Produces({MediaType.TEXT_PLAIN, "application/x-www-form-urlencoded"})
@Consumes({MediaType.TEXT_PLAIN, MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_HTML, "application/x-www-form-urlencoded"})
public String addAlert(String obj){

java.lang.Object is not serialized but java.lang.String is....

MIME should have never been a problem to begin with. And let that be a lesson, finding and copying code is a great thing, but you got to pay attention to minor details sometimes or you will waste a lot of time.
I agree. Here's the link:
subject: Tomcat 7 throwing "A message body reader for... is not found"
It's not a secret anymore!