PDA

View Full Version : Small issue with http 204



toolshed51
Feb 18th, 2011, 04:44 PM
I'm using Spring Android M2 and its saved me a lot of development time and has been great. The only issue I ran into so far was this.

Given that I'm running my Android app against my WCF 4 server,
And given that the response is a 204 No Content
WCF does not set the Content length or content type headers.
Spring Android expects the Content-Type header to be set and throws a RestClientException

I worked around this by doing a
try {
//RestTemplate.exchange(blah, blah, blah);
}
catch (RestClientException restClientException) {
if (restClientException.getMessage().contains("no Content-Type found")) {
return null;
}
throw restClientException;
}

Forgive me if I overlooked it, but it would also be awesome if the exception contained more information about the request that caused the exception.

Thanks - Russ

tusharj
Apr 11th, 2011, 04:45 PM
Hi Russ,
I'm also facing similar issue . do post back if you found any solution

toolshed51
May 16th, 2011, 01:17 PM
Index: C:/Users/rchadwick/workspace/spring-android-rest-template-1.0.0.M3/org/springframework/web/client/HttpMessageConverterExtractor.java
================================================== =================
--- C:/Users/rchadwick/workspace/spring-android-rest-template-1.0.0.M3/org/springframework/web/client/HttpMessageConverterExtractor.java (revision 2204)
+++ C:/Users/rchadwick/workspace/spring-android-rest-template-1.0.0.M3/org/springframework/web/client/HttpMessageConverterExtractor.java (working copy)
@@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.client.ClientHttpResponse ;
import org.springframework.http.converter.HttpMessageConv erter;
@@ -63,6 +64,10 @@
public T extractData(ClientHttpResponse response) throws IOException {
MediaType contentType = response.getHeaders().getContentType();
if (contentType == null) {
+ HttpStatus status = response.getStatusCode();
+ if (status == HttpStatus.NO_CONTENT || status == HttpStatus.NOT_MODIFIED) {
+ return null;
+ }
throw new RestClientException("Cannot extract response: no Content-Type found");
}
for (HttpMessageConverter messageConverter : messageConverters) {

Roy Clarkson
May 18th, 2011, 07:49 AM
There is currently an open issue in Spring Framework for this. When it is resolved, we'll pull the change into Spring Android. I've added a comment referencing this forum thread.

https://jira.springsource.org/browse/SPR-7911