SimpleClientHttpRequestFactory only works intermittently on SpringAndroid

I am using SpringAndroid M4.

I have the following code snippet:

RestTemplate restTemplate = new RestTemplate(); restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory()); HttpEntity<?> requestEntity = new HttpEntity<Object>(myHeader()); final String url = "my_url"; ResponseEntity<String> responseEntity = restTemplate.exchange(url,HttpMethod.GET, requestEntity, String.class); 

Believe it or not, it works alternately (first time yes, then no, then yes, then no, etc.)

This is the error stack trace (the error occurs with the restTemplate.exchange method) when it does not work:

 08-18 17:55:09.919: ERROR/(7722): java.lang.IllegalArgumentException: No matching constant for [-1] 08-18 17:55:09.919: ERROR/(7722): at org.springframework.http.HttpStatus.valueOf(HttpStatus.java:380) 08-18 17:55:09.919: ERROR/(7722): at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(SimpleClientHttpResponse.java:48) 08-18 17:55:09.919: ERROR/(7722): at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:45) 08-18 17:55:09.919: ERROR/(7722): at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:463) 08-18 17:55:09.919: ERROR/(7722): at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:425) 08-18 17:55:09.919: ERROR/(7722): at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:401) 
+4
source share
2 answers

Does this only happen when testing on an emulator? I have exactly the same problem, but this only happens when I use the emulator. Everything works fine on a real device.

0
source

This seems to be a bug in SimpleClientHttpResponse . In my case, this did not seem to have any consequences, although the HTTP return code might be incorrect.

Replacing it with HttpComponentsClientHttpRequestFactory , the problem seems to be gone.

0
source

All Articles