Hi to all,
I am developing an example for accessing Twitter. All goes well when I do the oAuth "dance". At the end when I try to invoke the available methods on the TwitterTemplate I get:
I am getting this when I do both:Exception in thread "main" org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [java.util.Map] and content type [application/json;charset=utf-8]
at org.springframework.web.client.HttpMessageConverte rExtractor.extractData(HttpMessageConverterExtract or.java:77)
at org.springframework.web.client.RestTemplate$Respon seEntityResponseExtractor.extractData(RestTemplate .java:619)
at org.springframework.web.client.RestTemplate$Respon seEntityResponseExtractor.extractData(RestTemplate .java:1)
at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:446)
at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:401)
at org.springframework.web.client.RestTemplate.postFo rEntity(RestTemplate.java:302)
at org.springframework.social.twitter.TwitterTemplate .updateStatus(TwitterTemplate.java:134)
at xx.xxxxxxx.SpringSocialApp.TwitterApp.main(Twitter App.java:121)
andCode:String profileId = twitterTemplate.getProfileId();
I found this post where one of the users mentions doing a try-catch block and ignoring the exception. This would go well for the updateStatus method (since I can see that the status gets updated). But creates a problem when you need to get something from the twitter server.Code:twitterTemplate.updateStatus("yupiiiiii!");
Any solution? None of you get this exception?!
If you need more details I would be glad to provide them.
Thanks,
Despot
SOME UPDATE:
It appears that the following converters are used:
[org.springframework.http.converter.ByteArrayHttpMe ssageConverter@9bc984, org.springframework.http.converter.StringHttpMessa geConverter@1cb2795, org.springframework.http.converter.ResourceHttpMes sageConverter@93bca2, org.springframework.http.converter.xml.SourceHttpM essageConverter@1455d1c, org.springframework.http.converter.xml.XmlAwareFor mHttpMessageConverter@e3ffdf, org.springframework.http.converter.xml.Jaxb2RootEl ementHttpMessageConverter@b3a5a0]
I found a piece of code in the source when the RestTemplate is created:
A wild guess: since the exception is all about not being able to resolve application/json content type, and on the other hand I cannot see the Jackson converter in the available converters, does this mean I am missing a library? Is spring-social-core.jar enough or should I include some other libraries in the project?Code:private static final boolean jaxb2Present = ClassUtils.isPresent("javax.xml.bind.Binder", RestTemplate.class.getClassLoader()); private static final boolean jacksonPresent = ClassUtils.isPresent("org.codehaus.jackson.map.ObjectMapper", RestTemplate.class.getClassLoader()) && ClassUtils.isPresent("org.codehaus.jackson.JsonGenerator", RestTemplate.class.getClassLoader()); private static boolean romePresent = ClassUtils.isPresent("com.sun.syndication.feed.WireFeed", RestTemplate.class.getClassLoader()); public RestTemplate() { this.messageConverters.add(new ByteArrayHttpMessageConverter()); this.messageConverters.add(new StringHttpMessageConverter()); this.messageConverters.add(new ResourceHttpMessageConverter()); this.messageConverters.add(new SourceHttpMessageConverter()); this.messageConverters.add(new XmlAwareFormHttpMessageConverter()); if (jaxb2Present) { this.messageConverters.add(new Jaxb2RootElementHttpMessageConverter()); } if (jacksonPresent) { this.messageConverters.add(new MappingJacksonHttpMessageConverter()); } if (romePresent) { this.messageConverters.add(new AtomFeedHttpMessageConverter()); this.messageConverters.add(new RssChannelHttpMessageConverter()); } }


Reply With Quote
