Maharsh
Maharsh

Reputation: 92

Spring restTemplate.postForEntity(or postForObject) gives error "no suitable HttpMessageConverter" in Stand alone Java application

I have stand alone Java Application with Spring 3.0. I am calling REST service "post" method call with 4 integer parameters. While calling restTemplate.postForEntity(), I am getting error "no suitable HttpMessageConverter found for request type". Is it require to set any messageConverter in restTemplate ? i don't find any sample on net.

Upvotes: 4

Views: 17627

Answers (2)

mayya
mayya

Reputation: 101

Most likely that REST service you called would have failed and postForObject() returned null. You need to check for errors using ResponseErrorHandler implementations.

Upvotes: 1

Grzegorz Rożniecki
Grzegorz Rożniecki

Reputation: 27995

Funny, I just answered similar question...

Nevertheless you may want check great Spring Reference Manual, particularly this fragment, documentation, IBM Dev blog post and RestTemplate example on SpringSource Blog (written when ).

From SpringSource Blog post:

HttpMessageConverters

Objects passed to and returned from the methods getForObject(), postForLocation(), and put() and are converted to HTTP requests and from HTTP responses by HttpMessageConverters. Converters for the main mime types and Java types are registered by default, but you can also write your own converter and plug it in the RestTemplate.

Also, IBM blog post here mentions common HttpMessageConverter implementations, you probably will use Marshalling (response in XML) or MappingJackson (for JSON) one.

Upvotes: 4

Related Questions