• 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

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ->
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$App
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$App
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$App
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$App
*/* ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.json.impl.provider.entity.JSONJAXBElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONArrayProvider$General
com.sun.jersey.json.impl.provider.entity.JSONObjectProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader
com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General
com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General
com.sun.jersey.json.impl.provider.entity.JacksonProviderProxy


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
 
Saloon Keeper
Posts: 27763
196
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
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.
 
Kevin Reynolds
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
AM","active":"T","user":{"userId":1,"userType":1,"name":"AdminK","active":"T"},"locationGroup":{"locationGroupId":1,"alertId":1,"locationType":300,"entityType":100,"entityKey":1,"active":"T","geoCodeGroupDTO":{"geoCodeGroupId":1,"name":"Test
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Turns out I did make a silly oversight. And then I spent 17 hours hunting the non-existing configuration problem...

The problem method:
@POST
@Path("newalert")
@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:
@POST
@Path("newalert")
@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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic