Announcement Announcement Module
Collapse
No announcement yet.
RestClientException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • RestClientException

    Hallo everyone, i'm taking a RestClientException and more precisely says: Could not extract response: no suitable HttpMessageConverter found for response type [frontend.model.Registration] and content type [application/xml].This happens
    when i'm trying to retieve through the rest template an xml

    The registration class is the following:

    @XmlRootElement(name="quser")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class Registration {

    private String username;
    //private String password;
    @XmlElement(name="first_name")
    private String firstname;
    @XmlElement(name="last_name")
    private String lastname;
    private String degree;
    private String institution;
    @XmlElement(name="authenticated_professional")
    private String authenticatedprofessional;
    private EsteemMeta esteem;
    private ArrayList<Researchareas> research_areas;
    private Role roles;
    private String fields;
    .
    .
    get/set methods


    I use the aforementioned class in order to retrieve an xml and as you can
    notice i use the JAXB annotations.The class i try to make this retrieve is the following:

    @RequestMapping(value = "/user",method = RequestMethod.GET)
    public String getUser(@RequestParam("id") int id, Model model) {

    List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
    acceptableMediaTypes.add(MediaType.APPLICATION_XML );


    HttpHeaders headers = new HttpHeaders();
    headers.setAccept(acceptableMediaTypes);
    HttpEntity<String> entity = new HttpEntity<String>(headers);


    try {
    ResponseEntity<Registration> result = restTemplate.exchange("http://www.../ckp/user/{id}",
    HttpMethod.GET, entity, Registration.class, id);



    } catch (Exception e) {
    System.out.println(e);

    }


    return "profile";
    }

    Here at the try i'm taking the exception.This was working perfectly fine in a sample
    code i saw. The problem probably is here:



    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schem...-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schem...ontext-3.0.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schem...ng-mvc-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schem...ng-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schem...ing-tx-3.0.xsd
    http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd">

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Resour ceBundleViewResolver"
    p:basename="config/views" p:order="1" />

    <bean class="org.springframework.web.servlet.mvc.support .ControllerClassNameHandlerMapping"/>

    <bean class="org.springframework.web.servlet.view.XmlVie wResolver">
    <property name="location">
    <value>/WEB-INF/classes/config/xml-views.xml</value>
    </property>
    <property name="order" value="0" />
    </bean>
    <!--It is used for redirect-->
    <bean id="urlBasedViewResolver"
    class="org.springframework.web.servlet.view.UrlBas edViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlVi ew"/>
    <property name="prefix" value=""/>
    <property name="suffix" value=""/>
    <property name="order" value="2" />
    </bean>

    <context:annotation-config />
    <!--<context:annotation-config />-->
    <context:component-scan base-package="frontend.controller" />
    <context:component-scan base-package="frontend.service" />


    <!-- Enables the Spring MVC @Controller programming model -->
    <mvc:annotation-driven />

    <!-- resources exclusions from servlet mapping -->
    <mvc:resources mapping="/style/**" location="/style/" />
    <mvc:resources mapping="/js/**" location="/js/" />
    <mvc:resources mapping="/pdf/**" location="/pdf/" />


    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2 .TilesConfigurer" p:definitions="/WEB-INF/tiles/tiles-definition.xml" />

    <bean id="themeSource" class="org.springframework.ui.context.support.Reso urceBundleThemeSource">
    <property name="basenamePrefix" value="config/themes/theme-" />
    </bean>

    <bean id="themeResolver" class="org.springframework.web.servlet.theme.Cooki eThemeResolver">
    <property name="defaultThemeName" value="default"/>
    <property name="cookieName" value="clienttheme"/>
    <property name="cookieMaxAge" value="-1"/>
    </bean>

    <!-- Application Message Bundle -->

    <bean id="messageSource"
    class="org.springframework.context.support.Reloada bleResourceBundleMessageSource">
    <property name="basenames">
    <list>
    <value>classpath:config/messages/messages</value>
    <value>classpath:config/messages/constants</value>
    <value>classpath:config/messages/errors</value>
    </list>
    </property>
    <property name="defaultEncoding" value="UTF-8" />
    <property name="fileEncodings" value="UTF-8" />
    </bean>


    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.Cookie LocaleResolver">
    <property name="defaultLocale" value="en" />
    <property name="cookieName" value="clientlanguage"/>
    <!-- in seconds. If set to -1, the cookie is not persisted (deleted when browser shuts down) -->
    <property name="cookieMaxAge" value="-1"/>
    </bean>


    <!-- Declare the Interceptor -->
    <mvc:interceptors>
    <!-- Locale Change Interceptor and Resolver definition -->
    <bean id="localeChangeInterceptor"
    class="org.springframework.web.servlet.i18n.Locale ChangeInterceptor">
    <property name="paramName" value="lang" />
    </bean>
    <!-- Theme Change Interceptor and Resolver definition -->
    <bean id="themeChangeInterceptor"
    class="org.springframework.web.servlet.theme.Theme ChangeInterceptor">
    <property name="paramName" value="theme" />
    </bean>
    </mvc:interceptors>


    <bean id="restTemplate" class="org.springframework.web.client.RestTemplate ">
    <property name="messageConverters">
    <list>
    <bean class="org.springframework.http.converter.xml.Sour ceHttpMessageConverter"/>
    </list>
    </property>
    </bean>


    <bean class="org.springframework.web.servlet.view.Conten tNegotiatingViewResolver">
    <property name="mediaTypes">
    <map>
    <entry key="xml" value="application/xml"/>
    <entry key="html" value="text/html"/>
    </map>
    </property>
    <property name="viewResolvers">
    <list>
    <bean class="org.springframework.web.servlet.view.BeanNa meViewResolver"/>
    </list>
    </property>
    </bean>

    </beans>


    The majority of the aformentioned code is not mine and i can't understand it.
    Please i need your help.What should i change?
    Last edited by alexios.7; May 9th, 2012, 11:51 PM.
Working...
X