2016-02-26 35 views
2

我們在Spring應用程序中使用Camel 2.14,並利用Camel CXF-RS組件(http://camel.apache.org/cxfrs.html)在第三方服務上產生RESTful請求。如何設置Camel RESTful客戶端超時和HTTPClientPolicy

當他們的服務器是離線和駱駝不能得到一個連接,它不會持續30秒超時。我們希望能夠調整此超時值,但都在努力看看我們如何能做到這一點。任何人都可以建議嗎?

我們可以看到駱駝本身使用從HTTPClientPolicy對象獲得的值,該對象上有一個setConnectionTimeOut ..但是我們如何獲取這個對象?

我們就可以在HTTPClientPolicy對象編程?或者,我們必須將它傳遞到駱駝的URI template.send(),例如:如果你想配置端點與XML文件超時

template.send("cxfrs://" + url + "/match/" + appId + "/" + reqId?httpClientAPI=true&http.connection.timeout=5000

+0

[駱駝cxfrs RESTful客戶端/ ProducerTemplate ConnectionTimeout]的可能的複製(http://stackoverflow.com/questions/36133777/camel-cxfrs-restful-client-producertemplate-connectiontimeout) –

+0

推測HTTP的副本://計算器.COM /問題/ 27617168 /如何到組,receivetimeout和連接超時換cxfendpoint – inanutshellus

回答

1

通過raphaëλ之前發佈的鏈接是正確的。 但是,如果您想完全以編程方式完成此操作,則可以使用cxf組件的選項之一(cxfEndpointConfigurer)執行此操作,如this camel-cxf component unit-test中所示。

在你的情況下,它會是這樣的:

template.send("cxfrs://" + url + "/match/" + appId + "/" + "reqId?httpClientAPI=true&cxfEndpointConfigurer=#endpointConfigurer" 

那麼你就需要一個「endpointConfigurer」豆有這樣的配置:

@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 
    } 
} 

即使這個答案來得有點晚了,我希望它可以幫助您與您的項目。