如何编写用于重试Java Webservice的java客户端代码 [英] How to write java client code for retry call to Java webservice
本文介绍了如何编写用于重试Java Webservice的java客户端代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须为其他一方发布的web服务编写Java客户端代码。
在该客户端代码中,如果发生任何超时,我必须提供重试指定次数的选项。
I have to write a Java client code for a webservice published by some other party. In that client code I have to give option for retry for specified number of times if any timeout occurs.
在webservice调用中,我已经传递了非持久对象,所以在重试过程中我认为应该保存这些
对象。
In webservice call I have passed non persisten objects, so in retry process I think these objects should be saved.
代码示例非常有用。
推荐答案
AOP和Java注释是正确的方法。我建议使用 jcabi-aspects (我是开发人员)的读取机制:
AOP and Java annotations is the right way to do it. I would recommend a read-made mechanism from jcabi-aspects (I'm a developer):
import com.jcabi.aspects.RetryOnFailure;
@RetryOnFailure(attempts = 4)
public String load(URL url) {
// sensitive operation that may throw an exception
return url.openConnection().getContent();
}
这篇关于如何编写用于重试Java Webservice的java客户端代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文