joh*_*hnm 2 java cxf apache-camel
我们在春季应用程序中使用Camel 2.14,并利用Camel CXF-RS组件(http://camel.apache.org/cxfrs.html)在第三方服务上生成RESTful请求。
当他们的服务器离线并且Camel无法建立连接时,它不会在30秒内超时。我们希望能够调整此超时值,但正在努力查看如何做到这一点。有人可以建议吗?
我们可以看到Camel本身使用从HTTPClientPolicy对象获取的值,该对象上具有setConnectionTimeOut ..但是如何获取此对象?
我们可以通过编程方式获取HTTPClientPolicy对象吗?还是必须在传递给template.send()的Camel URI中引用它,例如:
template.send("cxfrs://" + url + "/match/" + appId + "/" + reqId?httpClientAPI=true&http.connection.timeout=5000
小智 5
raphaë之前发布的链接?如果要使用XML文件配置端点超时,则正确。但是,如果要完全以编程方式进行操作,则可以使用cxf组件的选项之一(cxfEndpointConfigurer)进行操作,如此camel-cxf组件unit-test所示。
在您的情况下,将是这样的:
template.send("cxfrs://" + url + "/match/" + appId + "/" + "reqId?httpClientAPI=true&cxfEndpointConfigurer=#endpointConfigurer"
Run Code Online (Sandbox Code Playgroud)
然后,您将需要一个具有以下配置的“ endpointConfigurer” Bean:
@Component("endpointConfigurer")
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(webServiceConnectionTimeout);
policy.setReceiveTimeout(webServiceReadTimeout);
policy.setConnection(ConnectionType.CLOSE);
conduit.setClient(policy);
}
@Override
public void configureServer(Server server) {
// Do nothing here
}
}
Run Code Online (Sandbox Code Playgroud)
即使这个答案来得有点晚,我希望它能对您的项目有所帮助。
| 归档时间: |
|
| 查看次数: |
1520 次 |
| 最近记录: |