Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jakarta.mail-api-2.1.0.jar does not work in OSGi environment #629

Closed
mnlipp opened this issue Oct 21, 2022 · 6 comments · Fixed by #675
Closed

jakarta.mail-api-2.1.0.jar does not work in OSGi environment #629

mnlipp opened this issue Oct 21, 2022 · 6 comments · Fixed by #675

Comments

@mnlipp
Copy link
Contributor

mnlipp commented Oct 21, 2022

Describe the bug
An attempt has been made to solve service loader problems in an OSGi environment with org.glassfish.hk2.osgi-resource-locator.

The presence of the required class org.glassfish.hk2.osgiresourcelocator.ServiceLoader is detected with the code

    private static boolean isOsgi() {
        try {
            Class.forName(OSGI_SERVICE_LOADER_CLASS_NAME);
            return true;
        } catch (ClassNotFoundException ignored) {
        }
        return false;
    }

In order for this to work, class org.glassfish.hk2.osgiresourcelocator.ServiceLoader must be in the bundle's classpath (jar becomes "bundle" in OSGi). But the required import is missng in MANIFEST.MF and therefore the provider services are not found.

How it should be
For comparison: jakarta.activation-api-2.1.0.jar has in its MANIFEST.MF the line:

DynamicImport-Package: org.glassfish.hk2.osgiresourcelocator

which ensures that the class org.glassfish.hk2.osgiresourcelocator.ServiceLoader is in the classpath and the Class.forName is successful.

To Reproduce
Steps to reproduce the behavior:

  1. Deploy jakarta.mail-api-2.1.0.jar in an OSGi enviroment
  2. Attempt to use the IMAP provider

Expected behavior
Provider should be found.

@mnlipp
Copy link
Contributor Author

mnlipp commented Oct 22, 2022

Digging further, I found that the hk2 service locator is used in FactoryFinder only. Session.java uses the ServiceLoader without the hk2 "wrapper" and therefore fails to load the providers.

mnlipp added a commit to mnlipp/jgrapes that referenced this issue Oct 23, 2022
@jbescos
Copy link
Member

jbescos commented Oct 24, 2022

Hello,

It was reported one OSGi issue here:
eclipse-ee4j/angus-mail#15

There is already a fix here, but not merged yet:
eclipse-ee4j/angus-mail#19

Do you think that fix is valid here?.

@mnlipp
Copy link
Contributor Author

mnlipp commented Oct 24, 2022

Do you think that fix is valid here?.

Issue #15 is completely independent, i.e. I had to work around that sun.security.util issue in addition to the problem described here.

The proper fix for this issue (#629) -- both the missing import and the inconsistent usage of hk2 (#629 (comment)) -- is actually to "fix" #630. This will make #629 obsolete (This is why I provided a PR for #630 rather than #629.)

@mnlipp mnlipp mentioned this issue Nov 2, 2022
@mnlipp
Copy link
Contributor Author

mnlipp commented Nov 2, 2022

The (interesting) discussion may have caused the focus to be lost. So only as a reminder: this issue is about the missing DynamicImport-Package: org.glassfish.hk2.osgiresourcelocator (see initial description).

@jbescos
Copy link
Member

jbescos commented Nov 8, 2022

@mnlipp this was merged: #633

Can we close this?

@mnlipp
Copy link
Contributor Author

mnlipp commented Nov 8, 2022

Can we close this?

No. If you don't have the OSGi service mediator in your environment, the fallback is to use the hk2 service locator. This can only be found if it is in your class path, i.e. if it is imported. Therefore you need the import (as it is properly done in jakarta-api).

lukasj added a commit to lukasj/mail-api that referenced this issue Apr 28, 2023
…onment (hk2servicelocator)

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
lukasj added a commit that referenced this issue Apr 28, 2023
…k2servicelocator)

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants