Getting Unirest Config exception when I use java with Unirest API to call the web service asynchronous way. It is working as expected in the sync method.
I am writing a Java code for Apache Spark to call REST API.
Future> future = ui.post("http://x.x.x.x:x/xwa/evalrules").body(Str).asStringAsync( new Callback() {
public void failed(UnirestException e) {
System.out.println("JTX Failed Get message"+ e.getMessage());
}
public void completed(HttpResponse<String> resp) {
System.out.println(new Date() + " Consumer JTXX recvd response -> " + resp.getStatus() + "/" + resp.getBody());
//out_JSON=resp.body();
}
public void cancelled() {
System.out.println("The request has been cancelled JTX");
}
});
Expected: It is working as expected for first few calls. post that it is failing. I suspected the timeout so i have already disabled using approach.
Config c = Unirest.config().socketTimeout(0).connectTimeout(0).concurrency(10, 8); UnirestInstance ui = new UnirestInstance(c);
Error Message:
kong.unirest.UnirestConfigException: Http Clients are already built in order to build a new config execute Unirest.config().reset() before changing settings. This should be done rarely.
Any suggestions on how to resolve this will be highly appreciated. Thanks. Muthu