java.lang.NoSuchFieldError: INSTANCE in HttpClient when running Oozie

时间:2015-11-12 10:47:14

标签: java maven hadoop httpclient oozie

I have a Java app (as a Maven project) that uses HttpClient (v 4.5) in accessing a REST API, and then writes the GET response in HDFS as a JSON. This works fine when in Eclipse IDE. Here's my dependencies:

<dependencies>
  <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5</version>
  </dependency>
  <dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.3.1</version>
  </dependency>
  <dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-client</artifactId>
    <version>2.2.0</version>
</dependency>

When I try to integrate it with Oozie, because I'm planning to make the REST API call and HDFS write periodic, I encounter:

Caused by: java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:144)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:955)
at com.accenture.pdc.digital.sf.datascience.RestController.<init> RestController.java:26)
at com.accenture.pdc.digital.sf.datascience.App.main(App.java:53)

(RestController.java and App.java are my classes). When I trace, the problem lies in this line on my code:

CloseableHttpClient httpClient = HttpClients.createDefault();

and on further probing in the libraries source code, there's this deprecated:

AllowAllHostnameVerifier.INSTANCE

When I searched about this same problem, some said it could be a multiple version conflict of HttpClient or HttpCore. So the possible culprit could be the HttpClient dependency of hadoop-client (just my hunch). How can I tell if it is a multiple version conflict? If it is, how do I resolve it?

If not, are there alternative solution in opening a HttpClient to avoid this issue? Should I use library other than HttpClient?

1 个答案:

答案 0 :(得分:0)

对我有用的第一个选择是使用Jersey而不是HttpClient。由于hadoop-client已经使用jersey-core和jersey-client作为依赖,所以不妨使用现有的。此外,我将hadoop-client升级到2.6.0,因为我的Hadoop版本是2.6.0。

然后当我在pom.xml中删除了http-client时,我注意到http-client 4.2.5版突然出现了。它确认hadoop-client也将它作为依赖,正如我之前所怀疑的那样。因此,当我恢复到HttpClient解决方案,并调整一些行以适应旧版本时,它在Oozie中成功运行。