如何在 camel cxf 端点上配置超时

How to configure the timeout on a camel cxf endpoint

我有一个使用 apache camel cxf 组件开发的 soap 客户端 我们正在调用的客户端服务响应时间过长,我被要求增加调用的超时时间

我尝试为 cxf ToEndPoint 使用自定义 cxfEndpointConfigurer,如下所示:cxf://http://localhost:6025/MyMockService?cxfEndpointConfigurer=#MyCxfConfigurer&dataFormat=MESSAGE&portName=%7Bhttp%3A%2F%2Forg.tempuri%7DMyServiceSoap11&serviceName=%7Bhttp%3A%2F%2Forg.tempuri%7DMyServiceService

下面是代码:

public class TemplateEndpointConfigurer 实现 CxfEndpointConfigurer {

@Override
public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
    // Do nothing here
}

@Override
public void configureClient(Client client) {

    final HTTPConduit conduit = (HTTPConduit) client.getConduit();

    final HTTPClientPolicy policy = new HTTPClientPolicy();
    policy.setConnectionTimeout(30000);
    policy.setReceiveTimeout(300000);
    policy.setConnection(ConnectionType.CLOSE);
    conduit.setClient(policy);

}

@Override
public void configureServer(Server server) {
    // TODO Auto-generated method stub

}

}

但在 60000 毫秒后我仍然收到超时错误,这是 cxf 默认值

你知道我怎样才能成功设置这个超时吗?

非常感谢

我也遇到了同样的问题,我可以通过如下设置 Client.REQUEST_CONTEXT header 来修复它:

这可以在调用 Web 服务之前在路由中定义的 processor/bean 中完成:

    public void setWebServiceTimeout(Exchange exchange) {
      Map<String, Object> requestContext = new HashMap<String, Object>();
      HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
      clientPolicy.setReceiveTimeout(300000);
      requestContext.put(HTTPClientPolicy.class.getName(), clientPolicy);
      exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
}