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

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

How to configure the timeout on a camel cxf endpoint

问题

以下是翻译好的内容:

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

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

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 implements CxfEndpointConfigurer {

	@Override
	public void configure(AbstractWSDLBasedEndpointFactory factoryBean) {
		// 在这里不做任何操作
	}

	@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 自动生成的方法存根

	}
}

但是,尽管如此,我仍然在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 {

@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

}

}

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中完成:

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);
}
英文:

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 :

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

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:

确定