Search in sources :

Example 1 with OctetString

use of org.jsmpp.bean.OptionalParameter.OctetString 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 2 with OctetString

use of org.jsmpp.bean.OptionalParameter.OctetString 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 3 with OctetString

use of org.jsmpp.bean.OptionalParameter.OctetString 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 4 with OctetString

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

the class SmppDataSmCommand method createOptionalParameterByName.

protected Map<String, String> createOptionalParameterByName(OptionalParameter[] optionalParameters) {
    if (optionalParameters == null) {
        return null;
    }
    Map<String, String> optParams = new HashMap<String, String>();
    for (OptionalParameter optionalParameter : optionalParameters) {
        String value = null;
        if (optionalParameter instanceof COctetString) {
            value = ((COctetString) optionalParameter).getValueAsString();
        } else if (optionalParameter instanceof OctetString) {
            value = ((OctetString) optionalParameter).getValueAsString();
        } else if (optionalParameter instanceof Int) {
            value = String.valueOf(((Int) optionalParameter).getValue());
        } else if (optionalParameter instanceof Short) {
            value = String.valueOf(((Short) optionalParameter).getValue());
        } else if (optionalParameter instanceof Byte) {
            value = String.valueOf(((Byte) optionalParameter).getValue());
        } else if (optionalParameter instanceof Null) {
            value = null;
        }
        optParams.put(Tag.valueOf(optionalParameter.tag).name(), value);
    }
    return optParams;
}
Also used : OptionalParameter(org.jsmpp.bean.OptionalParameter) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Null(org.jsmpp.bean.OptionalParameter.Null) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) HashMap(java.util.HashMap) Byte(org.jsmpp.bean.OptionalParameter.Byte) COctetString(org.jsmpp.bean.OptionalParameter.COctetString) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) Int(org.jsmpp.bean.OptionalParameter.Int) Short(org.jsmpp.bean.OptionalParameter.Short)

Example 5 with OctetString

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

the class SmppBindingTest method createSmppMessageFromDeliveryReceiptWithOptionalParametersShouldReturnASmppMessage.

@SuppressWarnings("unchecked")
@Test
public void createSmppMessageFromDeliveryReceiptWithOptionalParametersShouldReturnASmppMessage() throws Exception {
    DeliverSm deliverSm = new DeliverSm();
    deliverSm.setSmscDeliveryReceipt();
    deliverSm.setShortMessage("id:2 sub:001 dlvrd:001 submit date:0908312310 done date:0908312311 stat:DELIVRD err:xxx Text:Hello SMPP world!".getBytes());
    deliverSm.setOptionalParameters(new OptionalParameter.OctetString(Tag.SOURCE_SUBADDRESS, "OctetString"), new OptionalParameter.COctetString((short) 0x001D, "COctetString"), new OptionalParameter.Byte(Tag.DEST_ADDR_SUBUNIT, (byte) 0x01), new OptionalParameter.Short(Tag.DEST_TELEMATICS_ID, (short) 1), new OptionalParameter.Int(Tag.QOS_TIME_TO_LIVE, 1), new OptionalParameter.Null(Tag.ALERT_ON_MESSAGE_DELIVERY));
    SmppMessage smppMessage = binding.createSmppMessage(deliverSm);
    assertEquals("Hello SMPP world!", smppMessage.getBody());
    assertEquals(10, smppMessage.getHeaders().size());
    assertEquals("2", smppMessage.getHeader(SmppConstants.ID));
    assertEquals(1, smppMessage.getHeader(SmppConstants.DELIVERED));
    // To avoid the test failure when running in different TimeZone
    //assertEquals(new Date(1251753060000L), smppMessage.getHeader(SmppConstants.DONE_DATE));
    assertEquals("xxx", smppMessage.getHeader(SmppConstants.ERROR));
    //assertEquals(new Date(1251753000000L), smppMessage.getHeader(SmppConstants.SUBMIT_DATE));
    assertEquals(1, smppMessage.getHeader(SmppConstants.SUBMITTED));
    assertEquals(DeliveryReceiptState.DELIVRD, smppMessage.getHeader(SmppConstants.FINAL_STATUS));
    assertEquals(SmppMessageType.DeliveryReceipt.toString(), smppMessage.getHeader(SmppConstants.MESSAGE_TYPE));
    Map<String, Object> optionalParameters = smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
    assertEquals(6, optionalParameters.size());
    assertEquals("OctetString", optionalParameters.get("SOURCE_SUBADDRESS"));
    assertEquals("COctetString", optionalParameters.get("ADDITIONAL_STATUS_INFO_TEXT"));
    assertEquals(Byte.valueOf((byte) 0x01), optionalParameters.get("DEST_ADDR_SUBUNIT"));
    assertEquals(Short.valueOf((short) 1), optionalParameters.get("DEST_TELEMATICS_ID"));
    assertEquals(Integer.valueOf(1), optionalParameters.get("QOS_TIME_TO_LIVE"));
    assertNull("0x00", optionalParameters.get("ALERT_ON_MESSAGE_DELIVERY"));
    Map<Short, Object> optionalParameter = smppMessage.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
    assertEquals(6, optionalParameter.size());
    assertArrayEquals("OctetString".getBytes("UTF-8"), (byte[]) optionalParameter.get(Short.valueOf((short) 0x0202)));
    assertEquals("COctetString", optionalParameter.get(Short.valueOf((short) 0x001D)));
    assertEquals(Byte.valueOf((byte) 0x01), optionalParameter.get(Short.valueOf((short) 0x0005)));
    assertEquals(Short.valueOf((short) 1), optionalParameter.get(Short.valueOf((short) 0x0008)));
    assertEquals(Integer.valueOf(1), optionalParameter.get(Short.valueOf((short) 0x0017)));
    assertNull("0x00", optionalParameter.get(Short.valueOf((short) 0x130C)));
}
Also used : OctetString(org.jsmpp.bean.OptionalParameter.OctetString) OptionalParameter(org.jsmpp.bean.OptionalParameter) OctetString(org.jsmpp.bean.OptionalParameter.OctetString) DeliverSm(org.jsmpp.bean.DeliverSm) Test(org.junit.Test)

Aggregations

OctetString (org.jsmpp.bean.OptionalParameter.OctetString)7 OptionalParameter (org.jsmpp.bean.OptionalParameter)5 COctetString (org.jsmpp.bean.OptionalParameter.COctetString)4 HashMap (java.util.HashMap)3 DeliverSm (org.jsmpp.bean.DeliverSm)3 Null (org.jsmpp.bean.OptionalParameter.Null)3 Test (org.junit.Test)3 Alphabet (org.jsmpp.bean.Alphabet)1 DeliveryReceipt (org.jsmpp.bean.DeliveryReceipt)1 Byte (org.jsmpp.bean.OptionalParameter.Byte)1 Int (org.jsmpp.bean.OptionalParameter.Int)1 Short (org.jsmpp.bean.OptionalParameter.Short)1 Tag (org.jsmpp.bean.OptionalParameter.Tag)1