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;
}