use of com.cloudhopper.smpp.type.UnsucessfulSME in project smscgateway by RestComm.
the class TxSmppServerSbb method onSubmitMultiLocal.
private void onSubmitMultiLocal(final TxSmppServerSbbUsage anSbbUsage, final com.cloudhopper.smpp.pdu.SubmitMulti event, final ActivityContextInterface aci) {
SmppTransaction smppServerTransaction = (SmppTransaction) aci.getActivity();
Esme esme = smppServerTransaction.getEsme();
String esmeName = esme.getName();
if (this.logger.isFineEnabled()) {
this.logger.fine("\nReceived SUBMIT_MULTI = " + event + " from Esme name=" + esmeName);
}
List<Address> addrList = event.getDestAddresses();
int msgCnt = 0;
if (addrList != null)
msgCnt = addrList.size();
CheckMessageLimitResult cres = esme.onMessageReceived(msgCnt);
if (cres.getResult() != CheckMessageLimitResult.Result.ok) {
if (cres.getResult() == CheckMessageLimitResult.Result.firstFault) {
this.updateOverrateCounters(cres);
this.logger.info(cres.getMessage());
}
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, cres.getMessage(), true);
}
SubmitMultiResp response = event.createResponse();
response.setCommandStatus(SmppConstants.STATUS_THROTTLED);
String s = cres.getMessage();
if (s.length() > 255)
s = s.substring(0, 255);
Tlv tlv;
try {
tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
response.addOptionalParameter(tlv);
} catch (TlvConvertException e) {
anSbbUsage.incrementCounterErrorSubmitMultiSm(ONE);
this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
}
// Lets send the Response with error here
long timestampB = 0L;
try {
this.smppServerSessions.sendResponsePdu(esme, event, response);
timestampB = System.currentTimeMillis();
} catch (Exception e) {
anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
}
try {
TargetAddress ta = createDestTargetAddress(event.getDestAddress(), esme.getNetworkId());
Sms sms = this.createSmsEvent(event, esme, ta, persistence);
sms.setTimestampB(timestampB);
generateFailureDetailedCdr(sms, EventType.IN_SMPP_REJECT_CONG, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, SmppConstants.STATUS_THROTTLED, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
} catch (SmscProcessingException e1) {
}
return;
}
SubmitMultiParseResult parseResult;
Sms singleSms = null;
try {
parseResult = this.createSmsEventMulti(event, esme, persistence, esme.getNetworkId());
for (Sms sms : parseResult.getParsedMessages()) {
singleSms = sms;
this.processSms(sms, persistence, esme, null, null, event, IncomingMessageType.submit_multi, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, event.getSequenceNumber());
}
} catch (SmscProcessingException e1) {
anSbbUsage.incrementCounterErrorSubmitMultiSm(ONE);
SbbStatsUtils.handleProcessingException(e1, anSbbUsage);
if (!e1.isSkipErrorLogging()) {
if (e1.isIsWarning()) {
this.logger.warning(e1.getMessage());
} else {
this.logger.severe(e1.getMessage(), e1);
}
smscStatAggregator.updateMsgInFailedAll();
}
if (smscPropertiesManagement.isGenerateRejectionCdr() && !e1.isMessageRejectCdrCreated()) {
if (singleSms != null) {
generateCDR(singleSms, CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), false, true);
} else {
generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
}
}
SubmitMultiResp response = event.createResponse();
response.setCommandStatus(e1.getSmppErrorCode());
String s = e1.getMessage();
if (s != null) {
if (s.length() > 255)
s = s.substring(0, 255);
Tlv tlv;
try {
tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
response.addOptionalParameter(tlv);
} catch (TlvConvertException e) {
this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
}
}
// Lets send the Response with error here
long timestampB = 0L;
try {
this.smppServerSessions.sendResponsePdu(esme, event, response);
timestampB = System.currentTimeMillis();
} catch (Exception e) {
anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
}
EventType eventType = null;
if (e1.getInternalErrorCode() == SmscProcessingException.INTERNAL_ERROR_STATE_OVERLOADED) {
eventType = EventType.IN_SMPP_REJECT_CONG;
} else {
eventType = EventType.IN_SMPP_REJECT_FORBIDDEN;
}
if (singleSms != null) {
singleSms.setTimestampB(timestampB);
generateRejectDetailedCdr(e1.getInternalErrorCode(), singleSms, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, e1.getSmppErrorCode(), esme.getRemoteAddressAndPort(), event.getSequenceNumber());
} else {
generateRejectDetailedCdr(e1.getInternalErrorCode(), event, esme, eventType, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, e1.getSmppErrorCode(), parseShortMessageText(event), timestampB);
}
return;
} catch (Throwable e1) {
anSbbUsage.incrementCounterErrorSubmitMultiSm(ONE);
String s = "Exception when processing SubmitMulti message: " + e1.getMessage();
this.logger.severe(s, e1);
smscStatAggregator.updateMsgInFailedAll();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(parseShortMessageText(event), esme.getNetworkId(), esme.getSystemId(), event.getSourceAddress().getAddress(), event.getSourceAddress().getTon(), event.getSourceAddress().getNpi(), event.getDestAddress().getAddress(), event.getDestAddress().getTon(), event.getDestAddress().getNpi(), CdrGenerator.CDR_SUBMIT_FAILED_ESME, e1.getMessage(), true);
}
SubmitMultiResp response = event.createResponse();
response.setCommandStatus(SmppConstants.STATUS_SYSERR);
if (s.length() > 255)
s = s.substring(0, 255);
Tlv tlv;
try {
tlv = TlvUtil.createNullTerminatedStringTlv(SmppConstants.TAG_ADD_STATUS_INFO, s);
response.addOptionalParameter(tlv);
} catch (TlvConvertException e) {
this.logger.severe("TlvConvertException while storing TAG_ADD_STATUS_INFO Tlv parameter", e);
}
// Lets send the Response with error here
try {
this.smppServerSessions.sendResponsePdu(esme, event, response);
if (singleSms != null) {
singleSms.setTimestampB(System.currentTimeMillis());
generateFailureDetailedCdr(singleSms, EventType.IN_SMPP_ERROR, ErrorCode.REJECT_INCOMING, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, SmppConstants.STATUS_SYSERR, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
}
anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
} catch (Exception e) {
this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
}
return;
}
SubmitMultiResp response = event.createResponse();
Sms sms = null;
if (parseResult.getParsedMessages().size() > 0)
sms = parseResult.getParsedMessages().get(0);
if (sms != null)
response.setMessageId(sms.getMessageIdText());
for (UnsucessfulSME usme : parseResult.getBadAddresses()) {
try {
response.addUnsucessfulSME(usme);
} catch (SmppInvalidArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Lets send the Response with success here
try {
if (sms == null || sms.getMessageDeliveryResultResponse() == null) {
this.smppServerSessions.sendResponsePdu(esme, event, response);
sms.setTimestampB(System.currentTimeMillis());
generateDetailedCDR(sms, EventType.IN_SMPP_RECEIVED, CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITMULTI, SmppConstants.STATUS_OK, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
}
} catch (Throwable e) {
anSbbUsage.incrementCounterErrorSubmitMultiSmResponding(ONE);
this.logger.severe("Error while trying to send SubmitMultiResponse=" + response, e);
}
}
use of com.cloudhopper.smpp.type.UnsucessfulSME in project smscgateway by RestComm.
the class TxSmppServerSbb method createSmsEventMulti.
protected SubmitMultiParseResult createSmsEventMulti(SubmitMulti event, Esme origEsme, PersistenceRAInterface store, int networkId) throws SmscProcessingException {
List<Address> addrList = event.getDestAddresses();
if (addrList == null || addrList.size() == 0) {
throw new SmscProcessingException("For received SubmitMulti no DestAddresses found: ", SmppConstants.STATUS_INVDLNAME, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_DST_ADDR_INVALID);
}
if (event.getSourceAddress() == null || event.getSourceAddress().getAddress() == null || event.getSourceAddress().getAddress().isEmpty()) {
throw new SmscProcessingException("SourceAddress digits are absent", SmppConstants.STATUS_INVSRCADR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_SRC_ADDR_INVALID);
}
// checking parameters first
String sourceAddr = event.getSourceAddress().getAddress();
int sourceAddrTon = event.getSourceAddress().getTon();
int sourceAddrNpi = event.getSourceAddress().getNpi();
int dcs = event.getDataCoding();
String err = MessageUtil.checkDataCodingSchemeSupport(dcs);
if (err != null) {
throw new SmscProcessingException("TxSmpp DataCoding scheme does not supported: " + dcs + " - " + err, SmppExtraConstants.ESME_RINVDCS, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_DATA_CODING_INVALID);
}
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
boolean udhPresent = (event.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0;
Tlv sarMsgRefNum = event.getOptionalParameter(SmppConstants.TAG_SAR_MSG_REF_NUM);
Tlv sarTotalSegments = event.getOptionalParameter(SmppConstants.TAG_SAR_TOTAL_SEGMENTS);
Tlv sarSegmentSeqnum = event.getOptionalParameter(SmppConstants.TAG_SAR_SEGMENT_SEQNUM);
boolean segmentTlvFlag = (sarMsgRefNum != null && sarTotalSegments != null && sarSegmentSeqnum != null);
// short message data
byte[] data = event.getShortMessage();
if (event.getShortMessageLength() == 0) {
// Probably the message_payload Optional Parameter is being used
Tlv messagePaylod = event.getOptionalParameter(SmppConstants.TAG_MESSAGE_PAYLOAD);
if (messagePaylod != null) {
data = messagePaylod.getValue();
}
}
if (data == null) {
data = new byte[0];
}
byte[] udhData;
byte[] textPart;
String msg;
udhData = null;
textPart = data;
if (udhPresent && data.length > 2) {
// UDH exists
int udhLen = (textPart[0] & 0xFF) + 1;
if (udhLen <= textPart.length) {
textPart = new byte[textPart.length - udhLen];
udhData = new byte[udhLen];
System.arraycopy(data, udhLen, textPart, 0, textPart.length);
System.arraycopy(data, 0, udhData, 0, udhLen);
}
}
msg = parseShortMessageText(event);
// checking max message length
int nationalLanguageLockingShift = 0;
int nationalLanguageSingleShift = 0;
if (udhPresent || segmentTlvFlag) {
// here splitting by SMSC is not supported
UserDataHeader udh = null;
int lenSolid = MessageUtil.getMaxSolidMessageBytesLength();
if (udhPresent)
udh = new UserDataHeaderImpl(udhData);
else {
udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
if (udh != null && udh.getNationalLanguageLockingShift() != null) {
lenSolid -= 3;
nationalLanguageLockingShift = udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode();
}
if (udh != null && udh.getNationalLanguageSingleShift() != null) {
lenSolid -= 3;
nationalLanguageSingleShift = udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode();
}
}
int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
if (udhData != null)
messageLen += udhData.length;
if (messageLen > lenSolid) {
throw new SmscProcessingException("Message length in bytes is too big for solid message: " + messageLen + ">" + lenSolid, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
}
} else {
// here splitting by SMSC is supported
int lenSegmented = MessageUtil.getMaxSegmentedMessageBytesLength();
if (msg.length() * 2 > (lenSegmented - 6) * 255) {
// firstly draft length check
UserDataHeader udh = createNationalLanguageUdh(origEsme, dataCodingScheme);
int messageLen = MessageUtil.getMessageLengthInBytes(dataCodingScheme, msg, udh);
if (udh != null && udh.getNationalLanguageLockingShift() != null) {
lenSegmented -= 3;
nationalLanguageLockingShift = udh.getNationalLanguageLockingShift().getNationalLanguageIdentifier().getCode();
}
if (udh != null && udh.getNationalLanguageSingleShift() != null) {
lenSegmented -= 3;
nationalLanguageSingleShift = udh.getNationalLanguageSingleShift().getNationalLanguageIdentifier().getCode();
}
if (messageLen > lenSegmented * 255) {
throw new SmscProcessingException("Message length in bytes is too big for segmented message: " + messageLen + ">" + lenSegmented, SmppConstants.STATUS_INVPARLEN, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, SmscProcessingException.INTERNAL_ERROR_MISC_MSG_TOO_LONG);
}
}
}
// ValidityPeriod processing
Tlv tlvQosTimeToLive = event.getOptionalParameter(SmppConstants.TAG_QOS_TIME_TO_LIVE);
Date validityPeriod;
if (tlvQosTimeToLive != null) {
long valTime;
try {
valTime = (new Date()).getTime() + tlvQosTimeToLive.getValueAsInt();
} catch (TlvConvertException e) {
throw new SmscProcessingException("TlvConvertException when getting TAG_QOS_TIME_TO_LIVE tlv field: " + e.getMessage(), SmppConstants.STATUS_INVOPTPARAMVAL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
}
validityPeriod = new Date(valTime);
} else {
try {
validityPeriod = MessageUtil.parseSmppDate(event.getValidityPeriod());
} catch (ParseException e) {
throw new SmscProcessingException("ParseException when parsing ValidityPeriod field: " + e.getMessage(), SmppConstants.STATUS_INVEXPIRY, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_VALIDITY_PERIOD_PARSING);
}
}
// ScheduleDeliveryTime processing
Date scheduleDeliveryTime;
try {
scheduleDeliveryTime = MessageUtil.parseSmppDate(event.getScheduleDeliveryTime());
} catch (ParseException e) {
throw new SmscProcessingException("ParseException when parsing ScheduleDeliveryTime field: " + e.getMessage(), SmppConstants.STATUS_INVSCHED, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e, SmscProcessingException.INTERNAL_ERROR_MISC_SCHEDULER_DELIVERY_TIME_PARSING);
}
long messageId = store.c2_getNextMessageId();
SmscStatProvider.getInstance().setCurrentMessageId(messageId);
ArrayList<Sms> msgList = new ArrayList<Sms>(addrList.size());
ArrayList<UnsucessfulSME> badAddresses = new ArrayList<UnsucessfulSME>(addrList.size());
for (Address address : addrList) {
boolean succAddr = false;
TargetAddress ta = null;
try {
ta = createDestTargetAddress(address, networkId);
succAddr = true;
} catch (SmscProcessingException e) {
Address addr = (Address) e.getExtraErrorData();
if (addr != null) {
UnsucessfulSME asme = new UnsucessfulSME(e.getSmppErrorCode(), addr);
badAddresses.add(asme);
}
}
if (succAddr) {
Sms sms = new Sms();
sms.setDbId(UUID.randomUUID());
sms.setOriginationType(OriginationType.SMPP);
sms.setSourceAddr(sourceAddr);
sms.setSourceAddrTon(sourceAddrTon);
sms.setSourceAddrNpi(sourceAddrNpi);
sms.setOrigNetworkId(networkId);
sms.setDataCoding(dcs);
sms.setNationalLanguageLockingShift(nationalLanguageLockingShift);
sms.setNationalLanguageSingleShift(nationalLanguageSingleShift);
sms.setOrigSystemId(origEsme.getSystemId());
sms.setOrigEsmeName(origEsme.getName());
sms.setSubmitDate(new Timestamp(System.currentTimeMillis()));
sms.setServiceType(event.getServiceType());
sms.setEsmClass(event.getEsmClass());
sms.setProtocolId(event.getProtocolId());
sms.setPriority(event.getPriority());
sms.setRegisteredDelivery(event.getRegisteredDelivery());
sms.setReplaceIfPresent(event.getReplaceIfPresent());
sms.setDefaultMsgId(event.getDefaultMsgId());
sms.setShortMessageText(msg);
sms.setShortMessageBin(udhData);
MessageUtil.applyValidityPeriod(sms, validityPeriod, true, smscPropertiesManagement.getMaxValidityPeriodHours(), smscPropertiesManagement.getDefaultValidityPeriodHours());
MessageUtil.applyScheduleDeliveryTime(sms, scheduleDeliveryTime);
// storing additional parameters
ArrayList<Tlv> optionalParameters = event.getOptionalParameters();
if (optionalParameters != null && optionalParameters.size() > 0) {
for (Tlv tlv : optionalParameters) {
if (tlv.getTag() != SmppConstants.TAG_MESSAGE_PAYLOAD) {
sms.getTlvSet().addOptionalParameter(tlv);
}
}
}
SmsSet smsSet;
smsSet = new SmsSet();
smsSet.setDestAddr(ta.getAddr());
smsSet.setDestAddrNpi(ta.getAddrNpi());
smsSet.setDestAddrTon(ta.getAddrTon());
smsSet.setNetworkId(origEsme.getNetworkId());
smsSet.addSms(sms);
sms.setSmsSet(smsSet);
sms.setMessageId(messageId);
msgList.add(sms);
}
}
return new SubmitMultiParseResult(msgList, badAddresses);
}
Aggregations