use of org.jsmpp.bean.ReplaceSm in project camel by apache.
the class SmppReplaceSmCommand method createReplaceSmTempate.
protected ReplaceSm createReplaceSmTempate(Exchange exchange) {
Message in = exchange.getIn();
ReplaceSm replaceSm = new ReplaceSm();
if (in.getHeaders().containsKey(SmppConstants.ID)) {
replaceSm.setMessageId(in.getHeader(SmppConstants.ID, String.class));
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR)) {
replaceSm.setSourceAddr(in.getHeader(SmppConstants.SOURCE_ADDR, String.class));
} else {
replaceSm.setSourceAddr(config.getSourceAddr());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_TON)) {
replaceSm.setSourceAddrTon(in.getHeader(SmppConstants.SOURCE_ADDR_TON, Byte.class));
} else {
replaceSm.setSourceAddrTon(config.getSourceAddrTon());
}
if (in.getHeaders().containsKey(SmppConstants.SOURCE_ADDR_NPI)) {
replaceSm.setSourceAddrNpi(in.getHeader(SmppConstants.SOURCE_ADDR_NPI, Byte.class));
} else {
replaceSm.setSourceAddrNpi(config.getSourceAddrNpi());
}
if (in.getHeaders().containsKey(SmppConstants.REGISTERED_DELIVERY)) {
replaceSm.setRegisteredDelivery(in.getHeader(SmppConstants.REGISTERED_DELIVERY, Byte.class));
} else {
replaceSm.setRegisteredDelivery(config.getRegisteredDelivery());
}
if (in.getHeaders().containsKey(SmppConstants.SCHEDULE_DELIVERY_TIME)) {
replaceSm.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) {
replaceSm.setValidityPeriod((String) validityPeriod);
} else if (validityPeriod instanceof Date) {
replaceSm.setValidityPeriod(SmppUtils.formatTime((Date) validityPeriod));
}
}
return replaceSm;
}
use of org.jsmpp.bean.ReplaceSm in project camel by apache.
the class SmppReplaceSmCommand method execute.
@Override
public void execute(Exchange exchange) throws SmppException {
byte[] message = getShortMessage(exchange.getIn());
ReplaceSm replaceSm = createReplaceSmTempate(exchange);
replaceSm.setShortMessage(message);
if (log.isDebugEnabled()) {
log.debug("Sending replacement command for a short message for exchange id '{}' and message id '{}'", exchange.getExchangeId(), replaceSm.getMessageId());
}
try {
session.replaceShortMessage(replaceSm.getMessageId(), TypeOfNumber.valueOf(replaceSm.getSourceAddrTon()), NumberingPlanIndicator.valueOf(replaceSm.getSourceAddrNpi()), replaceSm.getSourceAddr(), replaceSm.getScheduleDeliveryTime(), replaceSm.getValidityPeriod(), new RegisteredDelivery(replaceSm.getRegisteredDelivery()), replaceSm.getSmDefaultMsgId(), replaceSm.getShortMessage());
} catch (Exception e) {
throw new SmppException(e);
}
if (log.isDebugEnabled()) {
log.debug("Sent replacement command for a short message for exchange id '{}' and message id '{}'", exchange.getExchangeId(), replaceSm.getMessageId());
}
Message rspMsg = getResponseMessage(exchange);
rspMsg.setHeader(SmppConstants.ID, replaceSm.getMessageId());
}
Aggregations