![](/img/trans.png)
[英]Using Restlet ClientResource cannot send entity to Restlet Service
[英]Using the Restlet ClientResource correctly
我在Restlet(v 2.0.5)中的ClientResource遇到了問題,這可能是由於不了解其正確用法所致。
我正在使用ClientResource和Apache HTTP Client連接器,並編寫了以下內容:
private final ClientResource httpClient;
public SendClient(String uri) {
httpClient = new ClientResource(uri);
}
// Omitted code would create messages to send, and then use an executor
// to send this particular message to its destination.
public void run() {
ClientResource sendClient = null;
try {
sendClient = wsClient.getChild(uriResource); // re-use original httpclient instance, uriResource is passed in to the method that calls this.
sendClient.post(form);
} catch (Throwable e) {
logger.error("Unable to send message, {}", e.getMessage());
} finally {
if (sendClient != null) {
sendClient.release(); // As I understand from [Restlet WIKI][1]
}
}
}
這個對嗎? 我懷疑不是這樣,因為幾個小時后(7個或更多個),此部分代碼開始引發以下錯誤“內部服務器錯誤”,並且目的地不再接收消息。
關於我做錯了什么的任何想法?
注意:我知道ClientResource不是線程安全的,並且您會注意到,在我的代碼中,我使用執行程序來運行此部分代碼,但是,該執行程序僅包含一個線程,因此,直到我理解其他情況為止,我已經排除了這個問題。
注2:ClientResource Javadoc指出:“並發注釋:該類的實例並非旨在在多個線程之間共享。如果需要線程安全,請考慮使用較低級別的Client類。” 但是,restlet創建者說,實際上它是線程安全的,只是沒有明確為此目的而設計。 謝謝。
ClientResource是線程安全的,但是即使有可能,它也不是專門為由多個並發線程使用而設計的。 但是,多次重用同一實例是完全有效的。
回到您的問題,我們將需要對您的問題進行更詳細的堆棧跟蹤以尋求幫助,因為“內部服務器錯誤”會導致服務器端而不是客戶端端出現問題。
希望這會有所幫助,傑羅姆
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.