如何在Camel CXF端点上配置超时时间

huangapple go评论83阅读模式
英文:

How to configure the timeout on a camel cxf endpoint

问题

以下是翻译好的内容:

我有一个使用Apache Camel CXF组件开发的SOAP客户端。
我们调用的客户端服务响应时间过长,要求我增加调用的超时时间。

我尝试使用自定义的cxfEndpointConfigurer来配置cxf ToEndPoint,如下所示:

  1. cxf://http://localhost:6025/MyMockService?cxfEndpointConfigurer=#MyCxfConfigurer&dataFormat=MESSAGE&portName=%7Bhttp%3A%2F%2Forg.tempuri%7DMyServiceSoap11&serviceName=%7Bhttp%3A%2F%2Forg.tempuri%7DMyServiceService

以下是相关的代码:

  1. public class TemplateEndpointConfigurer implements CxfEndpointConfigurer {
  2. @Override
  3. public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
  4. // 在这里不做任何操作
  5. }
  6. @Override
  7. public void configureClient(Client client) {
  8. final HTTPConduit conduit = (HTTPConduit) client.getConduit();
  9. final HTTPClientPolicy policy = new HTTPClientPolicy();
  10. policy.setConnectionTimeout(30000);
  11. policy.setReceiveTimeout(300000);
  12. policy.setConnection(ConnectionType.CLOSE);
  13. conduit.setClient(policy);
  14. }
  15. @Override
  16. public void configureServer(Server server) {
  17. // TODO 自动生成的方法存根
  18. }
  19. }

但是,尽管如此,我仍然在60000毫秒后收到超时错误,这是cxf的默认值。

您有任何想法如何成功设置这个超时吗?

非常感谢。

英文:

I have a soap client developed using apache camel cxf component
The client's service that we are invoking takes too much time to respond and I was asked to increase the timeout of the invocation

I tried to use a custom cxfEndpointConfigurer for the cxf ToEndPoint as following : cxf://http://localhost:6025/MyMockService?cxfEndpointConfigurer=#MyCxfConfigurer&dataFormat=MESSAGE&portName=%7Bhttp%3A%2F%2Forg.tempuri%7DMyServiceSoap11&serviceName=%7Bhttp%3A%2F%2Forg.tempuri%7DMyServiceService

and here is the code bellow :

public class TemplateEndpointConfigurer implements CxfEndpointConfigurer {

  1. @Override
  2. public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
  3. // Do nothing here
  4. }
  5. @Override
  6. public void configureClient(Client client) {
  7. final HTTPConduit conduit = (HTTPConduit) client.getConduit();
  8. final HTTPClientPolicy policy = new HTTPClientPolicy();
  9. policy.setConnectionTimeout(30000);
  10. policy.setReceiveTimeout(300000);
  11. policy.setConnection(ConnectionType.CLOSE);
  12. conduit.setClient(policy);
  13. }
  14. @Override
  15. public void configureServer(Server server) {
  16. // TODO Auto-generated method stub
  17. }

}

But I still get a timeout error after 60000ms which is the cxf default

do you have any idea how I can set successfully set this timeout ?

Thank you very much

答案1

得分: 1

同样的问题也发生在我身上,我通过设置Client.REQUEST_CONTEXT头部如下所示来解决了这个问题:

这可以在调用网络服务之前在路由中定义的处理器/bean中完成:

  1. public void setWebServiceTimeout(Exchange exchange) {
  2. Map<String, Object> requestContext = new HashMap<String, Object>();
  3. HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
  4. clientPolicy.setReceiveTimeout(300000);
  5. requestContext.put(HTTPClientPolicy.class.getName(), clientPolicy);
  6. exchange.getIn().setHeader(Client.REQUEST_CONTEXT, requestContext);
  7. }
英文:

The same issue had occurred to me and i was able to fix it by setting the Client.REQUEST_CONTEXT header as below:

This can be done in a processor/bean defined in the route before calling the web service :

  1. public void setWebServiceTimeout(Exchange exchange) {
  2. Map&lt;String, Object&gt; requestContext = new HashMap&lt;String, Object&gt;();
  3. HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
  4. clientPolicy.setReceiveTimeout(300000);
  5. requestContext.put(HTTPClientPolicy.class.getName(), clientPolicy);
  6. exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
  7. }

huangapple
  • 本文由 发表于 2020年9月19日 04:21:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/63962381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定