use of org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class DBOperations method createSms.
protected SmsSet createSms(final Row row, SmsSet smsSet, boolean shortMessageNewStringFormat, boolean addedCorrId, boolean addedNetworkId, boolean addedOrigNetworkId, boolean addedPacket1, boolean getMessageInProcessing) throws PersistenceException {
if (row == null) {
return smsSet;
}
int inSystem = row.getInt(Schema.COLUMN_IN_SYSTEM);
UUID smscUuid = row.getUUID(Schema.COLUMN_SMSC_UUID);
if (!getMessageInProcessing && (inSystem == IN_SYSTEM_SENT || inSystem == IN_SYSTEM_INPROCESS && smscUuid.equals(currentSessionUUID))) {
// inSystem it is in processing or processed - skip this
return smsSet;
}
Sms sms = new Sms();
sms.setStored(true);
sms.setDbId(row.getUUID(Schema.COLUMN_ID));
sms.setDueSlot(row.getLong(Schema.COLUMN_DUE_SLOT));
sms.setSourceAddr(row.getString(Schema.COLUMN_ADDR_SRC_DIGITS));
sms.setSourceAddrTon(row.getInt(Schema.COLUMN_ADDR_SRC_TON));
sms.setSourceAddrNpi(row.getInt(Schema.COLUMN_ADDR_SRC_NPI));
if (addedOrigNetworkId) {
sms.setOrigNetworkId(row.getInt(Schema.COLUMN_ORIG_NETWORK_ID));
}
sms.setMessageId(row.getLong(Schema.COLUMN_MESSAGE_ID));
sms.setMoMessageRef(row.getInt(Schema.COLUMN_MO_MESSAGE_REF));
sms.setOrigEsmeName(row.getString(Schema.COLUMN_ORIG_ESME_NAME));
sms.setOrigSystemId(row.getString(Schema.COLUMN_ORIG_SYSTEM_ID));
sms.setSubmitDate(getRowDate(row, Schema.COLUMN_SUBMIT_DATE));
sms.setServiceType(row.getString(Schema.COLUMN_SERVICE_TYPE));
sms.setEsmClass(row.getInt(Schema.COLUMN_ESM_CLASS));
sms.setProtocolId(row.getInt(Schema.COLUMN_PROTOCOL_ID));
sms.setPriority(row.getInt(Schema.COLUMN_PRIORITY));
sms.setRegisteredDelivery(row.getInt(Schema.COLUMN_REGISTERED_DELIVERY));
sms.setReplaceIfPresent(row.getInt(Schema.COLUMN_REPLACE));
sms.setDataCodingForDatabase(row.getInt(Schema.COLUMN_DATA_CODING));
sms.setDefaultMsgId(row.getInt(Schema.COLUMN_DEFAULT_MSG_ID));
if (shortMessageNewStringFormat) {
sms.setShortMessageText(row.getString(Schema.COLUMN_MESSAGE_TEXT));
ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE_BIN);
if (bb != null) {
byte[] buf = new byte[bb.limit() - bb.position()];
bb.get(buf);
sms.setShortMessageBin(buf);
}
} else {
ByteBuffer bb = row.getBytes(Schema.COLUMN_MESSAGE);
if (bb != null) {
byte[] buf = new byte[bb.limit() - bb.position()];
bb.get(buf);
sms.setShortMessage(buf);
// convert to a new format
byte[] shortMessage = sms.getShortMessage();
byte[] textPart = shortMessage;
byte[] udhData = null;
boolean udhExists = false;
DataCodingScheme dcs = new DataCodingSchemeImpl(sms.getDataCoding());
String msg = null;
if (dcs.getCharacterSet() == CharacterSet.GSM8) {
udhData = shortMessage;
} else {
if ((sms.getEsmClass() & SmppConstants.ESM_CLASS_UDHI_MASK) != 0) {
udhExists = true;
}
if (udhExists && shortMessage != null && shortMessage.length > 2) {
// UDH exists
int udhLen = (shortMessage[0] & 0xFF) + 1;
if (udhLen <= shortMessage.length) {
textPart = new byte[shortMessage.length - udhLen];
udhData = new byte[udhLen];
System.arraycopy(shortMessage, udhLen, textPart, 0, textPart.length);
System.arraycopy(shortMessage, 0, udhData, 0, udhLen);
}
}
switch(dcs.getCharacterSet()) {
case GSM7:
msg = new String(textPart);
break;
case UCS2:
Charset ucs2Charset = Charset.forName("UTF-16BE");
bb = ByteBuffer.wrap(textPart);
CharBuffer bf = ucs2Charset.decode(bb);
msg = bf.toString();
break;
default:
udhData = sms.getShortMessage();
break;
}
}
sms.setShortMessageText(msg);
sms.setShortMessageBin(udhData);
}
}
sms.setScheduleDeliveryTime(getRowDate(row, Schema.COLUMN_SCHEDULE_DELIVERY_TIME));
sms.setValidityPeriod(getRowDate(row, Schema.COLUMN_VALIDITY_PERIOD));
sms.setDeliveryCount(row.getInt(Schema.COLUMN_DELIVERY_COUNT));
if (addedPacket1) {
sms.setOriginatorSccpAddress(row.getString(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS));
// TODO: extra columns for further usage
sms.setStatusReportRequest(row.getBool(Schema.COLUMN_STATUS_REPORT_REQUEST));
sms.setDeliveryAttempt(row.getInt(Schema.COLUMN_DELIVERY_ATTEMPT));
sms.setUserData(row.getString(Schema.COLUMN_USER_DATA));
sms.setExtraData(row.getString(Schema.COLUMN_EXTRA_DATA));
sms.setExtraData_2(row.getString(Schema.COLUMN_EXTRA_DATA_2));
sms.setExtraData_3(row.getString(Schema.COLUMN_EXTRA_DATA_3));
sms.setExtraData_4(row.getString(Schema.COLUMN_EXTRA_DATA_4));
}
String s = row.getString(Schema.COLUMN_OPTIONAL_PARAMETERS);
if (s != null) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(s.getBytes());
XMLObjectReader reader = XMLObjectReader.newInstance(bais);
TlvSet copy = reader.read(TLV_SET, TlvSet.class);
sms.getTlvSet().clearAllOptionalParameter();
sms.getTlvSet().addAllOptionalParameter(copy.getOptionalParameters());
} catch (XMLStreamException e) {
String msg = "XMLStreamException when deserializing optional parameters for '" + sms.getDbId() + "'!";
throw new PersistenceException(msg, e);
}
}
if (smsSet == null) {
smsSet = new SmsSet();
String destAddr = null;
int destAddrTon = -1;
int destAddrNpi = -1;
destAddr = row.getString(Schema.COLUMN_ADDR_DST_DIGITS);
destAddrTon = row.getInt(Schema.COLUMN_ADDR_DST_TON);
destAddrNpi = row.getInt(Schema.COLUMN_ADDR_DST_NPI);
if (destAddr == null || destAddrTon == -1 || destAddrNpi == -1) {
throw new PersistenceException("destAddr or destAddrTon or destAddrNpi is absent for ID='" + sms.getDbId() + "'");
}
smsSet.setDestAddr(destAddr);
smsSet.setDestAddrTon(destAddrTon);
smsSet.setDestAddrNpi(destAddrNpi);
if (getMessageInProcessing) {
smsSet.setInSystem(inSystem);
smsSet.setStatus(ErrorCode.fromInt(row.getInt(Schema.COLUMN_SM_STATUS)));
}
if (addedNetworkId) {
smsSet.setNetworkId(row.getInt(Schema.COLUMN_NETWORK_ID));
} else {
String tagId = row.getString(Schema.COLUMN_TARGET_ID);
if (tagId != null) {
String[] ss = tagId.split("_");
if (ss.length == 4) {
String s1 = ss[3];
try {
int networkId = Integer.parseInt(s1);
smsSet.setNetworkId(networkId);
} catch (Exception e) {
}
}
}
}
if (addedCorrId)
smsSet.setCorrelationId(row.getString(Schema.COLUMN_CORR_ID));
else
smsSet.setCorrelationId(row.getString(Schema.COLUMN_IMSI));
}
int dueDelay = row.getInt(Schema.COLUMN_DUE_DELAY);
if (dueDelay > smsSet.getDueDelay())
smsSet.setDueDelay(dueDelay);
boolean alertingSupported = row.getBool(Schema.COLUMN_ALERTING_SUPPORTED);
if (alertingSupported)
smsSet.setAlertingSupported(true);
smsSet.addSms(sms);
return smsSet;
}
use of org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class TxSmppServerSbbTest method testSubmitSm_BadCodingSchema.
// @Test(groups = { "TxSmppServer" })
// public void testSubmitMulti_BadAddr() 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 requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
// long clientBindTimeout = SmppConstants.DEFAULT_BIND_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, -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_SUBSCRIBER);
// 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, 0);
// b1 = this.pers.checkSmsExists(dueSlot, ta2.getTargetId());
// assertEquals(b1, 1);
//
// SubmitMultiResp resp = (SubmitMultiResp)this.smppSess.getRespList().get(0);
// assertEquals(resp.getCommandStatus(), 0);
// assertEquals(resp.getOptionalParameterCount(), 0);
// assertEquals(resp.getUnsucessfulSmes().size(), 1);
// assertEquals(resp.getUnsucessfulSmes().get(0).getAddress().getAddress(), "5555");
// }
@Test(groups = { "TxSmppServer" })
public void testSubmitSm_BadCodingSchema() 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 requestExpiryTimeout = SmppConstants.DEFAULT_REQUEST_EXPIRY_TIMEOUT;
long clientBindTimeout = SmppConstants.DEFAULT_BIND_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);
SubmitSm event = new SubmitSm();
Date curDate = new Date();
this.fillSm(event, curDate, true);
event.setShortMessage(msgUtf8);
DataCodingSchemeImpl dcss = new DataCodingSchemeImpl(DataCodingGroup.GeneralGroup, null, null, null, CharacterSet.GSM7, true);
// DataCodingGroup dataCodingGroup, DataCodingSchemaMessageClass
// messageClass,
// DataCodingSchemaIndicationType dataCodingSchemaIndicationType,
// Boolean setIndicationActive,
// CharacterSet characterSet, boolean isCompressed
event.setDataCoding((byte) 12);
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);
TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Utf8);
this.sbb.onSubmitSm(event, aci);
b2 = this.pers.c2_getDueSlotForTargetId(psc, ta1.getTargetId());
assertEquals(b2, 0);
assertEquals(this.smppSess.getReqList().size(), 0);
assertEquals(this.smppSess.getRespList().size(), 1);
PduResponse resp = this.smppSess.getRespList().get(0);
assertEquals(resp.getCommandStatus(), 260);
assertEquals(resp.getOptionalParameterCount(), 1);
Tlv tlvr = resp.getOptionalParameter(SmppConstants.TAG_ADD_STATUS_INFO);
String errMsg = tlvr.getValueAsString();
assertEquals(errMsg, "TxSmpp DataCoding scheme does not supported: 12 - Only GSM7, GSM8 and USC2 are supported");
}
use of org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class CdrGenerator method generateCdr.
public static void generateCdr(Sms smsEvent, String status, String reason, boolean generateReceiptCdr, boolean generateCdr, boolean messageIsSplitted, boolean lastSegment, boolean calculateMsgPartsLenCdr, boolean delayParametersInCdr, int seqNumber) {
if (!generateCdr)
return;
if (!generateReceiptCdr && smsEvent.isMcDeliveryReceipt())
// we do not generate CDR's for receipt if generateReceiptCdr option is off
return;
int msgParts = 0, charNumbers = 0;
if (calculateMsgPartsLenCdr) {
if (messageIsSplitted) {
msgParts = 1;
} else {
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(smsEvent.getDataCoding());
msgParts = MessageUtil.calculateMsgParts(smsEvent.getShortMessageText(), dataCodingScheme, smsEvent.getNationalLanguageLockingShift(), smsEvent.getNationalLanguageSingleShift());
}
if (lastSegment) {
charNumbers = smsEvent.getShortMessageText().length();
} else {
charNumbers = 0;
}
}
int dcs = smsEvent.getDataCoding();
Long receiptLocalMessageId = smsEvent.getReceiptLocalMessageId();
long msgPartDelTime = -1;
if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber - 1)) {
msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getMsgPartDelTime(seqNumber - 1);
} else if (smsEvent.getMsgPartsSeqNumbers().contains(seqNumber)) {
msgPartDelTime = smsEvent.getMsgPartDelTime(seqNumber) - smsEvent.getSubmitDate().getTime();
}
DeliveryReceiptData deliveryReceiptData = MessageUtil.parseDeliveryReceipt(smsEvent.getShortMessageText(), smsEvent.getTlvSet());
String st = null;
int tlvMessageState = -1;
int err = -1;
if (deliveryReceiptData != null) {
st = deliveryReceiptData.getStatus();
tlvMessageState = deliveryReceiptData.getTlvMessageState() == null ? -1 : deliveryReceiptData.getTlvMessageState();
err = deliveryReceiptData.getError();
}
StringBuffer sb = new StringBuffer();
sb.append(DATE_FORMAT.format(smsEvent.getSubmitDate())).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSourceAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddr()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrTon()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getDestAddrNpi()).append(CdrGenerator.CDR_SEPARATOR).append(status).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginationType()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getReceiptLocalMessageId() == null ? "message" : "dlr").append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigSystemId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getDlvMessageId()).append(CdrGenerator.CDR_SEPARATOR).append((receiptLocalMessageId != null && receiptLocalMessageId == -1) ? "xxxx" : smsEvent.getReceiptLocalMessageId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getLocationInfoWithLMSI() != null ? smsEvent.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddress() : null).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getImsi()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getCorrelationId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOriginatorSccpAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMtServiceCenterAddress()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getOrigNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getSmsSet().getNetworkId()).append(CdrGenerator.CDR_SEPARATOR).append(smsEvent.getMprocNotes()).append(CdrGenerator.CDR_SEPARATOR).append(msgParts).append(CdrGenerator.CDR_SEPARATOR).append(charNumbers).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getProcessingTime(smsEvent.getSubmitDate()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? getScheduleDeliveryDelayMilis(smsEvent.getSubmitDate(), smsEvent.getScheduleDeliveryTime()) : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(delayParametersInCdr ? smsEvent.getDeliveryCount() : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(msgPartDelTime != -1 ? msgPartDelTime : CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(dcs).append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(getFirst20CharOfSMS(smsEvent.getShortMessageText()))).append("\"").append(CdrGenerator.CDR_SEPARATOR).append("\"").append(getEscapedString(reason)).append("\"").append(CdrGenerator.CDR_SEPARATOR).append(st != null ? st : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(tlvMessageState != -1 ? tlvMessageState : CdrGenerator.CDR_EMPTY).append(CdrGenerator.CDR_SEPARATOR).append(err != -1 ? err : CdrGenerator.CDR_EMPTY);
CdrGenerator.generateCdr(sb.toString());
}
use of org.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl 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.restcomm.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.
the class SmppTestingForm method submitMessage.
private void submitMessage(EncodingType encodingType, int messageClass, String messageText, SplittingType splittingType, ValidityType validityType, String destAddr, SmppSimulatorParameters.MessagingMode messagingMode, int specifiedSegmentLength) {
if (session0 == null)
return;
try {
int dcs = 0;
ArrayList<byte[]> msgLst = new ArrayList<byte[]>();
int msgRef = 0;
switch(encodingType) {
case GSM7_DCS_0:
dcs = 0;
break;
case GSM8_DCS_4:
dcs = 4;
break;
case UCS2_DCS_8:
dcs = 8;
break;
}
// if (messageClass) {
// dcs += 16;
// }
int messageClassVal = 0;
if (messageClass > 0) {
messageClassVal = messageClass;
}
DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(dcs);
int maxLen = MessageUtil.getMaxSolidMessageCharsLength(dataCodingScheme);
int maxSplLen = MessageUtil.getMaxSegmentedMessageCharsLength(dataCodingScheme);
if (splittingType == SplittingType.SplitWithParameters_SpecifiedSegmentLength || splittingType == SplittingType.SplitWithUdh_SpecifiedSegmentLength) {
maxLen = specifiedSegmentLength;
maxSplLen = specifiedSegmentLength;
}
int segmCnt = 0;
int esmClass = 0;
boolean addSegmTlv = false;
if (messageText.length() > maxLen) {
// may be message splitting
SplittingType st = splittingType;
switch(st) {
case DoNotSplit:
// we do not split
byte[] buf1 = encodeSegment(messageText, encodingType);
byte[] buf2;
if (encodingType == EncodingType.GSM8_DCS_4) {
// 4-bytes length
byte[] bf3 = new byte[7];
// total UDH length
bf3[0] = 6;
// UDH id
bf3[1] = 5;
// UDH length
bf3[2] = 4;
bf3[3] = 0x3E;
bf3[4] = (byte) 0x94;
bf3[5] = 0;
bf3[6] = 0;
// 0-bytes length
// bf3 = new byte[3];
// bf3[0] = 2; // total UDH length
// bf3[1] = 112; // UDH id
// bf3[2] = 0; // UDH length
buf2 = new byte[bf3.length + buf1.length];
System.arraycopy(bf3, 0, buf2, 0, bf3.length);
System.arraycopy(buf1, 0, buf2, bf3.length, buf1.length);
esmClass = 0x40;
} else {
buf2 = buf1;
}
msgLst.add(buf2);
ArrayList<String> r1 = this.splitStr(messageText, maxSplLen);
segmCnt = r1.size();
break;
case SplitWithParameters_DefaultSegmentLength:
case SplitWithParameters_SpecifiedSegmentLength:
msgRef = getNextMsgRef();
r1 = this.splitStr(messageText, maxSplLen);
for (String bf : r1) {
msgLst.add(encodeSegment(bf, encodingType));
}
segmCnt = msgLst.size();
addSegmTlv = true;
break;
case SplitWithUdh_DefaultSegmentLength:
case SplitWithUdh_SpecifiedSegmentLength:
msgRef = getNextMsgRef();
r1 = this.splitStr(messageText, maxSplLen);
byte[] bf1 = new byte[6];
// total UDH length
bf1[0] = 5;
// UDH id
bf1[1] = 0;
// UDH length
bf1[2] = 3;
// refNum
bf1[3] = (byte) msgRef;
// segmCnt
bf1[4] = (byte) r1.size();
int i1 = 0;
for (String bfStr : r1) {
byte[] bf = encodeSegment(bfStr, encodingType);
i1++;
// segmNum
bf1[5] = (byte) i1;
byte[] bf2 = new byte[bf1.length + bf.length];
System.arraycopy(bf1, 0, bf2, 0, bf1.length);
System.arraycopy(bf, 0, bf2, bf1.length, bf.length);
msgLst.add(bf2);
}
segmCnt = msgLst.size();
esmClass = 0x40;
break;
}
} else {
byte[] buf = encodeSegment(messageText, encodingType);
if (encodingType == EncodingType.GSM8_DCS_4) {
byte[] bf1 = new byte[7];
// total UDH length
bf1[0] = 6;
// UDH id
bf1[1] = 5;
// UDH length
bf1[2] = 4;
bf1[3] = 0x3e;
bf1[4] = (byte) 0x94;
bf1[5] = 0;
bf1[6] = 0;
// 0-bytes length
// bf1 = new byte[3];
// bf1[0] = 2; // total UDH length
// bf1[1] = 112; // UDH id
// bf1[2] = 0; // UDH length
byte[] bf2 = new byte[bf1.length + buf.length];
System.arraycopy(bf1, 0, bf2, 0, bf1.length);
System.arraycopy(buf, 0, bf2, bf1.length, buf.length);
msgLst.add(bf2);
esmClass = 0x40;
} else {
msgLst.add(buf);
}
segmCnt = 1;
}
esmClass |= messagingMode.getCode();
this.doSubmitMessage(dcs, msgLst, msgRef, addSegmTlv, esmClass, validityType, segmCnt, destAddr, messageClassVal);
} catch (Exception e) {
this.addMessage("Failure to submit message", e.toString());
return;
}
}
Aggregations