oikonomiyaki
oikonomiyaki

Reputation: 7951

java.lang.NoSuchFieldError: INSTANCE in HttpClient when running 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?

Upvotes: 1

Views: 2782

Answers (1)

oikonomiyaki
oikonomiyaki

Reputation: 7951

The first alternative that worked for me is to use Jersey instead of HttpClient. Since hadoop-client already uses jersey-core and jersey-client as a dependency, might as well use what's existing already. Also, I upgraded hadoop-client to 2.6.0, since the Hadoop version I have is 2.6.0.

Then when I removed the http-client in pom.xml, I've noticed that http-client, version 4.2.5, suddenly appears. It confirms that hadoop-client also have it as dependency, as I suspected earlier. So when I reverted to HttpClient solution, and adjusted some lines to suit the older version, it runs successfully in Oozie.

Upvotes: 0

Related Questions