Search code examples
javaamazon-web-servicessdkwebsphere

Jar conflict issue


I am using aws sdk package to access aws api from web application deployed in a websphere application. During build the application doesn't throws any compile time issue. After deployment it throws java.lang.NoSuchFieldError: org/apache/http/conn/ssl/AllowAllHostnameVerifier.INSTANCE

I read some post, it says about jar conflict. Its taking the default httpclient jars from IBM. I want to point my code to take my version of httpclient which I have given in lib folder. Can someone help me to point my code to pick my version of jars added manually.


Solution

  • In order to make your app use its own version of something that's included in the server, you'll need to use parent-last class loader delegation. Assuming the Apache HTTP client is in your web module's WEB-INF/lib directory, you'll want to make that change to the web module's class loader setting (this doc is specifically from 8.5.5 but should work on any version from the last decade or so): https://www.ibm.com/docs/en/was-nd/8.5.5?topic=loading-configuring-web-module-class-loaders

    Note that parent-last delegation comes with its own set of risks, as there are some things that don't play well with the server if you try and use a version in your app (the Servlet API is one of the more notable ones). If you try this but run into things like ClassCastExceptions or LinkageErrors, you may instead want to put the HTTP client into an isolated shared library (selecting the "use an isolated class loader for this shared library" option) and associate the shared library with your web module or application: https://www.ibm.com/docs/en/was-nd/8.5.5?topic=servers-managing-shared-libraries

    All that said, the simplest solution might just be to update your server. An APAR several years ago (PI50993, included in fixpack 8.5.5.9) removed the application visibility to the server's version of the Apache HTTP client. Moving to a recent fixpack would probably resolve the issue as well.