1

I am writing a spring mvc app(Spring newbie) which has to call a rest service. I have the rest service deployed in my VM(weblogic 10.3.6 in Linux) and the app I am writing is in my local laptop weblogic(10.3.6 in Windows 8.1).

When I try calling the rest service the request goes fine to the restservice app, but the response fails with the following message

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.myclass.Acct] and content type [application/json;charset=UTF-8]
        at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:110)
        at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:572)

I am initializing the rest client in my controller & calling a method as below

Class1 ccc = new Class1();
Client client = new Client("REST URL","key","key1","USR",ccc);
client.getService("String"));

In the actual client, the call to rest service looks like this

Acct acct1 = restClient.getRestTemplate().getForObject("URL", Acct.class, "USR");

The error I get is here in the above line. I am not sure how to set the response type. When I change the Acct.class to String.class and Acct acct1 to Object acct1, then it works.

Do I need to set anything in my dispatcher-servlet.xml for the response type json? Let me know if any other configurations are needed to make this work. I did look at other posts related to this, but it did not help. Thanks.

user115391
  • 185
  • 1
  • 8
  • 22
  • 1
    please check this question http://stackoverflow.com/questions/24723394/could-not-extract-response-no-suitable-httpmessageconverter-found-for-response – Safwan Hijazi Jun 04 '15 at 22:56
  • Thanks for the response, I saw that question before I posted this. I am not initializing the beans in my xml. Is there any other way that I can get the same configuration without using xmls. Thanks. – user115391 Jun 05 '15 at 12:27
  • please insert the rest service in the code, so we can see the response type, also please insert Client class – Safwan Hijazi Jun 05 '15 at 15:50

1 Answers1

4

Thanks for the help. I have solved the issue and it is working now.

I made the following updates:

in my pom.xml

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.5.3</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.5.3</version>
</dependency>

in my dispatcher servlet

<!-- Configure to plugin JSON as request and response in method handler -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="jsonMessageConverter"/>
            </list>
        </property>
    </bean>

    <!-- Configure bean to convert JSON to POJO and vice versa -->
    <bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
    </bean> 

in my code(Acct class)

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
...........
..........
 @JsonIgnore
 @JsonProperty(value = "........")
 public Set getMethod()
 {
     return this.............;
 }

Now, I am able to get the results from the rest services.

Thanks.

user115391
  • 185
  • 1
  • 8
  • 22