@Override
    public void execute(Exchange exchange) throws SmppException {
        SubmitMulti[] submitMulties = createSubmitMulti(exchange);
        List<SubmitMultiResult> results = new ArrayList<>(submitMulties.length);

        for (SubmitMulti submitMulti : submitMulties) {
            SubmitMultiResult result;
            if (log.isDebugEnabled()) {
                log.debug("Sending multiple short messages for exchange id '{}'...", exchange.getExchangeId());
            }

            try {
                result = session.submitMultiple(
                        submitMulti.getServiceType(),
                        TypeOfNumber.valueOf(submitMulti.getSourceAddrTon()),
                        NumberingPlanIndicator.valueOf(submitMulti.getSourceAddrNpi()),
                        submitMulti.getSourceAddr(),
                        (Address[]) submitMulti.getDestAddresses(),
                        new ESMClass(submitMulti.getEsmClass()),
                        submitMulti.getProtocolId(),
                        submitMulti.getPriorityFlag(),
                        submitMulti.getScheduleDeliveryTime(),
                        submitMulti.getValidityPeriod(),
                        new RegisteredDelivery(submitMulti.getRegisteredDelivery()),
                        new ReplaceIfPresentFlag(submitMulti.getReplaceIfPresentFlag()),
                        DataCodings.newInstance(submitMulti.getDataCoding()),
                        submitMulti.getSmDefaultMsgId(),
                        submitMulti.getShortMessage(),
                        submitMulti.getOptionalParameters());
                results.add(result);
            } catch (Exception e) {
                throw new SmppException(e);
            }
        }

        if (log.isDebugEnabled()) {
            log.debug("Sent multiple short messages for exchange id '{}' and received results '{}'", exchange.getExchangeId(),
                    results);
        }

        List<String> messageIDs = new ArrayList<>(results.size());
        // {messageID : [{destAddr : address, error : errorCode}]}
        Map<String, List<Map<String, Object>>> errors = new HashMap<>();

        for (SubmitMultiResult result : results) {
            UnsuccessDelivery[] deliveries = result.getUnsuccessDeliveries();

            if (deliveries != null) {
                List<Map<String, Object>> undelivered = new ArrayList<>();

                for (UnsuccessDelivery delivery : deliveries) {
                    Map<String, Object> error = new HashMap<>();
                    error.put(SmppConstants.DEST_ADDR, delivery.getDestinationAddress().getAddress());
                    error.put(SmppConstants.ERROR, delivery.getErrorStatusCode());
                    undelivered.add(error);
                }

                if (!undelivered.isEmpty()) {
                    errors.put(result.getMessageId(), undelivered);
                }
            }

            messageIDs.add(result.getMessageId());
        }

        Message message = ExchangeHelper.getResultMessage(exchange);
        message.setHeader(SmppConstants.ID, messageIDs);
        message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
        if (!errors.isEmpty()) {
            message.setHeader(SmppConstants.ERROR, errors);
        }
    }
@Test
    public void execute() throws Exception {
        Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
        exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
        exchange.getIn().setHeader(SmppConstants.ID, "1");
        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_TON, TypeOfNumber.NATIONAL.value());
        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR_NPI, NumberingPlanIndicator.NATIONAL.value());
        exchange.getIn().setHeader(SmppConstants.SOURCE_ADDR, "1818");
        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_TON, TypeOfNumber.INTERNATIONAL.value());
        exchange.getIn().setHeader(SmppConstants.DEST_ADDR_NPI, NumberingPlanIndicator.INTERNET.value());
        exchange.getIn().setHeader(SmppConstants.DEST_ADDR, Arrays.asList("1919"));
        exchange.getIn().setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, new Date(1111111));
        exchange.getIn().setHeader(SmppConstants.VALIDITY_PERIOD, new Date(2222222));
        exchange.getIn().setHeader(SmppConstants.PROTOCOL_ID, (byte) 1);
        exchange.getIn().setHeader(SmppConstants.PRIORITY_FLAG, (byte) 2);
        exchange.getIn().setHeader(SmppConstants.REGISTERED_DELIVERY,
                new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE).value());
        exchange.getIn().setHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, ReplaceIfPresentFlag.REPLACE.value());
        exchange.getIn().setBody("short message body");
        when(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.NATIONAL), eq(NumberingPlanIndicator.NATIONAL), eq("1818"),
                eq(new Address[] { new Address(TypeOfNumber.INTERNATIONAL, NumberingPlanIndicator.INTERNET, "1919") }),
                eq(new ESMClass()), eq((byte) 1), eq((byte) 2), eq("-300101001831100+"), eq("-300101003702200+"),
                eq(new RegisteredDelivery(SMSCDeliveryReceipt.FAILURE)),
                eq(ReplaceIfPresentFlag.REPLACE), eq(DataCodings.newInstance((byte) 0)), eq((byte) 0),
                eq("short message body".getBytes())))
                .thenReturn(new SubmitMultiResult("1", null, null));

        command.execute(exchange);

        assertEquals(Collections.singletonList("1"), exchange.getMessage().getHeader(SmppConstants.ID));
        assertEquals(1, exchange.getMessage().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
        assertNull(exchange.getMessage().getHeader(SmppConstants.ERROR));
    }