英文:
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<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);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论