开发者

SimpleClientHttpRequestFactory only works alternately on SpringAndroid

I am using SpringAndroid M4.

I have the following fragment of code:

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, and so on..)

This is the stack trace of the error (error is thrown on restTemplate.exchange method) when it doesn't 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)


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


This appears to be a bug in SimpleClientHttpResponse. In my case it didn't seem to have any implications, although possibly the HTTP return code is incorrect.

By replacing it with HttpComponentsClientHttpRequestFactory, the problem appears to have disappeared.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