Extracting the E-Mail Service

Building a generic E-Mail service for an OSGi environment from the pebble implementation Create a generic E-Mail interface like MailGateway:

public interface MailGateway {
    void send(String emailAddress, String emailName, String to, String subject, String message);
    void send(String emailAddress, String emailName, Collection<String> to, String subject, String message);
    void send(String emailAddress, String emailName, Collection<String> to, Collection<String> cc, Collection<String> bcc, String subject, String message);
}

A reference to the MailGateway service is configured as usual:

<osgi:reference id="mailGateway" interface="de.datenkollektiv.util.email.MailGateway" />

During development a console writer E-Mail stub can be used to satisfy the MailGateway dependency. The Spring configuration for exporting the LoggerMailGateway is straight forward:

<bean id="mailGateway" class="de.datenkollektiv.util.email.impl.LoggerMailGateway" />
<osgi:service ref="mailGateway" interface="de.datenkollektiv.util.email.MailGateway" />

All mail related dependencies are moved away from pebble into the implementing bundle (snippet taken from MANIFEST.MF):

Require-Bundle: com.springsource.javax.mail;bundle-version="[1.4.1,1.5.0)",
    com.springsource.javax.activation;bundle-version="[1.1.1,1.2.0)",
Import-Package:  javax.naming

This post is part of a series about an OSGi experiment: Migrate a monolith to a modular OSGi application architecture.

▷ The Beginning of an OSGi Experiment

▷ Building OSGi ready pebble with Maven

▷ Third time it's a charm

▷ Extracting the first OSGi bundle

▷ Extract the DAO layer

▷ Adding the listener aspect

▶︎ Extracting the E-Mail Service

▷ Adding an OSGi command (Equinox)

▷ ...


Header cover Photo by Matthew Henry from Burst