wpgsh / cloud4water

Apache License 2.0
0 stars 0 forks source link

How to fix the problom 'dependency jersey-media-multipart in pom.xml cause the error "503 Jersey is not ready yet! "'? #23

Closed sdwbvios closed 7 years ago

sdwbvios commented 7 years ago

API methods createNewAvatar and updateUserAvatar need use multipart . and I refer to the documentation https://jersey.java.net/documentation/latest/media.html#d0e9266 . when I add the dependency

<dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
        <version>2.24</version>
</dependency> 

in pom.xml .It will appear the error '503 Jersey is not ready yet!'. And there is no error log in karaf.log. I am confused about what caused the problem and how to fix it by using this dependency.

alexlukichev commented 7 years ago
  1. The problem was related to class resolution in OSGi. When you have a pom compile dependency the KAR plugin will pull the corresponding bundle into the archive and because of the explicit version requirements (2.24) it will override the already existing bundle that provides the same functionality (2.22.2). Now, the problem is that in Jersey it is also required to register the MIME provider in a non-compliant-OSGi way. And that provider was for 2.22.2 and not for 2.24 that the application code referenced to. OSGi classloader correctly had 2 version of the same library loaded in separate classloader which caused Jersey to fail with NoClassDefFoundError (or such).

    Switching to 2.22.2 and (also very importantly) provided dependency scope removed duplicate library and the Jersey issue has been resolved.

  2. Also it seems to me that you have misconfigured annotations on the multipart method. I fixed this as well.