我在
Android中使用RoboSpice for Rest Api调用,我想在调用中添加30秒的连接超时我将如何操作?
这是我的代码
public class AddBrandsService extends SpringAndroidSpiceRequest<AddBrands.Response> { public final AddBrands.Response loadDataFromNetwork(){ return getRestTemplate().postForObject(url,request,AddBrands.Response.class); } } this service is called here private SpiceManager contentManager = new SpiceManager( JacksonspringAndroidSpiceService.class); contentManager.execute(service,lastRequestCacheKey,DurationInMillis.ONE_SECOND,new AddBrandsListner());
提前致谢…
解决方法
这是代码.基本上,你必须在两个不同的实现之间处理android的版本作为spring android切换,以避免网络堆栈中的已知错误.不幸的是,两种实现都不共享与超时相关的公共接口.
private void manageTimeOuts(RestTemplate restTemplate) { // set timeout for requests ClientHttpRequestFactory factory = restTemplate.getRequestFactory(); if (factory instanceof HttpComponentsClientHttpRequestFactory) { HttpComponentsClientHttpRequestFactory advancedFactory = (HttpComponentsClientHttpRequestFactory) factory; advancedFactory.setConnectTimeout(WEBSERVICES_TIMEOUT); advancedFactory.setReadTimeout(WEBSERVICES_TIMEOUT); } else if (factory instanceof SimpleClientHttpRequestFactory) { SimpleClientHttpRequestFactory advancedFactory = (SimpleClientHttpRequestFactory) factory; advancedFactory.setConnectTimeout(WEBSERVICES_TIMEOUT); advancedFactory.setReadTimeout(WEBSERVICES_TIMEOUT); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。