Search in sources :

Example 6 with OptionalParameter

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

the class SmppBinding method createOptionalParameterByName.

private Map<String, Object> createOptionalParameterByName(DeliverSm deliverSm) {
    List<OptionalParameter> oplist = Arrays.asList(deliverSm.getOptionalParameters());
    Map<String, Object> optParams = new HashMap<String, Object>();
    for (OptionalParameter optPara : oplist) {
        try {
            Tag valueOfTag = OptionalParameter.Tag.valueOf(optPara.tag);
            if (valueOfTag != null) {
                if (COctetString.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), ((COctetString) optPara).getValueAsString());
                } else if (org.jsmpp.bean.OptionalParameter.OctetString.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), ((OctetString) optPara).getValueAsString());
                } else if (org.jsmpp.bean.OptionalParameter.Byte.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), Byte.valueOf(((org.jsmpp.bean.OptionalParameter.Byte) optPara).getValue()));
                } else if (org.jsmpp.bean.OptionalParameter.Short.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), Short.valueOf(((org.jsmpp.bean.OptionalParameter.Short) optPara).getValue()));
                } else if (org.jsmpp.bean.OptionalParameter.Int.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), Integer.valueOf(((org.jsmpp.bean.OptionalParameter.Int) optPara).getValue()));
                } else if (Null.class.isInstance(optPara)) {
                    optParams.put(valueOfTag.toString(), null);
                }
            } else {
                LOG.debug("Skipping optional parameter with tag {} because it was not recogized", optPara.tag);
            }
        } catch (IllegalArgumentException e) {
            LOG.debug("Skipping optional parameter with tag {} due " + e.getMessage(), optPara.tag);
        }
    }
    return optParams;
}
Also used : COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Null(org.jsmpp.bean.OptionalParameter.Null) HashMap(java.util.HashMap) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter) Tag(org.jsmpp.bean.OptionalParameter.Tag)

Example 7 with OptionalParameter

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

the class SmppBinding method createOptionalParameterByCode.

private Map<Short, Object> createOptionalParameterByCode(DeliverSm deliverSm) {
    List<OptionalParameter> oplist = Arrays.asList(deliverSm.getOptionalParameters());
    Map<Short, Object> optParams = new HashMap<Short, Object>();
    for (OptionalParameter optPara : oplist) {
        if (COctetString.class.isInstance(optPara)) {
            optParams.put(Short.valueOf(optPara.tag), ((COctetString) optPara).getValueAsString());
        } else if (org.jsmpp.bean.OptionalParameter.OctetString.class.isInstance(optPara)) {
            optParams.put(Short.valueOf(optPara.tag), ((OctetString) optPara).getValue());
        } else if (org.jsmpp.bean.OptionalParameter.Byte.class.isInstance(optPara)) {
            optParams.put(Short.valueOf(optPara.tag), Byte.valueOf(((org.jsmpp.bean.OptionalParameter.Byte) optPara).getValue()));
        } else if (org.jsmpp.bean.OptionalParameter.Short.class.isInstance(optPara)) {
            optParams.put(Short.valueOf(optPara.tag), Short.valueOf(((org.jsmpp.bean.OptionalParameter.Short) optPara).getValue()));
        } else if (org.jsmpp.bean.OptionalParameter.Int.class.isInstance(optPara)) {
            optParams.put(Short.valueOf(optPara.tag), Integer.valueOf(((org.jsmpp.bean.OptionalParameter.Int) optPara).getValue()));
        } else if (Null.class.isInstance(optPara)) {
            optParams.put(Short.valueOf(optPara.tag), null);
        }
    }
    return optParams;
}
Also used : COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Null(org.jsmpp.bean.OptionalParameter.Null) HashMap(java.util.HashMap) OptionalParameter(org.jsmpp.bean.OptionalParameter)

Example 8 with OptionalParameter

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

the class SmppBinding method createSmppMessage.

/**
     * Create a new SmppMessage from the inbound deliver sm or deliver receipt
     */
