Note that there are some explanatory texts on larger screens.

plurals
  1. POPUT method Spring MVC
    primarykey
    data
    text
    <p>I'm trying to use the following format for making a put request through the RESTtemplate.</p> <pre><code> @Autowired RestTemplate template; @RequestMapping(value = "/change", method = RequestMethod.PUT) public ModelAndView change(Data data){ List&lt;MediaType&gt; acceptableMediaTypes = new ArrayList&lt;MediaType&gt;(); acceptableMediaTypes.add(MediaType.APPLICATION_XML); HttpHeaders headers = new HttpHeaders(); headers.setAccept(acceptableMediaTypes); HttpEntity&lt;Data&gt; entity = new HttpEntity&lt;Data&gt;(data, headers); String url="http://www...com"; try { template.put(url, entity); } catch (Exception e) { System.out.println(e); } return new ModelAndView("redirect:/home"); } </code></pre> <p>I checked on the database and I realized that there is no change. Even the request is not written on the log file. When I'm debugging, I am not getting any error. Probably I'm not using correctly the put method. Can anyone suggest me how should I use the put method or what else should I try to perform a put request with the RestTemplate?</p> <p>Also i try to use the exchange method instead of the put:</p> <pre><code> try { ResponseEntity&lt;Data&gt; result = template.exchange(Url, HttpMethod.PUT, entity, Data.class); } catch (Exception e) { System.out.println(e); } </code></pre> <p>But in this case i'm taking the following exception:</p> <p>org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [website.Data] and content type [text/html;charset=utf-8].</p> <p>As you can see from the headers i set the content type as application/xml and not text/html. I look at the headers and i can see that contained:</p> <pre><code>Accept: application/xml </code></pre> <p>I really can't understand. What else should i change? Any comments on the exception?</p> <p>Configuration:</p> <pre><code>&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" p:basename="config/views" p:order="1" /&gt; &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt; &lt;bean class="org.springframework.web.servlet.view.XmlViewResolver"&gt; &lt;property name="location"&gt; &lt;value&gt;/WEB-INF/classes/config/xml-views.xml&lt;/value&gt; &lt;/property&gt; &lt;property name="order" value="0" /&gt; &lt;/bean&gt; &lt;!--It is used for redirect--&gt; &lt;bean id="urlBasedViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/&gt; &lt;property name="prefix" value=""/&gt; &lt;property name="suffix" value=""/&gt; &lt;property name="order" value="2" /&gt; &lt;/bean&gt; &lt;context:annotation-config /&gt; &lt;!--&lt;context:annotation-config /&gt;--&gt; &lt;context:component-scan base-package="data.controller" /&gt; &lt;context:component-scan base-package="data.service" /&gt; &lt;bean id="restTemplate" class="org.springframework.web.client.RestTemplate"&gt; &lt;property name="messageConverters"&gt; &lt;list&gt; &lt;bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload