use of org.mobicents.smsc.library.SmscProcessingException in project smscgateway by RestComm.
the class TxSipServerSbb method onMESSAGE.
// *********
// SIP Event Handlers
public void onMESSAGE(javax.sip.RequestEvent event, ActivityContextInterface aci) {
if (this.logger.isFineEnabled()) {
this.logger.fine("onMESSAGE " + event);
}
Sip sip = sipManagement.getSipByName(SipManagement.SIP_NAME);
try {
final Request request = event.getRequest();
byte[] message = request.getRawContent();
final ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME);
final String toUser = ((SipUri) toHeader.getAddress().getURI()).getUser();
final FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME);
final String fromUser = ((SipUri) fromHeader.getAddress().getURI()).getUser();
// Persist this message
TargetAddress ta = this.createDestTargetAddress(toUser, sip.getNetworkId());
byte[] udh = null;
Header udhHeader = request.getHeader(SipXHeaders.XSmsUdh);
if (udhHeader != null) {
udh = this.hexStringToByteArray(((SIPHeader) udhHeader).getValue());
}
Header codingHeader = request.getHeader(SipXHeaders.XSmsCoding);
DataCodingSchemeImpl codingSchme = dcsGsm7;
if (codingHeader != null) {
int dcs = Integer.parseInt(((SIPHeader) codingHeader).getValue());
codingSchme = this.createDataCodingScheme(dcs);
}
Date validityPeriod = null;
Header validityHeader = request.getHeader(SipXHeaders.XSmsValidty);
if (validityHeader != null) {
try {
validityPeriod = MessageUtil.parseDate(((SIPHeader) validityHeader).getValue());
} catch (ParseException e) {
logger.severe("ParseException when parsing ValidityPeriod field: " + e.getMessage(), e);
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e.getMessage(), true);
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e1) {
this.logger.severe("Exception while trying to send 500 response to sip", e1);
}
return;
}
}
// Registered Delivery
int regDeliveryInt = 0;
Header regDeliveryHeader = request.getHeader(SipXHeaders.XRegDelivery);
if (regDeliveryHeader != null) {
regDeliveryInt = Integer.parseInt(((SIPHeader) regDeliveryHeader).getValue());
}
Sms sms = null;
try {
sms = this.createSmsEvent(fromUser, message, ta, persistence, udh, codingSchme, validityPeriod, regDeliveryInt, sip.getNetworkId());
this.processSms(sms, persistence);
} catch (SmscProcessingException e1) {
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 (sms != null) {
generateCDR(sms, CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), false, true);
} else {
generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
}
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
res = (this.messageFactory.createResponse(500, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e) {
this.logger.severe("Exception while trying to send Ok response to sip", e);
}
return;
} catch (Throwable e1) {
this.logger.severe("Exception while processing a message from sip", e1);
smscStatAggregator.updateMsgInFailedAll();
if (smscPropertiesManagement.isGenerateRejectionCdr()) {
generateCDR(new String(message, utf8), sip.getNetworkId(), fromUser, toUser, ta.getNetworkId(), ta.getAddrTon(), ta.getAddrNpi(), CdrGenerator.CDR_SUBMIT_FAILED_SIP, e1.getMessage(), true);
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
// TODO: we possibly need to response ERROR message to sip
res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e) {
this.logger.severe("Exception while trying to send Ok response to sip", e);
}
return;
}
ServerTransaction serverTransaction = event.getServerTransaction();
Response res;
try {
res = (this.messageFactory.createResponse(200, serverTransaction.getRequest()));
event.getServerTransaction().sendResponse(res);
} catch (Exception e) {
this.logger.severe("Exception while trying to send Ok response to sip", e);
}
} catch (Exception e) {
this.logger.severe("Error while trying to process received the SMS " + event, e);
}
}
use of org.mobicents.smsc.library.SmscProcessingException in project smscgateway by RestComm.
the class ChargingSbb method rejectSmsByMproc.
private void rejectSmsByMproc(ChargingData chargingData, boolean isRejected) throws SmscProcessingException {
Sms sms = chargingData.getSms();
if (logger.isInfoEnabled()) {
logger.info("ChargingSbb: incoming message is " + (isRejected ? "rejected" : "dropped") + " by mProc rules, message=[" + sms + "]");
}
CdrGenerator.generateCdr(sms, (isRejected ? CdrGenerator.CDR_MPROC_REJECTED : CdrGenerator.CDR_MPROC_DROPPED), "Message is rejected by MProc rules.", smscPropertiesManagement.getGenerateReceiptCdr(), MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateCdr()), false, true, smscPropertiesManagement.getCalculateMsgPartsLenCdr(), smscPropertiesManagement.getDelayParametersInCdr());
try {
// sending of a failure response for transactional mode / delaying for charging result
MessageDeliveryResultResponseInterface.DeliveryFailureReason delReason = MessageDeliveryResultResponseInterface.DeliveryFailureReason.invalidDestinationAddress;
if (sms.getMessageDeliveryResultResponse() != null) {
if (isRejected) {
sms.getMessageDeliveryResultResponse().responseDeliveryFailure(delReason, null);
sms.setMessageDeliveryResultResponse(null);
} else {
sms.getMessageDeliveryResultResponse().responseDeliverySuccess();
sms.setMessageDeliveryResultResponse(null);
}
}
sms.getSmsSet().setStatus(ErrorCode.MPROC_ACCESS_NOT_GRANTED);
boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
if (storeAndForwMode) {
sms.setStored(true);
}
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// persistence.archiveFailuredSms(sms);
// } else {
String sourceAddrAndPort = null;
String messageType = null;
EventType eventType = null;
switch(sms.getOriginationType()) {
case SMPP:
EsmeManagement esmeManagement = EsmeManagement.getInstance();
Esme esme = esmeManagement.getEsmeByClusterName(sms.getSmsSet().getDestClusterName());
eventType = EventType.IN_SMPP_REJECT_MPROC;
if (esme != null) {
sourceAddrAndPort = esme.getRemoteAddressAndPort();
// shouldn't have null value
messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
}
break;
case HTTP:
messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
eventType = EventType.IN_HTTP_REJECT_MPROC;
break;
default:
break;
}
if (eventType != null) {
CdrDetailedGenerator.generateDetailedCdr(sms, eventType, sms.getSmsSet().getStatus(), messageType, 0, -1, sourceAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
}
if (MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateArchiveTable())) {
persistence.c2_createRecordArchive(sms, null, null, !smscPropertiesManagement.getReceiptsDisabling(), smscPropertiesManagement.getIncomeReceiptsProcessing());
}
// }
smscStatAggregator.updateMsgInRejectedAll();
CdrGenerator.generateCdr(sms, (isRejected ? CdrGenerator.CDR_MPROC_REJECTED : CdrGenerator.CDR_MPROC_DROPPED), CdrGenerator.CDR_SUCCESS_NO_REASON, smscPropertiesManagement.getGenerateReceiptCdr(), MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateCdr()), false, true, smscPropertiesManagement.getCalculateMsgPartsLenCdr(), smscPropertiesManagement.getDelayParametersInCdr());
} catch (PersistenceException e) {
throw new SmscProcessingException("PersistenceException when storing into Archive rejected by MProc message : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
}
}
use of org.mobicents.smsc.library.SmscProcessingException in project smscgateway by RestComm.
the class ChargingSbb method acceptSms.
private void acceptSms(ChargingData chargingData) throws SmscProcessingException {
Sms sms0 = chargingData.getSms();
if (logger.isInfoEnabled()) {
logger.info("ChargingSbb: accessGranted for: chargingType=" + chargingData.getChargingType() + ", message=[" + sms0 + "]");
}
try {
MProcResult mProcResult = MProcManagement.getInstance().applyMProcArrival(itsMProcRa, sms0, persistence);
FastList<Sms> smss = mProcResult.getMessageList();
if (smss != null) {
for (FastList.Node<Sms> n = smss.head(), end = smss.tail(); (n = n.getNext()) != end; ) {
Sms sms = n.getValue();
TargetAddress ta = new TargetAddress(sms.getSmsSet());
TargetAddress lock = persistence.obtainSynchroObject(ta);
sms.setTimestampC(System.currentTimeMillis());
try {
synchronized (lock) {
boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
if (!storeAndForwMode) {
try {
this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
} catch (Exception e) {
throw new SmscProcessingException("Exception when runnung injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
}
} else {
if (smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast) {
try {
sms.setStoringAfterFailure(true);
this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
} catch (Exception e) {
throw new SmscProcessingException("Exception when runnung injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
}
} else {
sms.setStored(true);
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// persistence.createLiveSms(sms);
// persistence.setNewMessageScheduled(sms.getSmsSet(),
// MessageUtil.computeDueDate(MessageUtil.computeFirstDueDelay(smscPropertiesManagement.getFirstDueDelay())));
// } else {
this.scheduler.setDestCluster(sms.getSmsSet());
persistence.c2_scheduleMessage_ReschedDueSlot(sms, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast, false);
// }
}
}
}
} finally {
persistence.releaseSynchroObject(lock);
}
}
}
if (mProcResult.isMessageRejected()) {
rejectSmsByMproc(chargingData, true);
return;
}
if (mProcResult.isMessageDropped()) {
rejectSmsByMproc(chargingData, false);
return;
}
// sending success response for charging result
if (sms0.getMessageDeliveryResultResponse() != null && sms0.getMessageDeliveryResultResponse().isOnlyChargingRequest()) {
sms0.getMessageDeliveryResultResponse().responseDeliverySuccess();
sms0.setTimestampB(System.currentTimeMillis());
EventType eventTypeSuccess = null;
String messageType = null;
String sourceAddr = null;
int seqNum = -1;
switch(sms0.getOriginationType()) {
case SMPP:
eventTypeSuccess = EventType.IN_SMPP_RECEIVED;
MessageDeliveryResultResponseInterface resp = sms0.getMessageDeliveryResultResponse();
messageType = resp.getMessageType();
seqNum = resp.getSeqNumber();
break;
case HTTP:
eventTypeSuccess = EventType.IN_HTTP_RECEIVED;
messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
break;
default:
break;
}
if (eventTypeSuccess != null) {
EsmeManagement esmeManagement = EsmeManagement.getInstance();
if (esmeManagement != null) {
// for testing there is no EsmeManagement
Esme esme = esmeManagement.getEsmeByClusterName(sms0.getOrigEsmeName());
// null check is for testing
if (esme != null) {
sourceAddr = esme.getRemoteAddressAndPort();
}
}
CdrDetailedGenerator.generateDetailedCdr(sms0, eventTypeSuccess, sms0.getSmsSet().getStatus(), messageType, SmppConstants.STATUS_OK, -1, sourceAddr, null, seqNum, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
}
sms0.setMessageDeliveryResultResponse(null);
}
smscStatAggregator.updateMsgInReceivedAll();
switch(sms0.getOriginationType()) {
case SMPP:
smscStatAggregator.updateMsgInReceivedSmpp();
break;
case SS7_MO:
smscStatAggregator.updateMsgInReceivedSs7();
smscStatAggregator.updateMsgInReceivedSs7Mo();
break;
case SS7_HR:
smscStatAggregator.updateMsgInReceivedSs7();
smscStatAggregator.updateMsgInReceivedSs7Hr();
break;
case SIP:
smscStatAggregator.updateMsgInReceivedSip();
break;
default:
break;
}
} catch (PersistenceException e) {
if (sms0 != null) {
generateCDR(sms0, CdrGenerator.CDR_SUBMIT_FAILED_CHARGING, e.getMessage(), false, true);
}
throw new SmscProcessingException("PersistenceException when storing LIVE_SMS : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
}
}
Aggregations