Search in sources :

Example 1 with NotificationSettings

use of org.nhindirect.gateway.smtp.NotificationSettings in project nhin-d by DirectProject.

the class TimelyAndReliableLocalDelivery method init.

/**
	 * {@inheritDoc}
	 */
public void init() throws MessagingException {
    super.init();
    try {
        final String sDispatchedDelay = GatewayConfiguration.getConfigurationParam(DISPATCHED_MDN_DELAY, this, "0");
        try {
            dispatchedMDNDelay = Integer.valueOf(sDispatchedDelay).intValue();
        } catch (NumberFormatException e) {
            // in case of parsing exceptions
            dispatchedMDNDelay = 0;
        }
        // create an instance of the local delivery if we can
        localDeliveryMailet = createLocalDeliveryClass();
        final Method initMethod = Mailet.class.getDeclaredMethod("init", MailetConfig.class);
        serviceMethod = Mailet.class.getDeclaredMethod("service", Mail.class);
        // set private objects if they exist
        final Class<?> localDeliveryMailetClass = localDeliveryMailet.getClass();
        Field field = getDeclaredFieldQuietly(localDeliveryMailetClass, "rrt");
        if (field != null) {
            field.setAccessible(true);
            field.set(localDeliveryMailet, rrt);
        }
        field = getDeclaredFieldQuietly(localDeliveryMailetClass, "usersRepository");
        if (field != null) {
            field.setAccessible(true);
            field.set(localDeliveryMailet, usersRepository);
        }
        field = getDeclaredFieldQuietly(localDeliveryMailetClass, "mailboxManager");
        if (field != null) {
            field.setAccessible(true);
            field.set(localDeliveryMailet, mailboxManager);
        }
        field = getDeclaredFieldQuietly(localDeliveryMailetClass, "domainList");
        if (field != null) {
            field.setAccessible(true);
            field.set(localDeliveryMailet, domainList);
        }
        field = getDeclaredFieldQuietly(localDeliveryMailetClass, "fileSystem");
        if (field != null) {
            field.setAccessible(true);
            field.set(localDeliveryMailet, fileSystem);
        }
        initMethod.invoke(localDeliveryMailet, this.getMailetConfig());
    } catch (Exception e) {
        throw new MessagingException("Failed to initialize TimelyAndReliableLocalDelivery.", e);
    }
    notificationProducer = new ReliableDispatchedNotificationProducer(new NotificationSettings(true, "Local Direct Delivery Agent", "Your message was successfully dispatched."));
}
Also used : Field(java.lang.reflect.Field) Mail(org.apache.mailet.Mail) MessagingException(javax.mail.MessagingException) NotificationSettings(org.nhindirect.gateway.smtp.NotificationSettings) Method(java.lang.reflect.Method) Mailet(org.apache.mailet.Mailet) MessagingException(javax.mail.MessagingException) ReliableDispatchedNotificationProducer(org.nhindirect.gateway.smtp.ReliableDispatchedNotificationProducer)

Example 2 with NotificationSettings

use of org.nhindirect.gateway.smtp.NotificationSettings in project nhin-d by DirectProject.

the class RESTSmtpAgentConfig method buildMDNSettings.

protected void buildMDNSettings() {
    Setting autoResponseSettings;
    Setting prodNameSetting;
    Setting textSetting;
    try {
        autoResponseSettings = settingsService.getSetting("MDNAutoResponse");
        prodNameSetting = settingsService.getSetting("MDNProdName");
        textSetting = settingsService.getSetting("MDNProdName");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting MDN settings: " + e.getMessage(), e);
    }
    boolean autoResponse = (autoResponseSettings == null) ? true : Boolean.parseBoolean(autoResponseSettings.getValue());
    String prodName = (prodNameSetting == null) ? "" : prodNameSetting.getValue();
    String text = (textSetting == null) ? "" : textSetting.getValue();
    notificationProducer = new NotificationProducer(new NotificationSettings(autoResponse, prodName, text));
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) NotificationProducer(org.nhindirect.gateway.smtp.NotificationProducer) Setting(org.nhindirect.config.model.Setting) NotificationSettings(org.nhindirect.gateway.smtp.NotificationSettings) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException)

Example 3 with NotificationSettings

use of org.nhindirect.gateway.smtp.NotificationSettings in project nhin-d by DirectProject.

the class XMLSmtpAgentConfig method buildMDNSettings.

/*
	 * Builds the MDN settings
	 */
