简体   繁体   English

在Solr Analyzer中调用Apache Stanbol REST端点时出现HTTP 500错误

[英]HTTP 500 error when invoking Apache Stanbol REST endpoint in Solr Analyzer

I am writing a Solr custom analyzer to post a value of a field to Apache Stanbol for enhancement during indexing phase. 我正在编写一个Solr定制分析器,以将字段的值发布到Apache Stanbol以便在索引阶段进行增强。

In my custom analyzer's incrementToken() method I have below code. 在我的自定义分析器的增量令牌()方法中,我有以下代码。 I'm posting the value of the token to Stanbol enhancer endpoint using a Jersey REST client. 我正在使用Jersey REST客户端将令牌的值发布到Stanbol Enhancer端点。 Instead of the expected enhacement result I always get a HTTP 500 error response when running the analyzer. 在运行分析器时,总是得到HTTP 500错误响应,而不是预期的增强结果。

But the same REST client logic works when executing it in a Java application main method. 但是,在Java应用程序main方法中执行时,相同的REST客户端逻辑也可以工作。

Can someone please help me identify where the problem is? 有人可以帮我确定问题出在哪里吗? Could it be a Java permission problem, invoking a web endpoint within the Solr analyzer? 在Solr分析器中调用Web端点可能是Java权限问题吗?

public boolean incrementToken() throws IOException {
    if (!input.incrementToken()) {
          return false;
        }
        char[] buffer = charTermAttr.buffer();
        String content = new String(buffer);

        Client client = Client.create();
        WebResource webResource = client.resource("http://localhost:8080/enhancer");
        ClientResponse response = webResource.type("text/plain").accept(new MediaType("application", "rdf+xml")).post(ClientResponse.class, content);


        int status = response.getStatus();
        if (status != 200 && status != 201 && status != 202) {
            throw new RuntimeException("Failed : HTTP error code : "
                 + response.getStatus());
        }

        String output = response.getEntity(String.class);
        System.out.println(output);
        charTermAttr.setEmpty();
        char[] newBuffer = output.toCharArray();
        charTermAttr.copyBuffer(newBuffer, 0, newBuffer.length);
        return true;
}

This seems to be a weird intermittent issue when I use the Solr Analysis UI (http://localhost:8983/solr/#/collection1/analysis) for testing my Analyzer. 当我使用Solr Analysis UI (http://localhost:8983/solr/#/collection1/analysis)测试我的Analyzer时,这似乎是一个奇怪的间歇性问题。

It works fine when I hard code the input value in the Analyzer and index. 当我在分析器和索引中对输入值进行硬编码时,它可以正常工作。 I gave the same input : "Tim Bernes Lee is a professor at MIT" hard coded in the Analyzer class and from the Solr Analysis UI. 我提供了相同的输入:“ Analyst”类和Solr Analysis UI中对“ Tim Bernes Lee是MIT的教授”进行了硬编码。 The UI response failed intermittently when I adjust the field value. 调整字段值时,UI响应间歇性失败。

This could be a problem with character encoding of the field value it seems. 这似乎与字段值的字符编码有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM