use of org.jsmpp.bean.DeliveryReceipt 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;
}
Aggregations