aspose file tools*
The moose likes Spring and the fly likes HttpMessageConverter for @RequestBody and @ResponseBody Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "HttpMessageConverter for @RequestBody and @ResponseBody" Watch "HttpMessageConverter for @RequestBody and @ResponseBody" New topic
Author

HttpMessageConverter for @RequestBody and @ResponseBody

H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
While troubling shooting/debug the error:

I came across these 3 below classes:

Why on the client side, RestTemplate has all HttpMessageConverter registered with 3 jaxb, json and rome optional
and
Why on the server side, RequestMappingHandlerAdapter or AnnotationMethodHandlerAdapter do not have all or rather defined as RestTemplate?


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

You should be using the RequestMappingHandlerAdapter now so I will only comment on that one. There are no advantages to using the older AnnotationHandlerMethodAdapter.

If you use the @EnableWebMvc in an @Configuration class or if you use the <annotation-driven/> tag in the MVC namespace (if you are using XML for configuration) then Jaxb2RootElementHttpMessageConverter, MappingJackson2HttpMessageConverter, MappingJacksonHttpMessageConverter, AtomFeedHttpMessageConverter, and RssChannelHttpMessageConverter will be registered automatically if the correct classes are present on the classpath. Alternatively you can extend WebMvcConfigurationSupport and override this behaviour among others in any way you see fit. This is true at least in spring 3.1.3-RELEASE and I assume other variations of 3.1.x as well (and 3.0.x as well if I recall)


In Spring 3.2 it was added as well to the default constructor of RequestMappingHandler adapter (where you were previously looking) in the form of an AllEncompassingFormHttpMessageConverter. Either way though assuming you are using the annotation or XML tag to initialize things they are getting registered. If you are manually wiring up your RequestMappingHandlerAdapter (totally unnecessary in most cases) then depending what your configuration looks like you may need to set explicity all the type converters you want registered.


This is the default constructor in 3.2.0 (note the absence of this in 3.1.x does not mean they were not getting registered. It happens in the bean definition parser or WebMvcConfigurationSupport depending on whether you are using XML or annotations to bootstrap your MVC stuff)


HTH


[How To Ask Questions][Read before you PM me]
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

As far as your 415 error see this post as well.
http://www.coderanch.com/t/605202/Spring/Spring-mvc-request-mapping-POST#2762495?OWASP_CSRFTOKEN=BS5C-EY5M-7CET-M3C6-V2DY-NG9P-7E24-4JD9
H Paul
Ranch Hand

Joined: Jul 26, 2011
Posts: 471
    
    4
Thanks Bill. See reply in your above mentioned thread.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HttpMessageConverter for @RequestBody and @ResponseBody