【问题标题】:Axis2 ServiceClient options ignore timeoutAxis2 ServiceClient 选项忽略超时
【发布时间】:2012-11-11 10:35:06
【问题描述】:

我正在使用 Axis2 版本:

Implementation-Version: 1.7.0-SNAPSHOT
Implementation-Vendor-Id: org.apache.axis2
Implementation-Vendor: The Apache Software Foundation
Jenkins-Build-Number: 1847

我想设置ServiceClient的超时时间为2000毫秒,这是我们的代码:

Options options = new Options();
options.setTo(new EndpointReference(getUserServiceEndPoint()));
options.setProperty(Constants.Configuration.ENABLE_REST,
        Constants.VALUE_TRUE);
// setting timeout to 2 second should be sufficient, if the server is
// not available within the 3 second interval you got a problem anyway
options.setTimeOutInMilliSeconds(2000);

ServiceClient sender = new ServiceClient();
sender.engageModule(new QName(Constants.MODULE_ADDRESSING)
        .getLocalPart());
sender.setOptions(options);
OMElement getSessionResult = sender
        .sendReceive(getPayloadMethodGetSession());

但我仍然在日志中看到:

org.apache.axis2.AxisFault:主机不接受连接 在 60000 毫秒的超时内

而且确实也需要 60 秒。所以错误信息不仅仅是错误的,似乎只是忽略了超时选项,它总是使用默认选项。

有人遇到过类似的问题吗?

谢谢
塞巴斯蒂安

【问题讨论】:

    标签: java rest soap timeout axis2


    【解决方案1】:

    根据 Axis2 1.6.3 的 API 文档,它是两个属性或 timeOutInMillis 之类的:

    Options options = new Options();
    options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));
    

    options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
    

    来源: http://axis.apache.org/axis2/java/core/docs/http-transport.html

    【讨论】:

    • 我不确定 java 类是否被实现为 c 代码的包装器,但在 options.c 中,setTimeoutInMilliseconds 仅修改连接超时:axis2_options_set_property(options, env, AXIS2_HTTP_CONNECTION_TIMEOUT, property) ;
    • 在使用方面,setTimeoutInMilliseconds 与 SO_TIMEOUT 仅在使用 curl 后端时有所不同。
    【解决方案2】:

    我能够解决这个问题(尽管它在我看来有点重复)

    int timeOutInMilliSeconds = 2000;
    options.setTimeOutInMilliSeconds(timeOutInMilliSeconds);
    options.setProperty(HTTPConstants.SO_TIMEOUT, timeOutInMilliSeconds);
    options.setProperty(HTTPConstants.CONNECTION_TIMEOUT, timeOutInMilliSeconds);
    

    塞巴斯蒂安

    【讨论】:

    • 看起来是重复的,但是这两个超时有一个重要的区别。 SO_TIMEOUT 是尝试建立与服务器的连接时的超时。 CONNECTION_TIMEOUT 是套接字发送请求后等待接收响应的时间。
    • 但是 options.setTimeOutInMilliSeconds(timeOutInMilliSeconds) 是什么?适合吗?好像一点效果都没有。
    • 我希望我能告诉你。 Options 类上的 javadoc 没有提供太多信息。我本来想用一种方法设置这两个值。我的 google-fu 似乎也没有轻易得到答案。
    • @NickRoth 我相信您混淆了 SO_TIMEOUT 和 CONNECTION_TIMEOUT 的定义。你说的反面是对的。
    • options.setTimeOutInMilliSeconds 和 options.setProperty HTTPConstants.CONNECTION_TIMEOUT 没有影响 ..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    相关资源
    最近更新 更多