有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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

我尝试为cxf ToEndPoint使用自定义cxfEndpointConfigurer,如下所示:cxf://http://localhost:6025/MyMockService?cxfEndpointConfigurer=#MyCxfConfigurer&dataFormat=消息&;端口名=%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

}

}

但是在60000ms之后,我仍然会收到一个超时错误,这是cxf的默认设置

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

多谢各位


共 (1) 个答案

  1. # 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);
    }