public SmppMessage createSmppMessage(DeliverSm deliverSm) throws Exception {
    SmppMessage smppMessage = new SmppMessage(deliverSm, configuration);
    String messagePayload = null;
    if (deliverSm.getShortMessage() == null && deliverSm.getOptionalParameters() != null) {
        List<OptionalParameter> oplist = Arrays.asList(deliverSm.getOptionalParameters());
        for (OptionalParameter optPara : oplist) {
            if (OptionalParameter.Tag.MESSAGE_PAYLOAD.code() == optPara.tag && OctetString.class.isInstance(optPara)) {
                messagePayload = ((OctetString) optPara).getValueAsString();
                break;
            }
        }
    }
    if (deliverSm.isSmscDeliveryReceipt()) {
        smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.DeliveryReceipt.toString());
        DeliveryReceipt smscDeliveryReceipt = null;
        if (deliverSm.getShortMessage() != null) {
            smscDeliveryReceipt = deliverSm.getShortMessageAsDeliveryReceipt();
        } else if (messagePayload != null) {
            smscDeliveryReceipt = DefaultDecomposer.getInstance().deliveryReceipt(messagePayload);
        }
        if (smscDeliveryReceipt != null) {
            smppMessage.setBody(smscDeliveryReceipt.getText());
            smppMessage.setHeader(SmppConstants.ID, smscDeliveryReceipt.getId());
            smppMessage.setHeader(SmppConstants.DELIVERED, smscDeliveryReceipt.getDelivered());
            smppMessage.setHeader(SmppConstants.DONE_DATE, smscDeliveryReceipt.getDoneDate());
            if (!"000".equals(smscDeliveryReceipt.getError())) {
                smppMessage.setHeader(SmppConstants.ERROR, smscDeliveryReceipt.getError());
            }
            smppMessage.setHeader(SmppConstants.SUBMIT_DATE, smscDeliveryReceipt.getSubmitDate());
            smppMessage.setHeader(SmppConstants.SUBMITTED, smscDeliveryReceipt.getSubmitted());
            smppMessage.setHeader(SmppConstants.FINAL_STATUS, smscDeliveryReceipt.getFinalStatus());
        }
        if (deliverSm.getOptionalParameters() != null && deliverSm.getOptionalParameters().length > 0) {
            // the deprecated way
            Map<String, Object> optionalParameters = createOptionalParameterByName(deliverSm);
            smppMessage.setHeader(SmppConstants.OPTIONAL_PARAMETERS, optionalParameters);
            // the new way
            Map<Short, Object> optionalParameter = createOptionalParameterByCode(deliverSm);
            smppMessage.setHeader(SmppConstants.OPTIONAL_PARAMETER, optionalParameter);
        }
    } else {
        smppMessage.setHeader(SmppConstants.MESSAGE_TYPE, SmppMessageType.DeliverSm.toString());
        if (deliverSm.getShortMessage() != null) {
            Alphabet alphabet = Alphabet.parseDataCoding(deliverSm.getDataCoding());
            if (SmppUtils.is8Bit(alphabet)) {
                smppMessage.setBody(deliverSm.getShortMessage());
            } else {
                smppMessage.setBody(String.valueOf(new String(deliverSm.getShortMessage(), configuration.getEncoding())));
            }
        } else if (messagePayload != null) {
            smppMessage.setBody(messagePayload);
        }
        smppMessage.setHeader(SmppConstants.SEQUENCE_NUMBER, deliverSm.getSequenceNumber());
        smppMessage.setHeader(SmppConstants.COMMAND_ID, deliverSm.getCommandId());
        smppMessage.setHeader(SmppConstants.SOURCE_ADDR, deliverSm.getSourceAddr());
        smppMessage.setHeader(SmppConstants.SOURCE_ADDR_NPI, deliverSm.getSourceAddrNpi());
        smppMessage.setHeader(SmppConstants.SOURCE_ADDR_TON, deliverSm.getSourceAddrTon());
        smppMessage.setHeader(SmppConstants.DATA_CODING, deliverSm.getDataCoding());
        smppMessage.setHeader(SmppConstants.DEST_ADDR, deliverSm.getDestAddress());
        smppMessage.setHeader(SmppConstants.DEST_ADDR_NPI, deliverSm.getDestAddrNpi());
        smppMessage.setHeader(SmppConstants.DEST_ADDR_TON, deliverSm.getDestAddrTon());
        smppMessage.setHeader(SmppConstants.SCHEDULE_DELIVERY_TIME, deliverSm.getScheduleDeliveryTime());
        smppMessage.setHeader(SmppConstants.VALIDITY_PERIOD, deliverSm.getValidityPeriod());
        smppMessage.setHeader(SmppConstants.SERVICE_TYPE, deliverSm.getServiceType());
    }
    return smppMessage;
}
Also used : OptionalParameter(org.jsmpp.bean.OptionalParameter) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Alphabet(org.jsmpp.bean.Alphabet) DeliveryReceipt(org.jsmpp.bean.DeliveryReceipt) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString)

