Examples of MessageRecipients


Examples of com.volantis.mps.recipient.MessageRecipients

            MessageRecipients messageRecipients,
            MessageRecipient messageSender)
            throws RecipientException, MessageException {

        // Maintain a record of recipients for who the message send failed
        MessageRecipients failures = new MessageRecipients();

        // Maintain references to multiple recipients so a failure can be
        // recorded against multiple recipients where to/cc/bcc are combined
        // and can each contain multiple values.
        List multipleRecipients = new ArrayList();

        Iterator recipientsIterator = messageRecipients.getIterator();

        // The message currently under construction.
        SMSMessage currentMessage = new SMSMessage();

        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);
        }

        // Return any failures
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

     * recipients and session and then send the message.
     */
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
            throws ServletException, IOException {
        MessageRecipients recipients = null;
        MessageRecipients ccRecipients = null;
        MessageRecipients bccRecipients = null;

        // Get the recipients from the servlet request
        try {
            recipients = getRecipients(request, RECIPIENTS);
            ccRecipients = getRecipients(request, CCRECIPIENTS);
            bccRecipients = getRecipients(request, BCCRECIPIENTS);

            if (recipients == null) {
                throw new RecipientException("No recipients could be found");
            }
        } catch (Exception ae) {
            logger.error("Error loading recipient set", ae);

            writeError(request, response, ae);

            return;
        }

        // According to the Servlet 2.4 spec:
        // "..The default encoding of a request the container uses to create the
        // request reader and parse POST data must be ???ISO-8859-1??? if none has
        // been specified by the client request. However, in order to
        // indicate to the developer in this case the failure of the client
        // to send a character encoding, the container returns null
        // from the getCharacterEncoding method.."
        String requestEncoding = request.getCharacterEncoding();
        if (requestEncoding == null) {
            requestEncoding = "ISO-8859-1";
        }
        // Are we sending a URL or an XML message?
        String url = request.getParameter("url");
        MultiChannelMessage message = null;

        // Do we have an explicit charset encoding? Null values are allowed and
        // should result in device default charset being used. N.B. the "null"
        // string is sent by the form element when the user does not want to
        // specify a character encoding
        String characterSet = request.getParameter("charset");
        if (characterSet.equalsIgnoreCase("null")) {
            characterSet = null;
        }


        // do we need to generate and save the message to file
        boolean genMessage = false;
        if (request.getParameter("genMsg") != null &&
            request.getParameter("genMsg").equalsIgnoreCase("on")) {
            genMessage = true;
        }

        // get the subject
        String subject = request.getParameter("subject");
        if (characterSet != null) {
            subject = ContentUtilities.convertEncoding(
                    subject,
                    requestEncoding,
                    characterSet
            );
        }

        if (!(url.equals(""))) {
            message = new MultiChannelMessageImpl(new URL(url), subject, characterSet);
        } else {
            String xml = request.getParameter("xml");
            if (characterSet != null) {
                // convert from request char set to specified charset
                xml = ContentUtilities.convertEncoding(
                        xml,
                        requestEncoding,
                        characterSet
                );
            }
            message = new MultiChannelMessageImpl(xml, subject, characterSet);
        }

        try {
            message.addAttachments(getAttachments(request));
        } catch (Exception ee) {
            // log the fact that this failed and carry on.
            // Probably not the best thing to do...
            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 {
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

        osw.write("Address: " + fromUser.getAddress() + "\n");
        osw.write("MSISDN : " + fromUser.getMSISDN() + "\n");
        osw.write("Channel: " + fromUser.getChannelName() + "\n");
        osw.write("Device : " + fromUser.getDeviceName() + "\n");
        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");
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

        String[] names = request.getParameterValues("recipients");
        String[] devices = request.getParameterValues("device");
        String[] type = request.getParameterValues("type");
        String[] channel = request.getParameterValues("channel");

        MessageRecipients messageRecipients = new MessageRecipients();

        for (int i = 0; i < type.length; i++) {
            if (type[i].equals(inType)) {
                if (!names[i].equals("")) {
                    MessageRecipient messageRecipient = new MessageRecipient();

                    // Is there a channel for this index? Is it not empty?
                    if (channel.length > i && !channel[i].equals("")) {
                        // set the channel for the recipient
                        messageRecipient.setChannelName(channel[i]);

                        if (channel[i].equals("smsc")) {
                            // The channel is smsc so set the MSISDN rather
                            // than the address
                            messageRecipient.setMSISDN(names[i]);
                        } else if (channel[i].equals("wappush")) {
                            // The channel is wappush so set the MSISDN rather
                            // than the address
                            messageRecipient.setMSISDN(names[i]);
                        } else if (channel[i].equals("mmsc") &&
                                names[i].charAt(0) == '+') {
                            messageRecipient.setMSISDN(names[i]);
                        } else {
                            messageRecipient.setAddress(
                                    new InternetAddress(names[i]));
                        }
                    } else {
                        // channel is not present or empty so use smtp
                        // as default - This will have to be changed if the
                        // smtp channel is not present in the mcs-config file
                        messageRecipient.setChannelName("smtp");
                    }

                    // If there is a device then set it otherwise let MPS use
                    // the defaults
                    if (devices.length > i) {
                        String device = devices[i];
                        if (!device.equals("")) {
                            messageRecipient.setDeviceName(device);
                        }
                    }

                    // Add recipient to the list of MessageRecipients
                    messageRecipients.addRecipient(messageRecipient);
                }
            }
        }

        return messageRecipients;
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

        // will try and initialise a servlet and get very upset with life!
        multiChannelMessage.setMessageURL ( new URL ( "http://test.message/file" ) );
        multiChannelMessage.setSubject ( "Test Message" );

        // Create some recipients
        MessageRecipients messageRecipients = createTestRecipients ();

        // Create a sender
        MessageRecipient messageSender =
                new MessageRecipient ( new InternetAddress ( "mps@volantis.com" ),
                        "Master" );

        // And now send that message to those recipients from that sender! :-)
        MessageRecipients failures = channel.sendImpl ( multiChannelMessage,
                messageRecipients,
                messageSender );
        assertNotNull ( "Should be a failure list, even if it is empty",
                failures );
        assertTrue ( "Expected some failures",
                failures.getIterator ().hasNext () );

        // Can't access recipients by index (annoyingly) so iterate over the
        // one expected failure here (Note: a mismatched channel is not a
        // failure, as it is expected that the message will be sent to the
        // other channel during the same batch send in a running MPS).
        for ( Iterator i = failures.getIterator (); i.hasNext (); ) {
            MessageRecipient recipient = ( MessageRecipient ) i.next ();
            System.out.println ( "Failure:\n" );
            assertEquals ( "Failed recipient MSISDN should match",
                    "failure",
                    recipient.getMSISDN () );
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

     *                            address of a recipient.
     */
    private MessageRecipients createTestRecipients ()
            throws RecipientException, AddressException {
        // Create a list
        MessageRecipients messageRecipients = new MessageRecipients ();

        // Create a recipient
        MessageRecipient recipient = new MessageRecipient ();
        recipient.setMSISDN ( "0123456789" );
        recipient.setAddress ( new InternetAddress ( "test@volantis.com" ) );
        recipient.setChannelName ( CHANNEL_NAME );
        recipient.setDeviceName ( "Master" );
        messageRecipients.addRecipient ( recipient );

        // Create a recipient
        recipient = new MessageRecipient ();
        recipient.setMSISDN ( "+44123456789" );
        recipient.setAddress ( new InternetAddress ( "me@volantis.com" ) );
        recipient.setChannelName ( CHANNEL_NAME );
        recipient.setDeviceName ( "Master" );
        messageRecipients.addRecipient ( recipient );

        // Create a recipient
        recipient = new MessageRecipient ();
        recipient.setMSISDN ( "failure" );
        recipient.setAddress ( new InternetAddress ( "you@volantis.com" ) );
        recipient.setChannelName ( CHANNEL_NAME );
        recipient.setDeviceName ( "Master" );
        messageRecipients.addRecipient ( recipient );

        // Create a recipient - intentionally for a different channel
        recipient = new MessageRecipient ();
        recipient.setMSISDN ( "1234567890" );
        recipient.setAddress ( new InternetAddress ( "them@volantis.com" ) );
        recipient.setChannelName ( "SMTP" );
        recipient.setDeviceName ( "Master" );
        messageRecipients.addRecipient ( recipient );

        // Return the list
        return messageRecipients;
    }
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

    public void setUp() throws Exception {
        super.setUp();

        message = new MultiChannelMessageImpl("http://localhost:8080/dummy",
                "Test message");
        recipients = new MessageRecipients();
        MessageRecipient recipient = new MessageRecipient(
                new InternetAddress("recipient@volantis.com"), "PC");
        recipients.addRecipient(recipient);
        sender = new MessageRecipient();
        sender.setAddress( new InternetAddress("test@volantis.com"));
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

        public void run() {
            List failureReasons = new ArrayList();
            for (int i=0; i<count; i++) {
                try {
                    // Attempt to send a message.
                    MessageRecipients failures =
                            adapter.sendImpl(mockMessage, recipients, sender);
                    // Record if not all of the messages were sent successfully.
                    final Iterator iterator = failures.getIterator();
                    while(iterator.hasNext()) {
                        MessageRecipient failure =
                                (MessageRecipient) iterator.next();
                        failureReasons.add(failure.getFailureReason());
                    }
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

        final MultiChannelMessage mcMessage =
                createMultiChannelMessage(sendRequest.getMessage());
        addRecipients(session, mpsRecipients);
        final MessageRecipient from = getSender(sendRequest.getSender());
        final MessageRecipients failures =
                sendMessage(session, mcMessage, from);

        final Failures result = aggregateResults(failures);

        if (LOGGER.isDebugEnabled()) {
View Full Code Here

Examples of com.volantis.mps.recipient.MessageRecipients

            throw new IllegalArgumentException("no recipients specified");
        }

        Map mpsMessageRecipients = new HashMap();

        mpsMessageRecipients.put(RecipientType.TO, new MessageRecipients());
        mpsMessageRecipients.put(RecipientType.CC, new MessageRecipients());
        mpsMessageRecipients.put(RecipientType.BCC, new MessageRecipients());

        partitionRecipients(mpsMessageRecipients, recipients);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Exited getRecipients");
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.