Search in sources :

Example 16 with ESMClass

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

the class SmppSubmitSmCommand method createSubmitSm.

protected SubmitSm[] createSubmitSm(Exchange exchange) throws SmppException {
    SubmitSm template = createSubmitSmTemplate(exchange);
    byte[][] segments = splitBody(exchange.getIn());
    ESMClass esmClass = exchange.getIn().getHeader(SmppConstants.ESM_CLASS, ESMClass.class);
    if (null != esmClass) {
        template.setEsmClass(esmClass.value());
    // multipart message
    } else if (segments.length > 1) {
        template.setEsmClass(new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI).value());
    }
    SubmitSm[] submitSms = new SubmitSm[segments.length];
    for (int i = 0; i < segments.length; i++) {
        SubmitSm submitSm = SmppUtils.copySubmitSm(template);
        submitSm.setShortMessage(segments[i]);
        submitSms[i] = submitSm;
    }
    return submitSms;
}
Also used : SubmitSm(org.jsmpp.bean.SubmitSm) ESMClass(org.jsmpp.bean.ESMClass)

Example 17 with ESMClass

use of org.jsmpp.bean.ESMClass 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)

Example 18 with ESMClass

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

the class SmppSubmitSmCommand method createSubmitSmTemplate.

@SuppressWarnings({ "unchecked" })
protected SubmitSm createSubmitSmTemplate(Exchange exchange) {
    Message in = exchange.getIn();
    SubmitSm submitSm = new SubmitSm();
    if (in.getHeaders().containsKey(SmppConstants.DATA_CODING)) {
        submitSm.setDataCoding(in.getHeader(SmppConstants.DATA_CODING, Byte.class));
    } else if (in.getHeaders().containsKey(SmppConstants.ALPHABET)) {
        submitSm.setDataCoding(in.getHeader(SmppConstants.ALPHABET, Byte.class));
    } else {
        submitSm.setDataCoding(config.getDataCoding());
    }
    if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR)) {
        submitSm.setDestAddress(in.getHeader(SmppConstants.DEST_ADDR, String.class));
    } else {
        submitSm.setDestAddress(config.getDestAddr());
    }
    if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_TON)) {
        submitSm.setDestAddrTon(in.getHeader(SmppConstants.DEST_ADDR_TON, Byte.class));
    } else {
        submitSm.setDestAddrTon(config.getDestAddrTon());
    }
    if (in.getHeaders().containsKey(SmppConstants.DEST_ADDR_NPI)) {
        submitSm.setDestAddrNpi(in.getHeader(SmppConstants.DEST_ADDR_NPI, Byte.class));
    } else {
        submitSm.setDestAddrNpi(config.getDestAddrNpi());
    }
    if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
        submitSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
    } else {
        submitSm.setSourceAddr(config.getSourceAddr());
    }
    if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
        submitSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
    } else {
        submitSm.setSourceAddrTon(config.getSourceAddrTon());
    }
    if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
        submitSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
    } else {
        submitSm.setSourceAddrNpi(config.getSourceAddrNpi());
    }
    if (in.getHeaders().containsKey(SmppConstants.SERVICE_TYPE)) {
        submitSm.setServiceType(in.getHeader(SmppConstants.SERVICE_TYPE, String.class));
    } else {
        submitSm.setServiceType(config.getServiceType());
    }
    if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
        submitSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
    } else {
        submitSm.setRegisteredDelivery(config.getRegisteredDelivery());
    }
    if (in.getHeaders().containsKey(SmppConstants.PROTOCOL_ID)) {
        submitSm.setProtocolId(in.getHeader(SmppConstants.PROTOCOL_ID, Byte.class));
    } else {
        submitSm.setProtocolId(config.getProtocolId());
    }
    if (in.getHeaders().containsKey(SmppConstants.PRIORITY_FLAG)) {
        submitSm.setPriorityFlag(in.getHeader(SmppConstants.PRIORITY_FLAG, Byte.class));
    } else {
        submitSm.setPriorityFlag(config.getPriorityFlag());
    }
    if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
        submitSm.setScheduleDeliveryTime(SmppUtils.formatTime(in.getHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, Date.class)));
    }
    if (in.getHeaders().containsKey(SmppConstants.VALIDITY_PERIOD)) {
        Object validityPeriod = in.getHeader(SmppConstants.VALIDITY_PERIOD);
        if (validityPeriod instanceof String) {
            submitSm.setValidityPeriod((String) validityPeriod);
        } else if (validityPeriod instanceof Date) {
            submitSm.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
        }
    }
    if (in.getHeaders().containsKey(SmppConstants.REPLACE_IF_PRESENT_FLAG)) {
        submitSm.setReplaceIfPresent(in.getHeader(SmppConstants.REPLACE_IF_PRESENT_FLAG, Byte.class));
    } else {
        submitSm.setReplaceIfPresent(config.getReplaceIfPresentFlag());
    }
    submitSm.setEsmClass(new ESMClass().value());
    Map<java.lang.Short, Object> optinalParamater = in.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
    if (optinalParamater != null) {
        List<OptionalParameter> optParams = createOptionalParametersByCode(optinalParamater);
        submitSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
    } else {
        Map<String, String> optinalParamaters = in.getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
        if (optinalParamaters != null) {
            List<OptionalParameter> optParams = createOptionalParametersByName(optinalParamaters);
            submitSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
        } else {
            submitSm.setOptionalParameters();
        }
    }
    return submitSm;
}
Also used : Message(org.apache.camel.Message) ESMClass(org.jsmpp.bean.ESMClass) Date(java.util.Date) OptionalParameter(org.jsmpp.bean.OptionalParameter) SubmitSm(org.jsmpp.bean.SubmitSm)

