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

  • Using GZIP - problem

    Hello!
    I just started my journey with the Spring for Android and I've encountered a problem with the usage of the GZIP i have the following code in my app:
    Code:
            HttpHeaders requestHeaders = new HttpHeaders();
            requestHeaders.setAcceptEncoding(ContentCodingType.ALL);
            HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
            
            RestTemplate restTemplate = new RestTemplate();
    
            restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());
    
           ResponseEntity<OfertaList> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, OfertaList.class);
    and i receive the following error:
    Code:
    java.lang.RuntimeException: Unable to start activity ComponentInfo{...Activity}: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [pl.magres.mobile.classes.OfertaList] and content type [application/x-gzip]
    when I use just:
    OfertaList result = restTemplate.getForObject(url, OfertaList.class, "");
    and the webservice without GZIP compression everything works

    what am i doing wrong?

  • #2
    Generally speaking, that error means that RestTemplate does not know how to handle the response from the server. In other words, it cannot find a message converter that understands the combination of response type and content type. In this case, the Content-Type is the culprit. RestTemplate does not currently support converting a Content-Type of application/x-gzip. If you look in the MediaType class, you can see we don't even have that mime type defined.

    The way the gzip support works is that RestTemplate looks at the Content-Encoding header for a value of gzip. If found it will attempt to decompress the response, then using the Content-Type, determine which message converter to use to correctly marshal the response.

    Because your server is responding with a Content-Type of application/x-gzip, instead of setting the Content-Encoding header, you will simply need to not set the Accept-Encoding header like you have already determined. We will evaluate how to better handle this scenario in a future release of Spring for Android.

    thanks for the feedback!

    Comment


    • #3
      I don't know did I got right what u meant, but I removed the setAcceptEncoding and so I have the following:

      Code:
      		HttpHeaders requestHeaders = new HttpHeaders();
      		// requestHeaders.setAcceptEncoding(ContentCodingType.GZIP);
      		HttpEntity<?> requestEntity = new HttpEntity<Object>(requestHeaders);
      
      		RestTemplate restTemplate = new RestTemplate();
      		restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());
      
      		ResponseEntity<OfertaList> response = restTemplate.exchange(url,HttpMethod.GET, requestEntity, OfertaList.class);
      and unfortunately that doesn't do the trick, still got:
      Code:
      java.lang.RuntimeException: Unable to start activity ComponentInfo{LoginActivity}: org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [OfertaList] and content type [application/x-gzip]
      Is there anything else that i can try? - I develop the server side with WCF and when i download the gzip response it unzips correctly uzing WinZip - so i guess the server side compression works ok

      Thanks for help

      Comment


      • #4
        If you are running this code on Android 2.3 (Gingerbread) or newer, then Android automatically sets the gzip accept header. You can disable this by setting the following in your requestHeaders. The server should then return a non-gzip'd response.

        Code:
        requestHeaders.setAcceptEncoding(ContentCodingType.IDENTITY);

        Comment

        Working...
        X