Announcement Announcement Module
Collapse
No announcement yet.
Small issue with http 204 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Small issue with http 204

    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

  • #2
    Hi Russ,
    I'm also facing similar issue . do post back if you found any solution

    Comment


    • #3
      Fixed this for our purposes with the following patch

      Code:
      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.HttpMessageConverter;
      @@ -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) {

      Comment


      • #4
        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

        Comment

        Working...
        X