简体   繁体   中英

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.

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. Instead of the expected enhacement result I always get a HTTP 500 error response when running the analyzer.

But the same REST client logic works when executing it in a Java application main method.

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?

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.

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. The UI response failed intermittently when I adjust the field value.

This could be a problem with character encoding of the field value it seems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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