fmisso
(Fabrice)
May 14, 2019, 1:39am
1
Hello,
I'm trying your Java REST client API in Android Studio.
But i have this error
Caused by: java.lang.NoSuchFieldError: No field INSTANCE of type Lorg/apache/http/message/BasicLineFormatter; in class Lorg/apache/http/message/BasicLineFormatter;
Impossible to find a solution...
I try to exclude httpclient module in my gradle file,
implementation ('org.elasticsearch.client:elasticsearch-rest-client:7.0.1'){
exclude module: 'httpclient'
exclude module: 'httpcore-nio'
exclude module: 'httpcore'
}
But nothing, it doesn't work.
Could you help me, please !
Thanks
1 Like
emskypl
(Mateusz Nogaj)
May 21, 2019, 7:14pm
2
I have the same problem. I was thinking about Java API but elastic say it's deprecated. Can someone help? Can we use other http client?
fmisso
(Fabrice)
May 21, 2019, 9:44pm
3
I did not find a solution despite hours of research. Too bad the support is not more active. I took the solution with an AsyncHttpClient object
public class DAOElastic extends JsonHttpResponseHandler{
private String URL;
private AsyncHttpClient client ;
private boolean error;
public DAOElastic(){
this.URL = "http://192.168.1.154:9200/";
this.client = new AsyncHttpClient();
this.error = false;
}
public void get(String url, RequestParams params) {
this.client.get((this.URL+url), params, this);
}
public void post(String url, RequestParams params) {
this.client.post((this.URL+url), params, this);
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
// If the response is JSONObject instead of expected JSONArray
this.error = false;
this.deserialiseMedicaments(response);
}
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
//Log.i(CLASS_NAME, "onSuccess: " + response.toString());
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
this.error = true;
}
@Override
public void onRetry(int retryNo) {
Log.i("Test", "onRetry " + retryNo);
// called when request is retried
}
@Override
public ArrayList<Object> getObjects() {
this.get("myobj/_search", null);
if (this.error == false){
return null;
}
else{
return null;
}
}
}
Not the better solution, but it's work.
system
(system)
Closed
June 18, 2019, 9:54pm
4
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.