PROBLEM
Logstash java custom filter The following error occurs when using the 'elasticsearch java api client 7.16'.
- java.lang.BootstrapMethodError: bootstrap method initialization exception
- Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type interface org.apache.http.Header; not a subtype of implementation type interface org.apache.http.NameValuePair
The way I tried:
- httpclient, httpcore jar Individual build
- jdk 11 version build (default 8)
- IP communication test between docker containers.
ā I have to use ELK 7.16.3 or higher version because of log4j vulnerability. ā
Help me, please..
LOG
nc-common-logstash | [DEBUG][org.elasticsearch.client.RestClient] request [HEAD http://elasticsearch:9200/] returned [HTTP/1.1 200 OK]
nc-common-logstash | java.lang.BootstrapMethodError: bootstrap method initialization exception
nc-common-logstash | at java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194) ~[?:?]
nc-common-logstash | at java.lang.invoke.CallSite.makeSite(CallSite.java:307) ~[?:?]
nc-common-logstash | at java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258) ~[?:?]
nc-common-logstash | at java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248) ~[?:?]
nc-common-logstash | at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:317) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | at org.elasticsearch.client.RestClient.performRequest(RestClient.java:301) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | at org.elasticsearch.client.RestClient.performRequest(RestClient.java:276) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:143) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | at co.elastic.clients.elasticsearch.ElasticsearchClient.ping(ElasticsearchClient.java:1188) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | at org.logstashplugins.TmsConfigLoader.loadTmsConfig(TmsConfigLoader.java:76) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | at org.logstashplugins.TmsConfigLoader.run(TmsConfigLoader.java:235) ~[logstash-filter-nc_netflow-1.0.0.jar:?]
nc-common-logstash | Caused by: java.lang.invoke.LambdaConversionException: Invalid receiver type interface org.apache.http.Header; not a subtype of implementation type interface org.apache.http.NameValuePair
nc-common-logstash | at java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:254) ~[?:?]
nc-common-logstash | at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:328) ~[?:?]
nc-common-logstash | at java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:127) ~[?:?]
nc-common-logstash | ... 10 more
CODE
import org.apache.http.HttpHost;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.client.RestClient;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch._types.ElasticsearchException;
import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
import co.elastic.clients.elasticsearch._types.query_dsl.TermQuery;
import co.elastic.clients.elasticsearch.core.SearchRequest;
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.search.Hit;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.endpoints.BooleanResponse;
import co.elastic.clients.transport.rest_client.RestClientTransport;
public class configLoader extends Thread {
...
...
...
public void loadConfig() {
RestClient restClient = null;
ElasticsearchTransport transport = null;
ElasticsearchClient client = null;
SearchRequest searchRequest = null;
SearchResponse<Object> searchResponse = null;
try {
if (this.esUrl != null) {
// host: elasticsearch, port: 9200, protocol: http
restClient = RestClient.builder(new HttpHost(esUrl.getHost(), esUrl.getPort(), esUrl.getProtocol())).build();
transport = new RestClientTransport(restClient, new JacksonJsonpMapper());
client = new ElasticsearchClient(transport);
BooleanResponse pingRes = client.ping();
if (pingRes.value()) {
if (this.logger != null) {
logger.info("ConfigLoader - Elasticsearch Connection Success");
}
// get config List
searchRequest = null;
searchResponse = null;
tmsConfigService.getList().clear();
searchRequest = createSearchRequest(this.indexPatternService, 0, 10000, "deleted", false);
searchResponse = client.search(searchRequest, Object.class);
for (Hit<Object> hit: searchResponse.hits().hits()) {
String _id = hit.id();
Object source = hit.source();
if(source != null){
Map<String, Object> item = (Map)source;
item.put("_id", _id);
Service service = new Service(item);
tmsConfigService.getList().add(service);
}
}
} else {
if (this.logger != null) {
logger.error("ConfigLoader - (ping fail)");
}
}
} else {
if (this.logger != null) {
logger.error("ConfigLoader - (empty url)");
}
}
} catch (java.io.IOException exception) {
if (this.logger != null) {
logger.error("ConfigLoader - IOException (error)");
logger.error(exception);
exception.printStackTrace();
}
} catch (ElasticsearchException exception) {
if (this.logger != null) {
logger.error("ConfigLoader - ElasticsearchException (search error)");
logger.error(exception);
}
} catch (Exception exception) {
if (this.logger != null) {
logger.error("ConfigLoader - Exception (error)");
logger.error(exception);
}
} finally {
if (client != null) {
try {
client.shutdown();
transport.close();
restClient.close();
} catch (Exception exception) {
if (logger != null) {
logger.error("ConfigLoader - IOException (close error)");
logger.error(exception);
}
}
}
}
}
@Override
public void run() {
super.run();
this.loadConfig();
while (this.isInterrupted() != true) {
this.loadConfig();
try {
sleep(60 * 30 * 1000);
} catch (InterruptedException exception) {
if (this.logger != null) {
logger.error("ConfigLoader - InterruptedException");
logger.error(exception);
}
break;
}
}
}
}
GRADLE DEPENDENCIES
dependencies {
implementation 'co.elastic.clients:elasticsearch-java:7.16.3'
// implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.16.3'
implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.16.3'
implementation 'org.elasticsearch.client:elasticsearch-rest-client-sniffer:7.16.3'
// implementation 'org.elasticsearch:elasticsearch:7.16.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'org.apache.httpcomponents:httpclient:4.5.10'
implementation 'org.apache.httpcomponents:httpcore:4.4.12'
implementation 'org.apache.logging.log4j:log4j-api:2.17.1'
implementation 'org.apache.logging.log4j:log4j-core:2.17.1'
implementation fileTree(dir: LOGSTASH_CORE_PATH, include: "build/libs/logstash-core-7.16.3.jar")
// implementation fileTree(dir: LOGSTASH_CUSTOM_LIBS_PATH, include: "build/libs/httpclient-4.5.10.jar")
// implementation fileTree(dir: LOGSTASH_CUSTOM_LIBS_PATH, include: "build/libs/httpcore-4.4.12.jar")
implementation 'org.jruby:jruby-complete:9.2.7.0'
testImplementation 'junit:junit:4.12'
//testImplementation 'org.jruby:jruby-complete:9.2.7.0'
}
ENVIRENMENT
centos 7.7
logstash 7.16.3
elasticsearch 7.16.3
jdk 1.8.0_251
docker-compose