solrj を使用して Solr にクエリを送信すると、SolrException がスローされることがあります。例外を掘り下げると、「Bad Request」と表示され、HTTP リターン コード (400) が返されます。
リクエスト URL を取得してブラウザに入力すると、より充実したエラー メッセージが表示されました。フィールド名の 1 つが無効であることを示すエラー メッセージがブラウザに表示されます。
これをログ ファイル内にキャプチャできるようにしたいと考えています。すべてのパラメーターを Apache HTTP クライアントの POST 要求にコピーして (GET では URL が長すぎるため、GET ではなく POST を使用しています)、要求を再実行することでこれをキャプチャできましたが、これは非効率的です。エラーメッセージを 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
}
}