georchestra / mapstore2-georchestra

geOrchestra newest viewer
Other
6 stars 23 forks source link

httpclient: multiple versions in the classpath ? #622

Open landryb opened 1 year ago

landryb commented 1 year ago

Describe the bug

like #603 but for httpclient/httpcore jars, right now using the mapstore proxy on master yields an error (cf georchestra/datadir#308):

Exception

javax.servlet.ServletException: Servlet.init() for servlet [HttpProxy] threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1684)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:829)

Root Cause

java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory
    org.apache.http.impl.conn.PoolingHttpClientConnectionManager$InternalConnectionFactory.<init>(PoolingHttpClientConnectionManager.java:620)
    org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:181)
    org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:165)
    org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:156)
    org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:132)
    org.apache.http.impl.conn.PoolingHttpClientConnectionManager.<init>(PoolingHttpClientConnectionManager.java:123)
    it.geosolutions.httpproxy.HTTPProxy.init(HTTPProxy.java:135)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1684)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:829)

looking at the content of the war, there are two (conflicting?) versions of http client libs:

# unzip -l /usr/share/lib/georchestra-mapstore/mapstore-generic.war |grep httpc
   328593  2020-03-08 13:04   WEB-INF/lib/httpcore-4.4.13.jar
    14581  2023-05-09 11:03   WEB-INF/lib/metrics-httpclient-3.0.2.jar
   780321  2020-12-26 10:01   WEB-INF/lib/httpclient-4.5.13.jar
   305001  2023-05-09 10:53   WEB-INF/lib/commons-httpclient-3.1.jar
   227275  2023-05-22 17:56   WEB-INF/lib/httpcore-4.2.4.jar
   433368  2023-05-22 17:56   WEB-INF/lib/httpclient-4.2.5.jar
landryb commented 1 year ago

looking at mvn dependency:tree only shows this version.. so i dunno what drags client 4.5.13 & core 4.4.13 ?

[ESC[1;34mINFOESC[m] org.georchestra.mapstore:mapstore-georchestra:war:1.0-SNAPSHOT
[ESC[1;34mINFOESC[m] +- it.geosolutions.mapstore:mapstore-services:jar:1.4-SNAPSHOT:compile
[ESC[1;34mINFOESC[m] |  +- com.codahale.metrics:metrics-httpclient:jar:3.0.2:compile
[ESC[1;34mINFOESC[m] |  |  \- org.apache.httpcomponents:httpclient:jar:4.2.5:compile
[ESC[1;34mINFOESC[m] |  |     \- org.apache.httpcomponents:httpcore:jar:4.2.4:compile

dropping the 'last' versions yields:

java.nio.file.NoSuchFileException: /srv/tomcat/georchestra/webapps/mapstore/WEB-INF/lib/httpclient-4.5.13.jar
    java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)

so something else drags them.

landryb commented 1 year ago

and dropping httpcore 4.2.4 gives the same error:

java.nio.file.NoSuchFileException: /srv/tomcat/georchestra/webapps/mapstore/WEB-INF/lib/httpcore-4.2.4.jar
    java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
landryb commented 1 year ago

an upstream mapstore2 war has httpclient-4.5.13.jar & httpcore-4.4.13.jar so i guess the conflict come from here ?

@pmauduit @tdipisa @offtherailz any hints on how to solve this ? updating to 2023.01 will update the dependencies and automagically fix it ?

landryb commented 1 year ago

apparently the conflict isnt on httpcore but on httpclient, as the problematic class comes from httpclient-4.5.13.jar which is the sole hit in all the jars:

root@demo:/srv/tomcat/georchestra/webapps/mapstore/WEB-INF/lib# jar tf httpclient-4.5.13.jar |grep ManagedHttpClientConnectionFactory
org/apache/http/impl/conn/ManagedHttpClientConnectionFactory.class

tried repackaging that jar without the problematic class but that doesnt help. also tried removing only httpclient-4.2.5.jar but some other jar still depends on it.

landryb commented 1 year ago

apparently that's not new that it causes some kind of conflicts, cf https://github.com/geosolutions-it/MapStore2/issues/7950#issuecomment-1209067089 & https://github.com/geosolutions-it/MapStore2/pull/8468

looking at https://github.com/geosolutions-it/MapStore2/blob/25aeef423d7a1213f7a7971c68c5a3db768dd02d/java/web/pom.xml#L48 it seems the 2022.02.xx branch we're tracking in the MS2 submodule doesnt have geosolutions-it/MapStore2#8468

tdipisa commented 1 year ago

@landryb unfortunately I don't have much time today for a deeper check but after a quick look I can say that most probably that problem will be fixed after the update to 2023.01.xx where we have provided some dependency management fixes also for that.

landryb commented 1 year ago

testing 2023.02, it seems there's indeed only a single version of httpclient libs/jars:

$unzip -l /usr/share/lib/georchestra-mapstore/mapstore-generic.war |grep httpc
   328593  2023-03-08 16:15   WEB-INF/lib/httpcore-4.4.13.jar
   328324  2023-06-21 17:53   WEB-INF/lib/httpcore-4.4.15.jar
   305001  2023-05-09 10:53   WEB-INF/lib/commons-httpclient-3.1.jar
   780321  2023-05-09 11:07   WEB-INF/lib/httpclient-4.5.13.jar
    12002  2023-06-21 17:53   WEB-INF/lib/metrics-httpclient-4.2.12.jar

and the internal mapstore proxy works. So... fixed in master, still affecting the now unmaintained/unsupported 2022.02 branch ?

catmorales commented 11 months ago

We have the same problem with the Docker image in production ( https://hub.docker.com/layers/geosolutionsit/mapstore2-georchestra/2022.02.02-geOrchestra/images/sha256-dc45f092a3d9b26e35709e0b2ca3e025b1434ac1fec63488497e660c216a5100?context=explores) and the consequence is that we can't use the Geobretagne OGC services. @pmauduit modified the docker image to remove the jars files in conflict.