Hi, sorry for the late reply, I was on vacation. Thank you for the tip, looking up with "aries:services" worked like a charm. Here is a JavaMail blueprint example for future reference. After dropping this file in the deploy folder, it is possible to obtain the JavaMail session via JNDI lookup "aries:services/mailSession".
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <!-- declare a javax.mail.Session instance which will be created by invoking the static factory method getInstance --> <bean id="mailSession" class="javax.mail.Session" factory-method= "getInstance"> <argument> <!-- passing in input a java.util.Properties object populated as defined below --> <props> <prop key="mail.smtp.host" value="smtp.example.org"></prop> <prop key="mail.smtp.port" value="465"></prop> <prop key="mail.smtp.auth" value="true"></prop> <prop key="mail.smtp.user" value="smtpuser"></prop> <prop key="password" value="smtp-password"></prop> <prop key="mail.smtp.socketFactory.port" value="465"></prop> <prop key="class" value="javax.net.ssl.SSLSocketFactory"></ prop> </props> </argument> </bean> <!-- publish the bean identified by id "mailSession" --> <service auto-export="all-classes" ref="mailSession"> <service-properties> <!-- with JNDI name suffix "mailSession" --> <entry key="osgi.jndi.service.name" value="mailSession"/> </service-properties> </service> </blueprint> On Sat, Jul 18, 2020 at 9:39 AM Benjamin Graf <[email protected]> wrote: > Hi Gian, > > try using aries:services instead of osgi:service for jndi lookup. This > will avoid creating a proxy around. > (https://aries.apache.org/modules/jndiproject.html) > > Regards, > > Benjamin > > On 17.07.2020 10:28, Giamma wrote: > > Hi, > > > > I have an application that tries to access a JavaMail session over JNDI. > > > > To make it run in Karaf I tried the following without luck: > > > > 1. I created a blueprint file which creates and configures the Java > Mail > > session > > 2. I configured the application to lookup the mail session as an OSGi > > service using JNDI name osgi:service/<mail-session-name> > > > > The mail session shows up in the jndi:names table: > > > > JNDI Name │ Class Name > > ─────────────────────────┼─────────────────────────────────────────────── > > osgi:service/jndi │ org.apache.karaf.jndi.internal.JndiServiceImpl > > osgi:service/mailSession │ javax.mail.Session > > > > but it is not usable because when I try to look it up, the blueprint > > container tries to proxy it, which is not possible because > > javax.mail.Session is a final class. > > > > Is there a better way to make a javax.mail.Session available over JNDI in > > Karaf? Something that does not require to write dedicated code that will > > use the JNDI API to bind the Session instance in the JNDI context? > Ideally > > I would like the session configuration to be easily editable, and the > above > > approach looked good in principle, because I just had to drop a blueprint > > file in the /deploy folder with all parameters, therefore easily > editable. > > > > Thanks in advance. > > > -- Gian Maria Romanato <gm.romanato (at) gmail (dot) com>
