dutchman_mn
Jun 1st, 2011, 12:49 PM
I am attempting to use the SimpleXmlHttpMessageConverter to render an XML response to a Java object like this:
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
RestTemplate restTemplate = new RestTemplate(requestFactory);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
SimpleXmlHttpMessageConverter xmlMessageConverter = new SimpleXmlHttpMessageConverter();
ArrayList supportedMediaTypes = new ArrayList();
MediaType mediaType = new MediaType("text", "xml", Charset.forName("ISO-8859-1"));
supportedMediaTypes.add(mediaType);
xmlMessageConverter.setSupportedMediaTypes(support edMediaTypes);
messageConverters.add(xmlMessageConverter);
restTemplate.setMessageConverters(messageConverter s);
HttpHeaders headers = new HttpHeaders();
ResponseEntity responseEntity =
restTemplate.exchange(restURL,
HttpMethod.GET,
new HttpEntity<String>(headers),
Class.forName(com.acme.Feed));
The reason I am altering the supported media type was the first time I tried it, I got an error message stating it did not support text/xml. SimpleXmlHttpMessageConverter has a default character set of UTF-8, but my response is text/xml;charset=ISO-8859-1 so I thought that was maybe the problem.
The error message is: org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [com.acme.Feed] and content type [text/xml;charset=ISO-8859-1]
The response xml looks like this:
<feed>
<feedname>Alerts</feedname>
<authData>
<token>...</token>
<username>...</username>
<employeeId>...</employeeId>
</authData>
<dataMessages>
<dataMessage>
...
</dataMessage>
</dataMessages>
</feed>
I am at a bit of a loss to understand how to resolve this issue.
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
RestTemplate restTemplate = new RestTemplate(requestFactory);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
messageConverters.add(new FormHttpMessageConverter());
messageConverters.add(new StringHttpMessageConverter());
SimpleXmlHttpMessageConverter xmlMessageConverter = new SimpleXmlHttpMessageConverter();
ArrayList supportedMediaTypes = new ArrayList();
MediaType mediaType = new MediaType("text", "xml", Charset.forName("ISO-8859-1"));
supportedMediaTypes.add(mediaType);
xmlMessageConverter.setSupportedMediaTypes(support edMediaTypes);
messageConverters.add(xmlMessageConverter);
restTemplate.setMessageConverters(messageConverter s);
HttpHeaders headers = new HttpHeaders();
ResponseEntity responseEntity =
restTemplate.exchange(restURL,
HttpMethod.GET,
new HttpEntity<String>(headers),
Class.forName(com.acme.Feed));
The reason I am altering the supported media type was the first time I tried it, I got an error message stating it did not support text/xml. SimpleXmlHttpMessageConverter has a default character set of UTF-8, but my response is text/xml;charset=ISO-8859-1 so I thought that was maybe the problem.
The error message is: org.springframework.web.client.RestClientException : Could not extract response: no suitable HttpMessageConverter found for response type [com.acme.Feed] and content type [text/xml;charset=ISO-8859-1]
The response xml looks like this:
<feed>
<feedname>Alerts</feedname>
<authData>
<token>...</token>
<username>...</username>
<employeeId>...</employeeId>
</authData>
<dataMessages>
<dataMessage>
...
</dataMessage>
</dataMessages>
</feed>
I am at a bit of a loss to understand how to resolve this issue.