Search in sources :

Example 1 with UnsuccessDelivery

use of org.jsmpp.bean.UnsuccessDelivery in project camel by apache.

the class SmppSubmitMultiCommandTest method executeWithConfigurationData.

@Test
public void executeWithConfigurationData() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "SubmitMulti");
    exchange.getIn().setHeader(SmppConstants.ID, "1");
    exchange.getIn().setBody("short message body");
    expect(session.submitMultiple(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), aryEq(new Address[] { new Address(TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1717") }), eq(new ESMClass()), eq((byte) 0), eq((byte) 1), (String) isNull(), (String) isNull(), eq(new RegisteredDelivery(SMSCDeliveryReceipt.SUCCESS_FAILURE)), eq(ReplaceIfPresentFlag.DEFAULT), eq(DataCodings.newInstance((byte) 0)), eq((byte) 0), aryEq("short message body".getBytes()))).andReturn(new SubmitMultiResult("1", new UnsuccessDelivery(new Address(TypeOfNumber.UNKNOWN, NumberingPlanIndicator.UNKNOWN, "1717"), 0)));
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals(Arrays.asList("1"), exchange.getOut().getHeader(SmppConstants.ID));
    assertEquals(1, exchange.getOut().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
    assertNotNull(exchange.getOut().getHeader(SmppConstants.ERROR));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Address(org.jsmpp.bean.Address) SubmitMultiResult(org.jsmpp.bean.SubmitMultiResult) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) UnsuccessDelivery(org.jsmpp.bean.UnsuccessDelivery) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with UnsuccessDelivery

use of org.jsmpp.bean.UnsuccessDelivery in project camel by apache.

the class SmppSubmitMultiCommand method execute.

@Override
public void execute(Exchange exchange) throws SmppException {
    SubmitMulti[] submitMulties = createSubmitMulti(exchange);
    List<SubmitMultiResult> results = new ArrayList<SubmitMultiResult>(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<String>(results.size());
    // {messageID : [{destAddr : address, error : errorCode}]}
    Map<String, List<Map<String, Object>>> errors = new HashMap<String, List<Map<String, Object>>>();
    for (SubmitMultiResult result : results) {
        UnsuccessDelivery[] deliveries = result.getUnsuccessDeliveries();
        if (deliveries != null) {
            List<Map<String, Object>> undelivered = new ArrayList<Map<String, Object>>();
            for (UnsuccessDelivery delivery : deliveries) {
                Map<String, Object> error = new HashMap<String, Object>();
                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 = getResponseMessage(exchange);
    message.setHeader(SmppConstants.ID, messageIDs);
    message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
    if (!errors.isEmpty()) {
        message.setHeader(SmppConstants.ERROR, errors);
    }
}
Also used : ReplaceIfPresentFlag(org.jsmpp.bean.ReplaceIfPresentFlag) Message(org.apache.camel.Message) HashMap(java.util.HashMap) ESMClass(org.jsmpp.bean.ESMClass) ArrayList(java.util.ArrayList) SubmitMultiResult(org.jsmpp.bean.SubmitMultiResult) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) UnsuccessDelivery(org.jsmpp.bean.UnsuccessDelivery) ArrayList(java.util.ArrayList) List(java.util.List) SubmitMulti(org.jsmpp.bean.SubmitMulti) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ESMClass (org.jsmpp.bean.ESMClass)2 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)2 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)2 UnsuccessDelivery (org.jsmpp.bean.UnsuccessDelivery)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 Address (org.jsmpp.bean.Address)1 ReplaceIfPresentFlag (org.jsmpp.bean.ReplaceIfPresentFlag)1 SubmitMulti (org.jsmpp.bean.SubmitMulti)1 Test (org.junit.Test)1