Example 19 with ESMClass

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

the class SmppSubmitSmCommand method execute.

@Override
public void execute(Exchange exchange) throws SmppException {
    SubmitSm[] submitSms = createSubmitSm(exchange);
    List<String> messageIDs = new ArrayList<String>(submitSms.length);
    for (int i = 0; i < submitSms.length; i++) {
        SubmitSm submitSm = submitSms[i];
        String messageID;
        if (log.isDebugEnabled()) {
            log.debug("Sending short message {} for exchange id '{}'...", i, exchange.getExchangeId());
        }
        try {
            messageID = session.submitShortMessage(submitSm.getServiceType(), TypeOfNumber.valueOf(submitSm.getSourceAddrTon()), NumberingPlanIndicator.valueOf(submitSm.getSourceAddrNpi()), submitSm.getSourceAddr(), TypeOfNumber.valueOf(submitSm.getDestAddrTon()), NumberingPlanIndicator.valueOf(submitSm.getDestAddrNpi()), submitSm.getDestAddress(), new ESMClass(submitSm.getEsmClass()), submitSm.getProtocolId(), submitSm.getPriorityFlag(), submitSm.getScheduleDeliveryTime(), submitSm.getValidityPeriod(), new RegisteredDelivery(submitSm.getRegisteredDelivery()), submitSm.getReplaceIfPresent(), DataCodings.newInstance(submitSm.getDataCoding()), (byte) 0, submitSm.getShortMessage(), submitSm.getOptionalParameters());
        } catch (Exception e) {
            throw new SmppException(e);
        }
        messageIDs.add(messageID);
    }
    if (log.isDebugEnabled()) {
        log.debug("Sent short message for exchange id '{}' and received message ids '{}'", exchange.getExchangeId(), messageIDs);
    }
    Message message = getResponseMessage(exchange);
    message.setHeader(SmppConstants.ID, messageIDs);
    message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
}
Also used : Message(org.apache.camel.Message) SubmitSm(org.jsmpp.bean.SubmitSm) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) ArrayList(java.util.ArrayList)

Example 20 with ESMClass

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

the class SmppDataSmCommandTest method executeWithConfigurationData.

@Test
public void executeWithConfigurationData() throws Exception {
    Exchange exchange = new DefaultExchange(new DefaultCamelContext(), ExchangePattern.InOut);
    exchange.getIn().setHeader(SmppConstants.COMMAND, "DataSm");
    expect(session.dataShortMessage(eq("CMT"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1616"), eq(TypeOfNumber.UNKNOWN), eq(NumberingPlanIndicator.UNKNOWN), eq("1717"), eq(new ESMClass()), eq(new RegisteredDelivery((byte) 1)), eq(DataCodings.newInstance((byte) 0)))).andReturn(new DataSmResult(new MessageId("1"), null));
    replay(session);
    command.execute(exchange);
    verify(session);
    assertEquals("1", exchange.getOut().getHeader(SmppConstants.ID));
    assertNull(exchange.getOut().getHeader(SmppConstants.OPTIONAL_PARAMETERS));
}
Also used : Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) RegisteredDelivery(org.jsmpp.bean.RegisteredDelivery) ESMClass(org.jsmpp.bean.ESMClass) DataSmResult(org.jsmpp.session.DataSmResult) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) MessageId(org.jsmpp.util.MessageId) Test(org.junit.Test)

Aggregations

ESMClass (org.jsmpp.bean.ESMClass)36 RegisteredDelivery (org.jsmpp.bean.RegisteredDelivery)33 Exchange (org.apache.camel.Exchange)30 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)30 DefaultExchange (org.apache.camel.impl.DefaultExchange)30 Test (org.junit.Test)30 SubmitMultiResult (org.jsmpp.bean.SubmitMultiResult)12 Address (org.jsmpp.bean.Address)11 Date (java.util.Date)9 LinkedHashMap (java.util.LinkedHashMap)6 DataSmResult (org.jsmpp.session.DataSmResult)5 Message (org.apache.camel.Message)4 MessageId (org.jsmpp.util.MessageId)4 OptionalParameter (org.jsmpp.bean.OptionalParameter)3 SubmitSm (org.jsmpp.bean.SubmitSm)3 ArrayList (java.util.ArrayList)2 EasyMock.isNull (org.easymock.EasyMock.isNull)2 SubmitMulti (org.jsmpp.bean.SubmitMulti)2 UnsuccessDelivery (org.jsmpp.bean.UnsuccessDelivery)2 Assert.assertNull (org.junit.Assert.assertNull)2