georchestra / mapstore2-georchestra

geOrchestra newest viewer
Other
6 stars 23 forks source link

jackson - multiple versions in the classpath #603

Closed pmauduit closed 1 year ago

pmauduit commented 1 year ago

Describe the bug

Encountered with the georchestra/mapstore:2022.02.00-geOrchestra docker image, but also on the webapp deployed on demo.georchestra.org/mapstore/ : there are several different and incompatible jackson versions in the classpath:

$ ls jackson*jar 
jackson-annotations-2.10.2.jar  jackson-core-2.13.1.jar      jackson-coreutils-1.6.jar    jackson-jaxrs-base-2.10.5.jar       jackson-module-jaxb-annotations-2.10.5.jar
jackson-annotations-2.13.1.jar  jackson-core-asl-1.9.13.jar  jackson-databind-2.10.2.jar  jackson-jaxrs-json-provider-2.10.5.jar  resteasy-jackson2-provider-3.13.2.Final.jar
jackson-core-2.10.2.jar     jackson-coreutils-1.12.jar   jackson-databind-2.13.1.jar  jackson-mapper-asl-1.9.13.jar

if one are lucky (on demo.georchestra.org it works), the expected - 2.13.1 - version is loaded, and there are no issue, but if not, one can get the following error trying to access the config.json endpoint:

# curl http://localhost:8080/mapstore/configs/config.json
<!doctype html><html lang="en"><head><title>HTTP Status 500 – Internal Server Error</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: &#39;java.lang.String[] com.fasterxml.jackson.annotation.JsonSubTypes$Type.names()&#39;</p><p><b>Description</b> The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: &#39;java.lang.String[] com.fasterxml.jackson.annotation.JsonSubTypes$Type.names()&#39;
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
</pre><p><b>Root Cause</b></p><pre>java.lang.NoSuchMethodError: &#39;java.lang.String[] com.fasterxml.jackson.annotation.JsonSubTypes$Type.names()&#39;
    com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.findSubtypes(JacksonAnnotationIntrospector.java:628)
    com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver._collectAndResolveByTypeId(StdSubtypeResolver.java:296)
    com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver.collectAndResolveSubtypesByTypeId(StdSubtypeResolver.java:212)
    com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findTypeDeserializer(BasicDeserializerFactory.java:1794)
    com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.createCollectionDeserializer(BasicDeserializerFactory.java:1367)
    com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:403)

To Reproduce

deploy the webapp, the docker image is likely to reproduce but since the loading order of the jars in the classpath is not predictible, it can work as it can fail.

Expected behavior

Only one version - 2.13.1 - is available in the classpath.

Desktop (please complete the following information):

Additional context

It seems to fail in a docker environment, but okay-ish in a regular setup (demo.georchestra.org is making use of the georchestra/ansible playbook to automate the setup/configuration).

landryb commented 1 year ago

i've had a quick look and in the maven dependency tree only jackson 2.10.2 is pulled as a direct dependency of https://mvnrepository.com/artifact/com.github.java-json-tools/json-patch/1.12 - so i don't understand what pulls 2.13.1.

maybe a tomcat (regular deployment) vs jetty (docker) issue if it only shows there ?

pmauduit commented 1 year ago

maybe a tomcat (regular deployment) vs jetty (docker) issue if it only shows there ?

no, the docker image is also making use of tomcat

landryb commented 1 year ago

dunno if that'd be a smart move or not, but maybe one of the versions can be excluded from the war via packagingExcludes as done in c008b965dd ?

landryb commented 1 year ago

currently experiencing it on https://demo.georchestra.org/mapstore/ (deployed with ansible so tomcat+wars) where loading localConfig.json fails with a 500 code (cf https://demo.georchestra.org/mapstore/configs/localConfig.json):

HTTP Status 500 – Internal Server Error

Type Exception Report

Message Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'java.lang.String[] com.fasterxml.jackson.annotation.JsonSubTypes$Type.names()'

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: 'java.lang.String[] com.fasterxml.jackson.annotation.JsonSubTypes$Type.names()'
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1082)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

java.lang.NoSuchMethodError: 'java.lang.String[] com.fasterxml.jackson.annotation.JsonSubTypes$Type.names()'
    com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.findSubtypes(JacksonAnnotationIntrospector.java:628)
    com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver._collectAndResolveByTypeId(StdSubtypeResolver.java:296)
    com.fasterxml.jackson.databind.jsontype.impl.StdSubtypeResolver.collectAndResolveSubtypesByTypeId(StdSubtypeResolver.java:212)
    com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findTypeDeserializer(BasicDeserializerFactory.java:1794)
    com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.createCollectionDeserializer(BasicDeserializerFactory.java:1367)

something is really wrong here. @tdipisa @offtherailz any idea ?

tdipisa commented 1 year ago

@landryb @pmauduit it's something we fixed on the MS side as well as some other downstream MS projects when working on https://github.com/geosolutions-it/MapStore2/pull/8764 It is possible to fix this by including the following MVN dependencyManagement block in the root pom file here:

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-core</artifactId>
                <version>2.13.1</version>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-annotations</artifactId>
                <version>2.13.1</version>
            </dependency>

            <dependency>
                <groupId>com.fasterxml.jackson.core</groupId>
                <artifactId>jackson-databind</artifactId>
                <version>2.13.1</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

and then adding the following in web/pom here:

      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-core</artifactId>
      </dependency>

      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-annotations</artifactId>
      </dependency>

      <dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
      </dependency>

That should fix the problem.

jeanmi151 commented 1 year ago

Thanks @landryb for the fix Could you also remake the docker image for georchestra/mapstore:2022.02.00-geOrchestra version with your modification ?

edevosc2c commented 1 year ago

I've looked at the GitHub actions workflow and all of what's needed is to create a new release (with a new tag) for publishing the new docker image: https://github.com/georchestra/mapstore2-georchestra/blob/master/.github/workflows/mapstore.yml#L115

landryb commented 1 year ago

you guys know better than me how this whack-a-mole works, feel free to do whatever is needed :)