0

当我使用 solrj 向 Solr 发送查询时,有时会抛出 SolrException。当我挖掘异常时,它只显示“错误请求”,并给出 HTTP 返回码(即 400)。

当我获取请求 URL 并将其放入浏览器时,我能够看到更丰富的错误消息。浏览器显示一条错误消息,指出其中一个字段名称无效。

我希望能够在我的日志文件中捕获它。我能够通过将所有参数复制到 Apache HTTP 客户端 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
                }
            }
4

1 回答 1

1

These messages aren't available via SolrJ. You can see them in solr's log file, but there is no way to capture them in your client, since solr only returns the 400 error status with a generic message to the client :(

于 2011-09-26T01:18:28.850 回答