本文介绍了Elasticsearch Rest Client抛出java.lang.ArrayStoreException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Elasticsearch Rest Client v5.5.3在Java应用程序中执行Elasticsearch查询.它总是抛出java.lang.ArrayStoreException.首先,我怀疑查询执行的频率,因为应用程序密集地执行查询,但是它在第一个查询时就引发异常.其次,我更新了一些依赖项,例如Elasticsearch rest客户端使用的Apache HttpCore.jar.但是我无法弄清楚如何解决它的任何一种方式仍然会引发异常.堆栈跟踪在下面;

I am using Elasticsearch Rest Client v5.5.3 to execute Elasticsearch queries in a Java application. It always throws java.lang.ArrayStoreException. First I suspect frequency of query execution since application intensively executes queries but it throws exception very first query. Second I update some dependencies like Apache HttpCore.jar which Elasticsearch rest client uses. But either way I could not figure out how to solve it still throws exception. Stack trace is below;

java.lang.ArrayStoreException: org.apache.http.impl.cookie.RFC2965VersionAttributeHandler
    at org.apache.http.impl.cookie.DefaultCookieSpecProvider.create(DefaultCookieSpecProvider.java:92) ~[httpclient-4.5.2.jar:4.5.2]
    at org.apache.http.client.protocol.RequestAddCookies.process(RequestAddCookies.java:152) ~[flux-core-1.1.0.jar:1.1.0]
    at org.apache.http.protocol.ImmutableHttpProcessor.process(ImmutableHttpProcessor.java:132) ~[flux-core-1.1.0.jar:1.1.0]
    at org.apache.http.impl.nio.client.MainClientExec.prepareRequest(MainClientExec.java:520) ~[httpasyncclient-4.1.2.jar:4.1.2]
    at org.apache.http.impl.nio.client.MainClientExec.prepare(MainClientExec.java:146) ~[httpasyncclient-4.1.2.jar:4.1.2]
    at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:124) ~[httpasyncclient-4.1.2.jar:4.1.2]
    at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141) ~[httpasyncclient-4.1.2.jar:4.1.2]
    at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:343) ~[rest-5.5.3.jar:5.5.3]
    at org.elasticsearch.client.RestClient.performRequestAsync(RestClient.java:325) ~[rest-5.5.3.jar:5.5.3]
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:218) ~[rest-5.5.3.jar:5.5.3]
    at org.elasticsearch.client.RestClient.performRequest(RestClient.java:191) ~[rest-5.5.3.jar:5.5.3]
    at com.nova.stats.platform.are.batch.rule.ElasticsearchQueryExecutor.execute(ElasticsearchQueryExecutor.java:36) [classes/:?]

该方法执行查询;

public String execute(String query, QueryParameters parameters) throws IOException {
        String index = (String) parameters.getParameter(GlobalConfigurations.ElasticsearchConfigurations.ConfigurationFields.INDEX);
        String type = (String) parameters.getParameter(GlobalConfigurations.ElasticsearchConfigurations.ConfigurationFields.TYPE);

        RestClient restClient = ElasticsearchRestClient.getClient();
        HttpEntity entity;
        Response response = null;
        try {
            entity = new NStringEntity(query);
            response = restClient.performRequest("GET", "/" + index + "/" + type + "/_search",
                    Collections.singletonMap("pretty", "true"), entity);
        } catch (Exception e) {
            logger.error("Could not perform request, query: " + query, e);
        }

        String responseStr = responseStr = EntityUtils.toString(response.getEntity());


        return responseStr;
    }

推荐答案

问题描述

问题根源是由于 httpclient-4.5.2 flux-core-1.1.0 冲突引起的"JAR Hell".我不知道为什么,但是 flux-core-1.1.0 jar包含在完整的httpclient代码库版本4.3.3中,该版本与4.5.2.不兼容.

The problem root cause is "JAR Hell" due to conflicts httpclient-4.5.2 and flux-core-1.1.0. I don't know why but flux-core-1.1.0 jar contains inside full httpclient codebase version 4.3.3 which is not compatible with 4.5.2.

什么是 ArrayStoreException ,Javadoc引用:

What is ArrayStoreException, Javadoc quote:

在版本httpclient-4.3.3中 RFC2965VersionAttributeHandler 看起来像

In version httpclient-4.3.3 RFC2965VersionAttributeHandler looks like

@Immutable
public class RFC2965VersionAttributeHandler implements CookieAttributeHandler {

在版本httpclient-4.5.2中, RFC2965VersionAttributeHandler 看起来像

In version httpclient-4.5.2 RFC2965VersionAttributeHandler looks like

@Immutable
public class RFC2965VersionAttributeHandler implements CommonCookieAttributeHandler {

以及 DefaultCookieSpec 中的问题,该问题尝试使用4.3.3中的 RFC2965VersionAttributeHandler 调用版本4.5.2的 RFC2965Spec 的构造函数,其中没有实现 CommonCookieAttributeHandler :

And the problem in DefaultCookieSpec which tries to invoke constructor of RFC2965Spec of version 4.5.2 with RFC2965VersionAttributeHandler from 4.3.3, which in not implements CommonCookieAttributeHandler:

RFC2965Spec(final boolean oneHeader,
            final CommonCookieAttributeHandler... handlers) {
    super(oneHeader, handlers);
}

解决方案

"JAR地狱"的最可能原因-您的 pom.xml (或gradle)具有对 httpclient-4.5.2 的依赖性.您应该将其从依赖项中删除或降级为 4.3.3 版本.另外,您的 pom.xml 可能具有 httpasyncclient-4.1.2 的依赖关系-在这种情况下,您也可以将其从依赖关系中删除或降级为 4.0.x 版本.值得一提的是,您的项目可能对 httpclient httpasyncclient 具有传递依赖-在这种情况下,您需要查找并修复它.

The most probably reason of "JAR Hell" - your pom.xml (or gradle) has dependency for httpclient-4.5.2. You should remove it from dependencies or downgrade to 4.3.3 version. Also your pom.xml may have dependency for httpasyncclient-4.1.2 - in this case you also could remove it from dependencies or downgrade to 4.0.x version. At worth your project could have transitive dependency for httpclient or httpasyncclient - in such case you need to find and fix it.

这篇关于Elasticsearch Rest Client抛出java.lang.ArrayStoreException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:44