private void buildMDNSettings(Node MDNNode) {
    if (MDNNode.getNodeType() == Node.ELEMENT_NODE) {
        Element settingsNode = (Element) MDNNode;
        String autoResponseString = settingsNode.getAttribute("autoResponse");
        boolean autoResponse = (autoResponseString == null || autoResponseString.isEmpty()) ? true : Boolean.parseBoolean(autoResponseString);
        String prodName = settingsNode.getAttribute("productName");
        String text = null;
        Node childNode = MDNNode.getFirstChild();
        do {
            if (childNode.getNodeType() == Node.ELEMENT_NODE) {
                if (childNode.getNodeName().equalsIgnoreCase("text"))
                    text = childNode.getFirstChild().getNodeValue();
            }
            childNode = childNode.getNextSibling();
        } while (childNode != null);
        notificationProducer = new NotificationProducer(new NotificationSettings(autoResponse, prodName, text));
    }
}
Also used : NotificationProducer(org.nhindirect.gateway.smtp.NotificationProducer) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) NotificationSettings(org.nhindirect.gateway.smtp.NotificationSettings)

Example 4 with NotificationSettings

use of org.nhindirect.gateway.smtp.NotificationSettings in project nhin-d by DirectProject.

the class WSSmtpAgentConfig method buildMDNSettings.

protected void buildMDNSettings() {
    Setting autoResponseSettings;
    Setting prodNameSetting;
    Setting textSetting;
    try {
        autoResponseSettings = cfService.getSettingByName("MDNAutoResponse");
        prodNameSetting = cfService.getSettingByName("MDNProdName");
        textSetting = cfService.getSettingByName("MDNText");
    } catch (Exception e) {
        throw new SmtpAgentException(SmtpAgentError.InvalidConfigurationFormat, "WebService error getting MDN settings: " + e.getMessage(), e);
    }
    boolean autoResponse = (autoResponseSettings == null) ? true : Boolean.parseBoolean(autoResponseSettings.getValue());
    String prodName = (prodNameSetting == null) ? "" : prodNameSetting.getValue();
    String text = (textSetting == null) ? "" : textSetting.getValue();
    notificationProducer = new NotificationProducer(new NotificationSettings(autoResponse, prodName, text));
}
Also used : SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) NotificationProducer(org.nhindirect.gateway.smtp.NotificationProducer) Setting(org.nhind.config.Setting) NotificationSettings(org.nhindirect.gateway.smtp.NotificationSettings) AddressException(javax.mail.internet.AddressException) SmtpAgentException(org.nhindirect.gateway.smtp.SmtpAgentException) PolicyParseException(org.nhindirect.policy.PolicyParseException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException)

Example 5 with NotificationSettings

use of org.nhindirect.gateway.smtp.NotificationSettings in project nhin-d by DirectProject.

the class DirectXdMailet method init.

/*
     * (non-Javadoc)
     * 
     * @see org.apache.mailet.base.GenericMailet#init()
     */
@Override
public void init() throws MessagingException {
    LOGGER.info("Initializing DirectXdMailet");
    super.init();
    // Get the endpoint URL
    endpointUrl = getInitParameter("EndpointURL");
    if (StringUtils.isBlank(endpointUrl)) {
        LOGGER.error("DirectXdMailet endpoint URL cannot be empty or null.");
        throw new MessagingException("DirectXdMailet endpoint URL cannot be empty or null.");
    }
    // Get the config-service URL
    try {
        configServiceUrl = getInitParameter("ConfigURL");
    } catch (Exception e) {
    // eat it
    }
    notificationProducer = new ReliableDispatchedNotificationProducer(new NotificationSettings(true, "Direct XD Delivery Agent", "Your message was successfully dispatched."));
}
Also used : MessagingException(javax.mail.MessagingException) NotificationSettings(org.nhindirect.gateway.smtp.NotificationSettings) MessagingException(javax.mail.MessagingException) AddressException(javax.mail.internet.AddressException) ReliableDispatchedNotificationProducer(org.nhindirect.gateway.smtp.ReliableDispatchedNotificationProducer)

Aggregations

NotificationSettings (org.nhindirect.gateway.smtp.NotificationSettings)5 AddressException (javax.mail.internet.AddressException)3 NotificationProducer (org.nhindirect.gateway.smtp.NotificationProducer)3 MessagingException (javax.mail.MessagingException)2 ReliableDispatchedNotificationProducer (org.nhindirect.gateway.smtp.ReliableDispatchedNotificationProducer)2 SmtpAgentException (org.nhindirect.gateway.smtp.SmtpAgentException)2 PolicyParseException (org.nhindirect.policy.PolicyParseException)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 CertificateException (java.security.cert.CertificateException)1 Mail (org.apache.mailet.Mail)1 Mailet (org.apache.mailet.Mailet)1 Setting (org.nhind.config.Setting)1 Setting (org.nhindirect.config.model.Setting)1 Element (org.w3c.dom.Element)1 Node (org.w3c.dom.Node)1