use of org.jsmpp.bean.SubmitSm in project camel by apache.
the class SmppSubmitSmCommand method createSubmitSm.
protected SubmitSm[] createSubmitSm(Exchange exchange) throws SmppException {
SubmitSm template = createSubmitSmTemplate(exchange);
byte[][] segments = splitBody(exchange.getIn());
ESMClass esmClass = exchange.getIn().getHeader(SmppConstants.ESM_CLASS, ESMClass.class);
if (null != esmClass) {
template.setEsmClass(esmClass.value());
// multipart message
} else if (segments.length > 1) {
template.setEsmClass(new ESMClass(MessageMode.DEFAULT, MessageType.DEFAULT, GSMSpecificFeature.UDHI).value());
}
SubmitSm[] submitSms = new SubmitSm[segments.length];
for (int i = 0; i < segments.length; i++) {
SubmitSm submitSm = SmppUtils.copySubmitSm(template);
submitSm.setShortMessage(segments[i]);
submitSms[i] = submitSm;
}
return submitSms;
}
use of org.jsmpp.bean.SubmitSm in project camel by apache.
the class SmppSubmitSmCommand method createSubmitSmTemplate.
@SuppressWarnings({ "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<java.lang.Short, Object> optinalParamater = in.getHeader(SmppConstants.OPTIONAL_PARAMETER, Map.class);
if (optinalParamater != null) {
List<OptionalParameter> optParams = createOptionalParametersByCode(optinalParamater);
submitSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
Map<String, String> optinalParamaters = in.getHeader(SmppConstants.OPTIONAL_PARAMETERS, Map.class);
if (optinalParamaters != null) {
List<OptionalParameter> optParams = createOptionalParametersByName(optinalParamaters);
submitSm.setOptionalParameters(optParams.toArray(new OptionalParameter[optParams.size()]));
} else {
submitSm.setOptionalParameters();
}
}
return submitSm;
}
use of org.jsmpp.bean.SubmitSm in project camel by apache.
the class SmppSubmitSmCommand method execute.
@Override
public void execute(Exchange exchange) throws SmppException {
SubmitSm[] submitSms = createSubmitSm(exchange);
List<String> messageIDs = new ArrayList<String>(submitSms.length);
for (int i = 0; i < submitSms.length; i++) {
SubmitSm submitSm = submitSms[i];
String messageID;
if (log.isDebugEnabled()) {
log.debug("Sending short message {} for exchange id '{}'...", i, exchange.getExchangeId());
}
try {
messageID = session.submitShortMessage(submitSm.getServiceType(), TypeOfNumber.valueOf(submitSm.getSourceAddrTon()), NumberingPlanIndicator.valueOf(submitSm.getSourceAddrNpi()), submitSm.getSourceAddr(), TypeOfNumber.valueOf(submitSm.getDestAddrTon()), NumberingPlanIndicator.valueOf(submitSm.getDestAddrNpi()), submitSm.getDestAddress(), new ESMClass(submitSm.getEsmClass()), submitSm.getProtocolId(), submitSm.getPriorityFlag(), submitSm.getScheduleDeliveryTime(), submitSm.getValidityPeriod(), new RegisteredDelivery(submitSm.getRegisteredDelivery()), submitSm.getReplaceIfPresent(), DataCodings.newInstance(submitSm.getDataCoding()), (byte) 0, submitSm.getShortMessage(), submitSm.getOptionalParameters());
} catch (Exception e) {
throw new SmppException(e);
}
messageIDs.add(messageID);
}
if (log.isDebugEnabled()) {
log.debug("Sent short message for exchange id '{}' and received message ids '{}'", exchange.getExchangeId(), messageIDs);
}
Message message = getResponseMessage(exchange);
message.setHeader(SmppConstants.ID, messageIDs);
message.setHeader(SmppConstants.SENT_MESSAGE_COUNT, messageIDs.size());
}
use of org.jsmpp.bean.SubmitSm in project camel by apache.
the class SmppUtils method copySubmitSm.
public static SubmitSm copySubmitSm(SubmitSm src) {
SubmitSm dest = new SubmitSm();
dest.setCommandId(src.getCommandId());
dest.setCommandLength(src.getCommandLength());
dest.setCommandStatus(src.getCommandStatus());
dest.setDataCoding(src.getDataCoding());
dest.setDestAddress(src.getDestAddress());
dest.setDestAddrNpi(src.getDestAddrNpi());
dest.setDestAddrTon(src.getDestAddrTon());
dest.setEsmClass(src.getEsmClass());
dest.setOptionalParameters(src.getOptionalParameters());
dest.setPriorityFlag(src.getPriorityFlag());
dest.setProtocolId(src.getProtocolId());
dest.setRegisteredDelivery(src.getRegisteredDelivery());
dest.setReplaceIfPresent(src.getReplaceIfPresent());
dest.setScheduleDeliveryTime(src.getScheduleDeliveryTime());
dest.setSequenceNumber(src.getSequenceNumber());
dest.setServiceType(src.getServiceType());
dest.setShortMessage(src.getShortMessage());
dest.setSmDefaultMsgId(src.getSmDefaultMsgId());
dest.setSourceAddr(src.getSourceAddr());
dest.setSourceAddrNpi(src.getSourceAddrNpi());
dest.setSourceAddrTon(src.getSourceAddrTon());
dest.setValidityPeriod(src.getValidityPeriod());
if (src.isDatagramMode()) {
dest.setDatagramMode();
}
if (src.isDefaultMessageType()) {
dest.setDefaultMessageType();
}
if (src.isDefaultMode()) {
dest.setDefaultMode();
}
if (src.isEsmeDeliveryAcknowledgement()) {
dest.setEsmeDelivertAcknowledgement();
}
if (src.isEsmeManualAcknowledgement()) {
dest.setEsmeManualAcknowledgement();
}
if (src.isForwardMode()) {
dest.setForwardMode();
}
if (src.isReplyPath()) {
dest.setReplyPath();
}
if (src.isSmscDelReceiptFailureRequested()) {
dest.setSmscDelReceiptFailureRequested();
}
if (src.isSmscDelReceiptNotRequested()) {
dest.setSmscDelReceiptNotRequested();
}
if (src.isSmscDelReceiptSuccessAndFailureRequested()) {
dest.setSmscDelReceiptSuccessAndFailureRequested();
}
if (src.isStoreAndForwardMode()) {
dest.setStoreAndForwardMode();
}
if (src.isUdhi()) {
dest.setUdhi();
}
if (src.isUdhiAndReplyPath()) {
dest.setUdhiAndReplyPath();
}
return dest;
}
Aggregations