【问题标题】:How to configure the timeout on a camel cxf endpoint如何在骆驼 cxf 端点上配置超时
【发布时间】:2020-09-20 02:27:48
【问题描述】:

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

我尝试为 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

下面是代码:

公共类 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 默认值

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

非常感谢

【问题讨论】:

    标签: java http apache-camel cxf


    【解决方案1】:

    我也遇到过同样的问题,我可以通过如下设置Client.REQUEST_CONTEXT 标头来解决它:

    这可以在调用 Web 服务之前在路由中定义的处理器/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);
    }
    

    【讨论】:

    • 您好 Parasanth,感谢您的回答,我确认它有效并且我选择了它另外,第一种方法的解决方案是放置 ""cxfConfigurer=#MyCxfConfigurer" 而不是"cxfEndpointConfigurer=#MyCxfConfigurer " 作为骆驼财产
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    相关资源
    最近更新 更多