0
當我使用solrj向Solr發送查詢時,有時會遇到SolrException。當我挖掘異常時,它只是說「錯誤的請求」,並給出了HTTP返回碼(400)。如何從solrj中獲取更多錯誤消息SolrException
當我將請求URL放到瀏覽器中時,我看到了一條更豐富的錯誤消息。瀏覽器會顯示一條錯誤消息,指出其中一個字段名稱無效。
我想能夠在我的日誌文件中捕獲這個。我能夠通過將所有參數複製到Apache HTTP Client POST請求(我使用POST而不是GET,因爲GET使URL太長)並重新執行請求來捕獲此問題,但效率不高。有沒有辦法直接從SolrException中獲取錯誤信息?
下面是我在做什麼:
catch (SolrServerException e) {
if(e.getRootCause() instanceof SolrException) {
SolrException ee = (SolrException) e.getRootCause();
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(SOLR_URL);
// copy params over
Iterator<String> iter = request.getParams().getParameterNamesIterator();
while(iter.hasNext()) {
String p = iter.next();
method.setParameter(p, request.getParams().get(p));
}
int statusCode;
try {
// re execute and display the error message
statusCode = client.executeMethod(method);
logger.error(method.getResponseBodyAsString());
} catch (Exception e1) {
// TODO Auto-generated catch block
}
}
從技術上講,SolrJ可能尚未實現它,但它*是*可能的,我已經在SolrNet中捕獲了整個錯誤信息。 –
它可能是javabin編碼的限制。 –