0

I have problems to declare an e-mail session as an OSGI service. I am using Apache Karaf 3.0.1 as container, Apache Aries for the blueprint JPA and JNDI enhancement.

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

  <bean id="mailSession" class="javax.mail.Session" init-method="getInstance">
      <property name="mail.smtp.host" value="mysmptpip"/>
      <property name="mail.smtp.port" value="25"/>
  </bean>

  <service auto-export="interfaces" ref="mailSession">
    <service-properties>
      <entry key="osgi.jndi.service.name" value="java:mail/MailSession"/>
    </service-properties>
  </service>
</blueprint>

I have an error of type enable to find a matching method on class javax.mail.Session for arguments [{mail.smtp.host=mysmptpip, mail.smtp.port=25}] ...

Does anybody have any idea how this should be fixed ?

In addtion I would like to know how can I declare a JavaMail session as a JNDI resource via Apache blueprint (that will create the service)?

perbellinio
  • 682
  • 5
  • 14
  • 1
    I don't agree with closing this question. It is not opinion based. The author just has an error in his blueprint xml. The correct bean definition should look something like this: mysmptpip 25 – fuemf5 Jun 30 '16 at 15:19

2 Answers2

1

I think you could provide a configured mail Session as a service. So the configuration would be centralized.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
0

BundleContext#registerService() suffices; you can add properties to the service registration if you want to, but it's not necessary. Remember to unregister the service when it's closed.

Tassos Bassoukos
  • 16,017
  • 2
  • 36
  • 40