I'm using Apache's httpcomponents to connect to a webservice. When I run my tests, initializing the client goes without problem. When I want to do an actual integration test however, I get the aforementioned exception with following stack trace:
java.lang.NoSuchFieldError: INSTANCE
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151)
at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:969)
at eu.sonetas.fuga.rs.foo.FooRs.<init>(IbanityRs.java:64)
at eu.sonetas.fuga.rs.foo.FooRs_EInvoicing.<init>(fooRs_EInvoicing.java:45)
I'm using httpclient 4.5.13, httpcore 4.4.14 and httpmime 4.5.13 (all latest versions) and tomcat 9.0.6.
I don't use any build tools, and I am pretty sure there's no other versions of the above jars on my class path.
This is the calling code where things go wrong:
public FooRs() throws FooException {
try {
SSLContext sslContext = SSLContexts.custom()
.loadKeyMaterial(readStore(), KEYPASS.toCharArray())
.build();
this.httpClient = HttpClients.custom().setSSLContext(sslContext).build();
//
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | UnrecoverableKeyException e) {
throw new FooException("Could not initialize FooRs:" e.getMessage());
}
}
CodePudding user response:
This problem was caused by an older versions of httpclient-cache on my class path