HttpClientBuilder - java.lang.NoSuchFieldError: INSTANCE

I have a Maven Java project that uses HttpClient to make HTTP requests. On my local Java webserver everything works fine. But after I deploy it to SAP Hana Cloud platform, I get the following error:

java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:52)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<init>(DefaultHttpRequestWriterFactory.java:56)
at org.apache.http.impl.io.DefaultHttpRequestWriterFactory.<clinit>(DefaultHttpRequestWriterFactory.java:46)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:72)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<init>(ManagedHttpClientConnectionFactory.java:84)
at org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.<clinit>(ManagedHttpClientConnectionFactory.java:59)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:493)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:149)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:138)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:114)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:726)
at com.sap.hana.cloud.odata.service.OlingoSampleApp.getHttpclient(OlingoSampleApp.java:382)
at com.sap.hana.cloud.odata.service.OlingoSampleApp.getCsrfToken(OlingoSampleApp.java:374)
at com.sap.hana.cloud.odata.service.ODataCalls.doGet(ODataCalls.java:163)
...

      

My dependency looks like this:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.3.5</version>
    <scope>compile</scope>
</dependency>

      

As per this question java.lang.NoSuchFieldError: org.apache.http.message.BasicLineFormatter.INSTANCE from Mashape Unirest in a Java application I tried to use the following codes to get the ClassLoader resource.

ClassLoader classLoader = this.getClass().getClassLoader();
URL resource = classLoader.getResource("org/apache/http/impl/client/HttpClientBuilder.class");
return resource;

      

and it returns the following

"jar:file:/some/path/WEB-INF/lib/httpclient-4.3.5.jar!/org/apache/http/impl/client/HttpClientBuilder.class"

      

You can see that the jar versions are the same. Every similar question I've looked at had incoherent jar versions as a source of failure. Could there be another reason for this error?

Update

After discussion in the comments, I'll clarify my question:

Dependency tree:

enter image description here

So now I see a version conflict and I deleted neo-java-web-api

. The Loader class now returns version 4.3.2 again. But I am still getting the error from the start.

The new, complete dependency tree without neo-java-web-api

now looks like this: enter image description here

+3


source to share


1 answer


I still couldn't find a solution for the real problem. But at least I could find a workaround. I changed the scope to <scope>provided</scope>

and only used the features that are also available in version 4.1.4. For example, new DefaultHttpClient(cm);

instead ofHttpClientBuilder.create().build();



+2


source







All Articles