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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations