use of com.cloudhopper.smpp.pdu.SubmitMultiResp in project smscgateway by RestComm.
the class TxSmppServerSbbTest method testSubmitMulti.
@Test(groups = { "TxSmppServer" })
public void testSubmitMulti() throws Exception {
if (!this.cassandraDbInited)
return;
this.smppSess = new SmppSessionsProxy();
this.sbb.setSmppServerSessions(smppSess);
int windowSize = SmppConstants.DEFAULT_WINDOW_SIZE;
long connectTimeout = SmppConstants.DEFAULT_CONNECT_TIMEOUT;
long clientBindTimeout = SmppConstants.DEFAULT_BIND_TIMEOUT;
long requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
long windowMonitorInterval = SmppConstants.DEFAULT_WINDOW_MONITOR_INTERVAL;
long windowWaitTimeout = SmppConstants.DEFAULT_WINDOW_WAIT_TIMEOUT;
Esme esme = new Esme("Esme_1", "Esme_systemId_1", "pwd", "host", 0, false, null, SmppInterfaceVersionType.SMPP34, -1, -1, null, SmppBindType.TRANSCEIVER, SmppSession.Type.CLIENT, windowSize, connectTimeout, requestExpiryTimeout, clientBindTimeout, windowMonitorInterval, windowWaitTimeout, "Esme_1", true, 30000, 0, 0, -1, -1, "^[0-9a-zA-Z]*", -1, -1, "^[0-9a-zA-Z]*", 0, false, 0, 0, 0, 0, -1, -1, 0, -1, -1, -1, -1);
ActivityContextInterface aci = new SmppTransactionProxy(esme);
SubmitMulti event = new SubmitMulti();
Date curDate = new Date();
this.fillSm(event, curDate, true);
event.setShortMessage(msgUcs2);
Address destAddr = new Address();
destAddr.setAddress("5555");
destAddr.setTon(SmppConstants.TON_INTERNATIONAL);
destAddr.setNpi(SmppConstants.NPI_E164);
event.addDestAddresses(destAddr);
Address destAddr2 = new Address();
destAddr2.setAddress("5556");
destAddr2.setTon(SmppConstants.TON_INTERNATIONAL);
destAddr2.setNpi(SmppConstants.NPI_E164);
event.addDestAddresses(destAddr2);
long dueSlot = this.pers.c2_getDueSlotForTime(scheduleDeliveryTime);
PreparedStatementCollection psc = this.pers.getStatementCollection(scheduleDeliveryTime);
int b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
long b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
assertEquals(b1, 0);
assertEquals(b2, 0L);
b1 = this.pers.checkSmsExists(dueSlot, ta2.getTargetId());
b2 = this.pers.c2_getDueSlotForTargetId(psc, ta2.getTargetId());
assertEquals(b1, 0);
assertEquals(b2, 0L);
TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Unicode);
this.sbb.onSubmitMulti(event, aci);
b1 = this.pers.checkSmsExists(dueSlot, ta1.getTargetId());
assertEquals(b1, 1);
b1 = this.pers.checkSmsExists(dueSlot, ta2.getTargetId());
assertEquals(b1, 1);
SmsSet smsSet = this.pers.c2_getRecordListForTargeId(dueSlot, ta1.getTargetId());
this.checkSmsSet(smsSet, curDate, true);
Sms sms = smsSet.getSms(0);
// msgUcs2
assertEquals(sms.getShortMessageText(), sMsg);
assertEquals(sms.getShortMessageBin(), udhCode);
assertEquals(this.smppSess.getReqList().size(), 0);
assertEquals(this.smppSess.getRespList().size(), 1);
SubmitMultiResp resp = (SubmitMultiResp) this.smppSess.getRespList().get(0);
assertEquals(resp.getCommandStatus(), 0);
assertEquals(resp.getOptionalParameterCount(), 0);
assertEquals(resp.getUnsucessfulSmes().size(), 0);
}
use of com.cloudhopper.smpp.pdu.SubmitMultiResp 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);
}
}
Aggregations