0

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());
        }
        
    }
KoMaBeLu
  • 63
  • 10
  • What is your project set up? – Mansoor Oct 22 '21 at 16:05
  • 1
    there is no 4.4.15 version of httpcore – op_ Oct 22 '21 at 16:28
  • The most probable cause is a copy of `httpclient` 4.3 or earlier trailing somewhere. – Piotr P. Karwasz Oct 22 '21 at 18:53
  • @Mansoor, using vs code with the tomcat plugin – KoMaBeLu Oct 24 '21 at 15:43
  • @PiotrP.Karwasz yeah I figure something like that but I can't seem to find out where, any ideas on finding this out? – KoMaBeLu Oct 24 '21 at 15:46
  • @KoMaBeLu: can you describe how your integration tests work? Do you simply deploy your application in Tomcat or do you use some other framework? In a Tomcat server you might have some additional libraries in the server's classpath. – Piotr P. Karwasz Oct 24 '21 at 19:55
  • @PiotrP.Karwasz, yup just deploying on the tomcat server. I was thinking something along those lines, but I'll take a look in my tomcat server – KoMaBeLu Oct 26 '21 at 16:56
  • @PiotrP.Karwasz So after some digging, except for some other programs using the older versions and the jars being present in maven/gradle caches, there's no actual copy of older versions on my system so I'm kinda stumped. – KoMaBeLu Oct 26 '21 at 17:09

1 Answers1

1

This problem was caused by an older versions of httpclient-cache on my class path

KoMaBeLu
  • 63
  • 10