Examples of MessageRecipient


Examples of com.volantis.mps.recipient.MessageRecipient

        Iterator recipientsIterator = messageRecipients.getIterator();

        while (recipientsIterator.hasNext()) {

            MessageRecipient recipient =
                    (MessageRecipient) recipientsIterator.next();

            if (recipient.resolveDeviceName(false) != MessageRecipient.OK) {
                logger.warn("device-resolution-failed-for", recipient);
                recipient.setFailureReason(
                        messageLocalizer.format(
                                "device-resolution-failed-for",
                                recipient));
                failures.addRecipient(recipient);
                continue;
            }

            // if recipient is on this channel
            if (recipient.getChannelName().equals(channelName)) {

                // if we are already creating a device specific recipient
                // list
                if (currentDeviceName != null) {

                    // if this recipient is targeted for a different device than
                    // the last recipient
                    if (!currentDeviceName.equals(recipient.getDeviceName())) {

                        // send exisiting message for current device and
                        // then create a new device dependent recipient list
                        boolean failed = false;
                        Exception cause = null;
                        try {
                            // send message via implemented sendImpl and hold
                            // over failures
                            MessageRecipients localFails =
                                    sendImpl(multiChannelMessage,
                                             deviceSpecificRecips,
                                             messageSender);
                            Iterator lfIterator = localFails.getIterator();

                            while (lfIterator.hasNext()) {
                                failures.addRecipient(
                                        (MessageRecipient) lfIterator.next());
                            }
                        } catch (MessageException me) {
                            failed = true;
                            cause = me;
                        } catch (RecipientException re) {
                            failed = true;
                            cause = re;
                        } finally {
                            if (failed) {
                                populateFailures(deviceSpecificRecips,
                                                 failures,
                                                 cause);

                                continue;
                            }
                        }

                        deviceSpecificRecips = new MessageRecipients();
                        currentDeviceName = recipient.getDeviceName();
                        deviceSpecificRecips.addRecipient(recipient);
                    } else {
                        // else add this recipient to the current device specific
                        // recipient list
                        deviceSpecificRecips.addRecipient(recipient);
                    }
                } else {
                    // this must be the first recipient in the list so we
                    // start the processing by creating a new device specific
                    // recipients list and setting the current device name
                    // to the recipients device
                    currentDeviceName = recipient.getDeviceName();
                    deviceSpecificRecips = new MessageRecipients();
                    deviceSpecificRecips.addRecipient(recipient);
                }
            }
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

                                  Exception cause)
            throws RecipientException {
        Iterator fIterator = deviceSpecificRecips.
                getIterator();
        while (fIterator.hasNext()) {
            MessageRecipient
                    failedRecipient =
                    (MessageRecipient) fIterator.next();

            String address = getAddress(failedRecipient);

            if (cause instanceof MessageException) {
                logger.warn("message-send-failed-to", address);
            } else {
                logger.warn("recipient-exception-for", address);
            }

            if ((failedRecipient.getFailureReason() == null) &&
                    (cause != null)) {
                failedRecipient.setFailureReason(cause.getMessage());
            }

            failures.addRecipient(failedRecipient);
        }
    }
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

        // to multiple recipients in one go; for each recipient this code needs
        // to do a send to the server!


        while (recipientsIterator.hasNext()) {
            MessageRecipient recipient = (MessageRecipient) recipientsIterator.next();

            try {
                // Construct parameters
                String parameterString =
                        constructParameters(formatMSISDN(recipient.getMSISDN(),
                                                         false,
                                                         true),
                                            messageURL,
                                            multiChannelMessage.getSubject());
                // Send the message
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

        MessageRecipients successes = new MessageRecipients();

        container.setFailures(failures);
        container.setSuccesses(successes);
       
        MessageRecipient recipient;
        MessageRecipient clone = null;
       
        Iterator recipientsIterator = recipients.getIterator();

        while (recipientsIterator.hasNext()) {
            recipient = (MessageRecipient)recipientsIterator.next();

            try {
                // Clone the recipient as we want to modify it.
                clone = (MessageRecipient)recipient.clone();


                RecipientInternals.setRecipientType(clone, recipientType);
                int channelStatus = clone.resolveChannelName(false);
                int deviceStatus = clone.resolveDeviceName(false);
               
                if (clone.getChannelName() != null &&
                    clone.getDeviceName() != null) {

                    if (clone.getAddress() != null ||
                        clone.getMSISDN() != null) {
                        successes.addRecipient(clone);
                    } else {
                        clone.setFailureReason(
                                messageLocalizer.format(
                                        "address-resolution-failed-for",
                                        clone));
                        failures.addRecipient(clone);
                    }
                } else {
                    if (deviceStatus != MessageRecipient.OK) {
                        clone.setFailureReason(
                                messageLocalizer.format(
                                        "device-resolution-failed-for",
                                        clone));
                    } else if (channelStatus != MessageRecipient.OK) {
                        clone.setFailureReason(
                                messageLocalizer.format(
                                        "channel-resolution-failed-for",
                                        clone));
                    }

                    failures.addRecipient(clone);
                }
            } catch (CloneNotSupportedException e) {
                // ignore
                logger.error("unexpected-clonenotsupportedexception", e);
            } catch (RecipientException rce) {
                try {
                    clone.setFailureReason(rce.getMessage());
                    failures.addRecipient(clone);
                } catch (RecipientException rce2) {
                    final String messageKey = "recipient-exception-caught";
                    logger.error(messageKey);
                    throw new MessageException(
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

        String currentChannel = null;

        while (recipientsIterator.hasNext()) {
           
            MessageRecipient recipient =
                    (MessageRecipient)recipientsIterator.next();
            try {
                if (recipient.getChannelName() != null) {

                    if (!recipient.getChannelName().equals(currentChannel)) {
                        currentChannel = recipient.getChannelName();
                        MessageChannel channel =
                                (MessageChannel) CHANNEL_MAP.get(currentChannel);
   
                        if (channel!= null) {
                            try {
                                MessageRecipients sendFailures =
                                        channel.send(message,
                                                     recipients,
                                                     replyTo);
                                if (sendFailures != null) {
                                    RecipientInternals.
                                            addRecipients(failures,
                                                          sendFailures);
                                }
                            } catch (RecipientException e) {
                                throw new MessageException(e);
                            }
                        } else {
                            // log channel configuration error
                            logger.error("unconfigured-message-channel",
                                            currentChannel);

                            // add channel recipients to failure list
                            Iterator cfIterator = recipients.getIterator();
                            MessageRecipients channelFailures =
                                    new MessageRecipients();
                            String failMsg =
                                    messageLocalizer.format(
                                            "unconfigured-message-channel",
                                            currentChannel);
                            while (cfIterator.hasNext()) {
                                MessageRecipient mr =
                                        (MessageRecipient) cfIterator.next();
                                if (mr.getChannelName()
                                      .equals(currentChannel)) {
                                    mr.setFailureReason(failMsg);
                                    channelFailures.addRecipient(mr);
                                }
                            }

                            RecipientInternals.addRecipients(failures,
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

            // Failure to create the message hence no failure logged here
            throw new MessageException(e);
        }

        Iterator recipientsIterator = messageRecipients.getIterator();
        MessageRecipient recipient = null;

        while (recipientsIterator.hasNext()) {
            recipient = (MessageRecipient) recipientsIterator.next();
            int recipientType = RecipientInternals.getRecipientType(recipient);
            try {
                switch (recipientType) {
                case RecipientInternals.TO_RECIPIENT:
                    {
                        message.addRecipient(Message.RecipientType.TO,
                                             recipient.getAddress());
                        multipleRecipients.add(recipient);
                        break;
                    }
                case RecipientInternals.CC_RECIPIENT:
                    {
                        message.addRecipient(Message.RecipientType.CC,
                                             recipient.getAddress());
                        multipleRecipients.add(recipient);
                        break;
                    }
                case RecipientInternals.BCC_RECIPIENT:
                    {
                        message.addRecipient(Message.RecipientType.BCC,
                                             recipient.getAddress());
                        multipleRecipients.add(recipient);
                        break;
                    }
                }
            } catch (MessagingException me) {
                // This exception can come from addRecipient so the
                // recipient needs to be added to the failures here
                // and it will not already have been added to the
                // multipleRecipients list so no need to remove it.
                logger.warn("message-recipient-addition-failed-for",
                            recipient.getAddress(), me);
                recipient.setFailureReason(me.getMessage());
                failures.addRecipient(recipient);
            }
        }

        // obtain device name for message header generation
        // from last recipient added
        String currentDeviceName = recipient.getDeviceName();


        // Try and send the messsage
        try {
            message = (MimeMessage) addHeaders(multiChannelMessage,
                                               message,
                                               currentDeviceName);
            MimeMultipart content =
                    multiChannelMessage.generateTargetMessageAsMimeMultipart(
                            currentDeviceName);
            message.setContent(content, content.getContentType());
            Transport.send(message);
        } catch (MessagingException me) {
            for (Iterator i = multipleRecipients.iterator(); i.hasNext();) {
                MessageRecipient failedRecipient = (MessageRecipient) i.next();
                logger.warn("message-send-failed-to",
                            failedRecipient.getAddress());
                logger.error(me);
                failedRecipient.setFailureReason(me.getMessage());
                failures.addRecipient( failedRecipient );
            }
        }

        // Return any failures
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

                    if(LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Submit response " +
                                response.debugString());
                    }
                    if (response.getCommandStatus() != Data.ESME_ROK) {
                        final MessageRecipient failedRecipient =
                            message.getMessageRecipient(i);
                        failedRecipient.setFailureReason(
                            localizer.format("message-submit-failure-with-status",
                                new Integer(response.getCommandStatus())));
                        failedRecipients.add(failedRecipient);
                    }
                }
            } catch (Exception e) {
                final MessageRecipient failedRecipient =
                    message.getMessageRecipient(i);
                failedRecipient.setFailureReason(e.getMessage());
                failedRecipients.add(failedRecipient);
            }
        }       
        if (!failedRecipients.isEmpty()) {
            throw new RequestFailedException(
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

        String deviceName = null;

        // Loop over all the recipients.
        while (recipientsIterator.hasNext()) {
            final MessageRecipient recipient =
                    (MessageRecipient) recipientsIterator.next();
            currentMessage.addRecipient(recipient);
            multipleRecipients.add(recipient);

            // check the device name
            final String currentDevice = recipient.getDeviceName();
            if (deviceName == null) {
                deviceName = currentDevice;
            } else if (currentDevice != null &&
                        !deviceName.equals(currentDevice)) {
                throw new IllegalStateException(
                    "Same device name is expected for all of the recipients.");
            }
        }

        if (deviceName == null) {
            throw new IllegalStateException(
                "At least one recipient with device name is expected.");
        }

        // Try and send the final messsage we were working on.
        try {
            currentMessage.setMessage(
                    multiChannelMessage.generateTargetMessageAsString(
                            deviceName));

            send(currentMessage);
        } catch (RequestFailedException e) {
            for (Iterator iter = e.getFailedRecipients(); iter.hasNext();) {
                final MessageRecipient failedRecipient =
                    (MessageRecipient) iter.next();
                LOGGER.warn("message-send-failed-to",
                        failedRecipient.getMSISDN());
                failures.addRecipient(failedRecipient);
            }
            LOGGER.warn("message-send-failed", e);
        } catch (MessageException me) {
            for (Iterator i = multipleRecipients.iterator(); i.hasNext();) {
                MessageRecipient failedRecipient =
                        (MessageRecipient) i.next();
                LOGGER.warn("message-send-failed-to",
                        failedRecipient.getMSISDN());
                failedRecipient.setFailureReason(me.getMessage());
                failures.addRecipient(failedRecipient);
            }           
            LOGGER.warn("message-send-failed", me);
        }
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

            logger.error("Failed to attach attachments", ee);
        }

        // Now set up the from recipient and send the messages to each
        // recipient specified in the list
        MessageRecipient fromUser = null;
        MessageRecipients failures = null;

        // file used to for debugging
        File outputFile = null;

        try {
            fromUser = new MessageRecipient();
            fromUser.setAddress(new InternetAddress("mps@volantis.com"));

            Session session = new Session();
            session.addRecipients("toList", recipients);
            session.addRecipients("ccList", ccRecipients);
            session.addRecipients("bccList", bccRecipients);
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipient

        osw.write("\nMessageRecipients\n");
        MessageRecipients mrs = session.getRecipients(toList);
        osw.write("\n'TO' recipients\n");
        Iterator it = mrs.getIterator();
        while(it.hasNext()) {
            MessageRecipient mr = (MessageRecipient)it.next();
            osw.write("Address: " + mr.getAddress() + "\n");
            osw.write("MSISDN : " + mr.getMSISDN() + "\n");
            osw.write("Channel: " + mr.getChannelName() + "\n");
            osw.write("Device : " + mr.getDeviceName() + "\n\n");

            // add this device if not already present
            if (!devices.contains(mr.getDeviceName())) {
                devices.add(mr.getDeviceName());
            }
        }
        mrs = session.getRecipients(ccList);
        osw.write("\n'CC' recipients\n");
        it = mrs.getIterator();
        while(it.hasNext()) {
            MessageRecipient mr = (MessageRecipient)it.next();
            osw.write("Address: " + mr.getAddress() + "\n");
            osw.write("MSISDN : " + mr.getMSISDN() + "\n");
            osw.write("Channel: " + mr.getChannelName() + "\n");
            osw.write("Device : " + mr.getDeviceName() + "\n\n");

            // add this device if not already present
            if (!devices.contains(mr.getDeviceName())) {
                devices.add(mr.getDeviceName());
            }
        }
        mrs = session.getRecipients(bccList);
        osw.write("\n'BCC' recipients\n");
        it = mrs.getIterator();
        while(it.hasNext()) {
            MessageRecipient mr = (MessageRecipient)it.next();
            osw.write("Address: " + mr.getAddress() + "\n");
            osw.write("MSISDN : " + mr.getMSISDN() + "\n");
            osw.write("Channel: " + mr.getChannelName() + "\n");
            osw.write("Device : " + mr.getDeviceName() + "\n\n");

            // add this device if not already present
            if (!devices.contains(mr.getDeviceName())) {
                devices.add(mr.getDeviceName());
            }
        }
        osw.write("-------------------------------------------------------\n");
        it = devices.iterator();
        while (it.hasNext()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.