我试图为Camel CXF组件这里设置“RESTful”,它在第三方服务上生成RESTful请求。默认的30000毫秒是长的。
Exchange exchange = template.send("cxfrs://" + url, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.setPattern(ExchangePattern.InOut);
Message inMessage = exchange.getIn();
setupDestinationURL(inMessage);
// using the http central client API
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, Boolean.TRUE);
// set the Http method
inMessage.setHeader(Exchange.HTTP_METHOD, "PUT");
// set the relative path
inMessage.setHeader(Exchange.HTTP_PATH, url);
// Specify the response class , cxfrs will use InputStream as the response object type
inMessage.setHeader(CxfConstants.CAMEL_CXF_RS_RESPONSE_CLASS, Customer.class);
// set a customer header
inMessage.setHeader("key", "value");
// since we use the Get method, so we don't need to set the message body
inMessage.setBody(null);
}
});正如许多人建议的那样,我尝试将它添加到我们的application-context中,但在通过HTTPConduit和HTTPClientPolicy类进行调试时看不到它修改默认值:
<http-conf:conduit name="*.http-conduit">
<http-conf:client ConnectionTimeout="5000"/>
</http-conf:conduit>我已经试过了
"?httpClientAPI=true&connectionTimeout=5000" 作为url字符串的选项。
如有任何帮助或指导,将不胜感激。
发布于 2016-03-21 21:54:17
像您所做的那样,在http-conf:conduit中添加application-context元素是可行的,并且应该能够工作。你凭什么说它没有?
通常,在建立连接之后,后端服务器需要很长时间才能回答;在这种情况下,设置ReceiveTimeout和ConnectionTimeout一样重要。
这是一个示例camel路由,它使用RS请求并调用第三方RS服务器;ReceiveTimeout和ConnectionTimeout参数按预期工作。
<cxf:rsServer id="rsFrontServer" address="..." serviceClass="..."/>
<cxf:rsClient id="rsBackendClient" address=".../" serviceClass="..."/>
<http-conf:conduit name="*.http-conduit">
<http-conf:client ReceiveTimeout="5000" ConnectionTimeout="5000"/>
</http-conf:conduit>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="front">
<from uri="cxfrs:bean:rsFrontServer"/>
<!-- do stuff -->
<to uri="cxfrs:bean:rsBackendClient"/>
</route>
</camelContext>https://stackoverflow.com/questions/36133777
复制相似问题