Example 9 with OptionalParameter

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

the class AbstractSmppCommand method determineTypeClass.

@SuppressWarnings("unchecked")
protected Class<? extends OptionalParameter> determineTypeClass(Tag tag) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    // we have to use reflection because the type field is private
    Field f = tag.getClass().getDeclaredField("type");
    f.setAccessible(true);
    return (Class<? extends OptionalParameter>) f.get(tag);
}
Also used : OptionalParameter(org.jsmpp.bean.OptionalParameter) Field(java.lang.reflect.Field)

Example 10 with OptionalParameter

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

the class AbstractSmppCommand method createOptionalParametersByCode.

protected List<OptionalParameter> createOptionalParametersByCode(Map<Short, Object> optinalParamaters) {
    List<OptionalParameter> optParams = new ArrayList<OptionalParameter>();
    for (Entry<Short, Object> entry : optinalParamaters.entrySet()) {
        OptionalParameter optParam = null;
        Short key = entry.getKey();
        Object value = entry.getValue();
        try {
            if (value == null) {
                optParam = new OptionalParameter.Null(key);
            } else if (value instanceof byte[]) {
                optParam = new OptionalParameter.OctetString(key, (byte[]) value);
            } else if (value instanceof String) {
                optParam = new OptionalParameter.COctetString(key, (String) value);
            } else if (value instanceof Byte) {
                optParam = new OptionalParameter.Byte(key, (Byte) value);
            } else if (value instanceof Integer) {
                optParam = new OptionalParameter.Int(key, (Integer) value);
            } else if (value instanceof Short) {
                optParam = new OptionalParameter.Short(key, (Short) value);
            } else {
                log.info("Couldn't determine optional parameter for value {} (type: {}). Skip this one.", value, value.getClass());
                continue;
            }
            optParams.add(optParam);
        } catch (Exception e) {
            log.info("Couldn't determine optional parameter for key {} and value {}. Skip this one.", key, value);
        }
    }
    return optParams;
}
Also used : OctetString(org.jsmpp.bean.OptionalParameter.OctetString) ArrayList(java.util.ArrayList) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter)

Aggregations

OptionalParameter (org.jsmpp.bean.OptionalParameter)15 OctetString (org.jsmpp.bean.OptionalParameter.OctetString)8 COctetString (org.jsmpp.bean.OptionalParameter.COctetString)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Exchange (org.apache.camel.Exchange)3 Message (org.apache.camel.Message)3 ESMClass (org.jsmpp.bean.ESMClass)3 Null (org.jsmpp.bean.OptionalParameter.Null)3 DataSmResult (org.jsmpp.session.DataSmResult)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 DataSm (org.jsmpp.bean.DataSm)2 DeliverSm (org.jsmpp.bean.DeliverSm)2 Byte (org.jsmpp.bean.OptionalParameter.Byte)2 Short (org.jsmpp.bean.OptionalParameter.Short)2 Tag (org.jsmpp.bean.OptionalParameter.Tag)2