}
@SuppressWarnings({ "rawtypes", "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<String, String> optinalParamaters = in.getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
if (optinalParamaters != null) {
List<OptionalParameter> optParams = new ArrayList<OptionalParameter>();
for (Entry<String, String> entry : optinalParamaters.entrySet()) {
OptionalParameter optParam = null;
try {
Tag tag = Tag.valueOf(entry.getKey());
Class type = determineTypeClass(tag);
if (OctetString.class.equals(type)) {
optParam = new OptionalParameter.OctetString(tag.code(), entry.getValue());
} else if (COctetString.class.equals(type)) {
optParam = new OptionalParameter.COctetString(tag.code(), entry.getValue());
} else if (org.jsmpp.bean.OptionalParameter.Byte.class.equals(type)) {
optParam = new OptionalParameter.Byte(tag.code(), Byte.valueOf(entry.getValue()));
} else if (org.jsmpp.bean.OptionalParameter.Int.class.equals(type)) {
optParam = new OptionalParameter.Int(tag.code(), Integer.valueOf(entry.getValue()));
} else if (org.jsmpp.bean.OptionalParameter.Short.class.equals(type)) {
optParam = new OptionalParameter.Short(tag.code(), Short.valueOf(entry.getValue()));
} else if (org.jsmpp.bean.OptionalParameter.Null.class.equals(type)) {
optParam = new OptionalParameter.Null(tag);
}
optParams.add(optParam);
} catch (Exception e) {
log.info("Couldn't determine optional parameter for key {} and value {}. Skip this one.", entry.getKey(), entry.getValue());
}
}
submitSm.setOptionalParametes(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
submitSm.setOptionalParametes();
}
return submitSm;
}