Search in sources :

Example 1 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class DBOperations method setSmsFields.

private void setSmsFields(Sms sms, long dueSlot, BoundStatement boundStatement, boolean archive, boolean shortMessageNewStringFormat, boolean addedCorrId, boolean addedNetworkId, boolean addedOrigNetworkId, boolean addedPacket1) throws PersistenceException {
    boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
    boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
    if (addedNetworkId) {
        boundStatement.setInt(Schema.COLUMN_NETWORK_ID, sms.getSmsSet().getNetworkId());
    }
    boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
    boundStatement.setInt(Schema.COLUMN_IN_SYSTEM, IN_SYSTEM_UNSENT);
    boundStatement.setUUID(Schema.COLUMN_SMSC_UUID, emptyUuid);
    boundStatement.setString(Schema.COLUMN_ADDR_DST_DIGITS, sms.getSmsSet().getDestAddr());
    boundStatement.setInt(Schema.COLUMN_ADDR_DST_TON, sms.getSmsSet().getDestAddrTon());
    boundStatement.setInt(Schema.COLUMN_ADDR_DST_NPI, sms.getSmsSet().getDestAddrNpi());
    if (sms.getSourceAddr() != null) {
        boundStatement.setString(Schema.COLUMN_ADDR_SRC_DIGITS, sms.getSourceAddr());
    } else {
        boundStatement.setToNull(Schema.COLUMN_ADDR_SRC_DIGITS);
    }
    boundStatement.setInt(Schema.COLUMN_ADDR_SRC_TON, sms.getSourceAddrTon());
    boundStatement.setInt(Schema.COLUMN_ADDR_SRC_NPI, sms.getSourceAddrNpi());
    if (addedOrigNetworkId) {
        boundStatement.setInt(Schema.COLUMN_ORIG_NETWORK_ID, sms.getOrigNetworkId());
    }
    boundStatement.setInt(Schema.COLUMN_DUE_DELAY, sms.getSmsSet().getDueDelay());
    if (sms.getSmsSet().getStatus() != null)
        boundStatement.setInt(Schema.COLUMN_SM_STATUS, sms.getSmsSet().getStatus().getCode());
    else
        boundStatement.setToNull(Schema.COLUMN_SM_STATUS);
    boundStatement.setBool(Schema.COLUMN_ALERTING_SUPPORTED, sms.getSmsSet().isAlertingSupported());
    boundStatement.setLong(Schema.COLUMN_MESSAGE_ID, sms.getMessageId());
    boundStatement.setInt(Schema.COLUMN_MO_MESSAGE_REF, sms.getMoMessageRef());
    if (sms.getOrigEsmeName() != null) {
        boundStatement.setString(Schema.COLUMN_ORIG_ESME_NAME, sms.getOrigEsmeName());
    } else
        boundStatement.setToNull(Schema.COLUMN_ORIG_ESME_NAME);
    if (sms.getOrigSystemId() != null) {
        boundStatement.setString(Schema.COLUMN_ORIG_SYSTEM_ID, sms.getOrigSystemId());
    } else
        boundStatement.setToNull(Schema.COLUMN_ORIG_SYSTEM_ID);
    if (sms.getSubmitDate() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_SUBMIT_DATE, sms.getSubmitDate());
    } else
        boundStatement.setToNull(Schema.COLUMN_SUBMIT_DATE);
    if (sms.getDeliverDate() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_DELIVERY_DATE, sms.getDeliverDate());
    } else
        boundStatement.setToNull(Schema.COLUMN_DELIVERY_DATE);
    if (sms.getServiceType() != null) {
        boundStatement.setString(Schema.COLUMN_SERVICE_TYPE, sms.getServiceType());
    } else
        boundStatement.setToNull(Schema.COLUMN_SERVICE_TYPE);
    boundStatement.setInt(Schema.COLUMN_ESM_CLASS, sms.getEsmClass());
    boundStatement.setInt(Schema.COLUMN_PROTOCOL_ID, sms.getProtocolId());
    boundStatement.setInt(Schema.COLUMN_PRIORITY, sms.getPriority());
    boundStatement.setInt(Schema.COLUMN_REGISTERED_DELIVERY, sms.getRegisteredDelivery());
    boundStatement.setInt(Schema.COLUMN_REPLACE, sms.getReplaceIfPresent());
    boundStatement.setInt(Schema.COLUMN_DATA_CODING, sms.getDataCodingForDatabase());
    boundStatement.setInt(Schema.COLUMN_DEFAULT_MSG_ID, sms.getDefaultMsgId());
    if (shortMessageNewStringFormat) {
        if (sms.getShortMessageText() != null) {
            boundStatement.setString(Schema.COLUMN_MESSAGE_TEXT, sms.getShortMessageText());
        } else
            boundStatement.setToNull(Schema.COLUMN_MESSAGE_TEXT);
        if (sms.getShortMessageBin() != null) {
            boundStatement.setBytes(Schema.COLUMN_MESSAGE_BIN, ByteBuffer.wrap(sms.getShortMessageBin()));
        } else
            boundStatement.setToNull(Schema.COLUMN_MESSAGE_BIN);
        boundStatement.setToNull(Schema.COLUMN_MESSAGE);
    } else {
        // convert to an old format
        String msg = sms.getShortMessageText();
        byte[] udhData = sms.getShortMessageBin();
        byte[] textPart = null;
        DataCodingScheme dcs = new DataCodingSchemeImpl(sms.getDataCoding());
        switch(dcs.getCharacterSet()) {
            case GSM7:
                textPart = msg.getBytes();
                break;
            case UCS2:
                Charset ucs2Charset = Charset.forName("UTF-16BE");
                ByteBuffer bb = ucs2Charset.encode(msg);
                textPart = new byte[bb.limit()];
                bb.get(textPart);
                break;
            default:
                // we do not support this yet
                break;
        }
        byte[] data;
        if (textPart != null) {
            if (udhData != null) {
                data = new byte[textPart.length + udhData.length];
                System.arraycopy(udhData, 0, data, 0, udhData.length);
                System.arraycopy(textPart, 0, data, udhData.length, textPart.length);
            } else {
                data = textPart;
            }
        } else {
            if (udhData != null) {
                data = udhData;
            } else {
                data = new byte[0];
            }
        }
        boundStatement.setBytes(Schema.COLUMN_MESSAGE, ByteBuffer.wrap(data));
    }
    if (sms.getScheduleDeliveryTime() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, sms.getScheduleDeliveryTime());
    } else
        boundStatement.setToNull(Schema.COLUMN_SCHEDULE_DELIVERY_TIME);
    if (sms.getValidityPeriod() != null) {
        setBoundStatementDate(boundStatement, Schema.COLUMN_VALIDITY_PERIOD, sms.getValidityPeriod());
    } else
        boundStatement.setToNull(Schema.COLUMN_VALIDITY_PERIOD);
    boundStatement.setInt(Schema.COLUMN_DELIVERY_COUNT, sms.getDeliveryCount());
    if (addedPacket1) {
        if (sms.getOriginatorSccpAddress() != null) {
            boundStatement.setString(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS, sms.getOriginatorSccpAddress());
        } else
            boundStatement.setToNull(Schema.COLUMN_ORIGINATOR_SCCP_ADDRESS);
        // TODO: extra columns for further usage
        boundStatement.setBool(Schema.COLUMN_STATUS_REPORT_REQUEST, sms.isStatusReportRequest());
        boundStatement.setInt(Schema.COLUMN_DELIVERY_ATTEMPT, sms.getDeliveryAttempt());
        if (sms.getUserData() != null) {
            boundStatement.setString(Schema.COLUMN_USER_DATA, sms.getUserData());
        } else
            boundStatement.setToNull(Schema.COLUMN_USER_DATA);
        String extraData = sms.getExtraData();
        if (extraData != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA, extraData);
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA);
        if (sms.getExtraData_2() != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA_2, sms.getExtraData_2());
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA_2);
        if (sms.getExtraData_3() != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA_3, sms.getExtraData_3());
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA_3);
        if (sms.getExtraData_4() != null) {
            boundStatement.setString(Schema.COLUMN_EXTRA_DATA_4, sms.getExtraData_4());
        } else
            boundStatement.setToNull(Schema.COLUMN_EXTRA_DATA_4);
    }
    if (sms.getTlvSet().getOptionalParameterCount() > 0) {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
            writer.setIndentation("\t");
            writer.write(sms.getTlvSet(), TLV_SET, TlvSet.class);
            writer.close();
            byte[] rawData = baos.toByteArray();
            String serializedEvent = new String(rawData);
            boundStatement.setString(Schema.COLUMN_OPTIONAL_PARAMETERS, serializedEvent);
        } catch (XMLStreamException e) {
            String msg = "XMLStreamException when serializing optional parameters for '" + sms.getDbId() + "'!";
            throw new PersistenceException(msg, e);
        }
    } else {
        boundStatement.setToNull(Schema.COLUMN_OPTIONAL_PARAMETERS);
    }
    if (!archive) {
        if (addedCorrId) {
            boundStatement.setToNull(Schema.COLUMN_CORR_ID);
        }
        boundStatement.setToNull(Schema.COLUMN_IMSI);
        if (sms.getSmsSet().getCorrelationId() != null) {
            if (addedCorrId) {
                boundStatement.setString(Schema.COLUMN_CORR_ID, sms.getSmsSet().getCorrelationId());
            } else {
                boundStatement.setString(Schema.COLUMN_IMSI, sms.getSmsSet().getCorrelationId());
            }
        }
    } else {
        if (sms.getSmsSet().getLocationInfoWithLMSI() != null && sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber() != null) {
            boundStatement.setString(Schema.COLUMN_NNN_DIGITS, sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddress());
            boundStatement.setInt(Schema.COLUMN_NNN_AN, sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getAddressNature().getIndicator());
            boundStatement.setInt(Schema.COLUMN_NNN_NP, sms.getSmsSet().getLocationInfoWithLMSI().getNetworkNodeNumber().getNumberingPlan().getIndicator());
        } else {
            boundStatement.setToNull(Schema.COLUMN_NNN_DIGITS);
            boundStatement.setToNull(Schema.COLUMN_NNN_AN);
            boundStatement.setToNull(Schema.COLUMN_NNN_NP);
        }
        if (sms.getSmsSet().getType() != null) {
            boundStatement.setInt(Schema.COLUMN_SM_TYPE, sms.getSmsSet().getType().getCode());
        } else {
            boundStatement.setToNull(Schema.COLUMN_SM_TYPE);
        }
        if (addedCorrId) {
            boundStatement.setString(Schema.COLUMN_CORR_ID, sms.getSmsSet().getCorrelationId());
        }
        boundStatement.setString(Schema.COLUMN_IMSI, sms.getSmsSet().getImsi());
    }
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) XMLStreamException(javolution.xml.stream.XMLStreamException) Charset(java.nio.charset.Charset) XMLObjectWriter(javolution.xml.XMLObjectWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer)

Example 2 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class A2Text method testA3.

@Test
public void testA3() throws Exception {
    DataCodingScheme dcs = new DataCodingSchemeImpl(0xF1);
    String msg = "Welcome to [thiopien\nPrices in EUR\n\nLocal calls from 2.19/min\nIncoming calls 1.29/min\nCalls home from 1.99/min\n\nSMS from 1.29\nData from 19.99/mb\n\n--Lufth";
    UserDataHeader udh = new UserDataHeaderImpl();
    ConcatenatedShortMessagesIdentifierImpl udhe = new ConcatenatedShortMessagesIdentifierImpl(false, 227, 2, 1);
    udh.addInformationElement(udhe);
    int messageLen = MessageUtil.getMessageLengthInBytes(dcs, msg, udh);
    int i1 = 0;
    i1++;
}
Also used : DataCodingScheme(org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme) ConcatenatedShortMessagesIdentifierImpl(org.mobicents.protocols.ss7.map.smstpdu.ConcatenatedShortMessagesIdentifierImpl) UserDataHeaderImpl(org.mobicents.protocols.ss7.map.smstpdu.UserDataHeaderImpl) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) UserDataHeader(org.mobicents.protocols.ss7.map.api.smstpdu.UserDataHeader) Test(org.testng.annotations.Test)

Example 3 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class MtTest method Ucs2Test.

@Test(groups = { "Mt" })
public void Ucs2Test() throws Exception {
    String s1 = "пїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅ";
    Charset ucs2Charset = Charset.forName("UTF-16BE");
    Charset utf8 = Charset.forName("UTF-8");
    // ByteBuffer bb = ByteBuffer.wrap(textPart);
    // CharBuffer bf = ucs2Charset.decode(bb);
    // msg = bf.toString();
    ByteBuffer bb = utf8.encode(s1);
    byte[] buf = new byte[bb.limit()];
    bb.get(buf, 0, bb.limit());
    String s2 = new String(buf);
    int gg = 0;
    gg++;
// MtSbbProxy proxy = new MtSbbProxy(this.pers);
// Sms sms = new Sms();
// sms.setDataCoding(8);
// byte[] shortMessage = new byte[] { (byte) 0xd8, (byte) 0xb2, (byte) 0xd9, (byte) 0x85, (byte) 0xd8, (byte) 0xa7, (byte) 0xd9, (byte) 0x86, (byte) 0xdb,
// (byte) 0x8c, (byte) 0xda, (byte) 0xa9, (byte) 0xd9, (byte) 0x87, 0x20, (byte) 0xd8, (byte) 0xa8, (byte) 0xd8, (byte) 0xb1, (byte) 0xd8,
// (byte) 0xb1, (byte) 0xd8, (byte) 0xb3, (byte) 0xdb, (byte) 0x8c };
// boolean moreMessagesToSend = false;
// int messageReferenceNumber = 0;
// int messageSegmentCount = 0;
// int messageSegmentNumber = 0;
// DataCodingScheme dataCodingScheme = new DataCodingSchemeImpl(8);
// boolean udhExists = false;
// SmsSignalInfo si = proxy.createSignalInfo(sms, shortMessage, moreMessagesToSend, messageReferenceNumber, messageSegmentCount, messageSegmentNumber,
// dataCodingScheme, udhExists);
}
Also used : Charset(java.nio.charset.Charset) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 4 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class MtTest2 method Ucs2Test.

@Test(groups = { "Mt" })
public void Ucs2Test() throws Exception {
    // Long msgId = 15L;
    // String s1 = msgId.toString(10);
    // String sss2 = String.format("%010d", 15L);
    String s11 = "زمانیکه بررسی";
    Charset ucs2Charset = Charset.forName("UTF-16BE");
    Charset utf8 = Charset.forName("UTF-8");
    // ByteBuffer bb = ByteBuffer.wrap(textPart);
    // CharBuffer bf = ucs2Charset.decode(bb);
    // msg = bf.toString();
    ByteBuffer bb = utf8.encode(s11);
    byte[] buf = new byte[bb.limit()];
    bb.get(buf, 0, bb.limit());
    String s2 = new String(buf);
    UserDataImpl ud = new UserDataImpl(s2, new DataCodingSchemeImpl(8), null, null);
    AddressField originatingAddress = new AddressFieldImpl(TypeOfNumber.InternationalNumber, NumberingPlanIdentification.ISDNTelephoneNumberingPlan, "123456");
    ProtocolIdentifier pi = new ProtocolIdentifierImpl(0);
    AbsoluteTimeStamp serviceCentreTimeStamp = new AbsoluteTimeStampImpl(05, 3, 4, 5, 6, 7, 0);
    SmsDeliverTpduImpl smsDeliverTpduImpl = new SmsDeliverTpduImpl(false, false, false, true, originatingAddress, pi, serviceCentreTimeStamp, ud);
    SmsSignalInfoImpl SmsSignalInfoImpl = new SmsSignalInfoImpl(smsDeliverTpduImpl, null);
    int gg = 0;
    gg++;
}
Also used : AddressField(org.mobicents.protocols.ss7.map.api.smstpdu.AddressField) AbsoluteTimeStamp(org.mobicents.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp) AddressFieldImpl(org.mobicents.protocols.ss7.map.smstpdu.AddressFieldImpl) Charset(java.nio.charset.Charset) SmsSignalInfoImpl(org.mobicents.protocols.ss7.map.service.sms.SmsSignalInfoImpl) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ByteBuffer(java.nio.ByteBuffer) ProtocolIdentifierImpl(org.mobicents.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl) AbsoluteTimeStampImpl(org.mobicents.protocols.ss7.map.smstpdu.AbsoluteTimeStampImpl) UserDataImpl(org.mobicents.protocols.ss7.map.smstpdu.UserDataImpl) ProtocolIdentifier(org.mobicents.protocols.ss7.map.api.smstpdu.ProtocolIdentifier) SmsDeliverTpduImpl(org.mobicents.protocols.ss7.map.smstpdu.SmsDeliverTpduImpl) Test(org.testng.annotations.Test)

Example 5 with DataCodingSchemeImpl

use of org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl in project smscgateway by RestComm.

the class MtTest2 method Ucs2Test3.

@Test(groups = { "Mt" })
public void Ucs2Test3() throws Exception {
    String s11 = "ura nus";
    byte[] buf = s11.getBytes();
    UserDataImpl ud = new UserDataImpl(s11, new DataCodingSchemeImpl(16), null, null);
    AddressField originatingAddress = new AddressFieldImpl(TypeOfNumber.InternationalNumber, NumberingPlanIdentification.ISDNTelephoneNumberingPlan, "123456");
    ProtocolIdentifier pi = new ProtocolIdentifierImpl(0);
    AbsoluteTimeStamp serviceCentreTimeStamp = new AbsoluteTimeStampImpl(05, 3, 4, 5, 6, 7, 0);
    SmsDeliverTpduImpl smsDeliverTpduImpl = new SmsDeliverTpduImpl(false, false, false, true, originatingAddress, pi, serviceCentreTimeStamp, ud);
    SmsSignalInfoImpl SmsSignalInfoImpl = new SmsSignalInfoImpl(smsDeliverTpduImpl, null);
    int gg = 0;
    gg++;
}
Also used : AddressField(org.mobicents.protocols.ss7.map.api.smstpdu.AddressField) AbsoluteTimeStamp(org.mobicents.protocols.ss7.map.api.smstpdu.AbsoluteTimeStamp) AddressFieldImpl(org.mobicents.protocols.ss7.map.smstpdu.AddressFieldImpl) SmsSignalInfoImpl(org.mobicents.protocols.ss7.map.service.sms.SmsSignalInfoImpl) DataCodingSchemeImpl(org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl) ProtocolIdentifierImpl(org.mobicents.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl) AbsoluteTimeStampImpl(org.mobicents.protocols.ss7.map.smstpdu.AbsoluteTimeStampImpl) UserDataImpl(org.mobicents.protocols.ss7.map.smstpdu.UserDataImpl) ProtocolIdentifier(org.mobicents.protocols.ss7.map.api.smstpdu.ProtocolIdentifier) SmsDeliverTpduImpl(org.mobicents.protocols.ss7.map.smstpdu.SmsDeliverTpduImpl) Test(org.testng.annotations.Test)

Aggregations

DataCodingSchemeImpl (org.mobicents.protocols.ss7.map.smstpdu.DataCodingSchemeImpl)24 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)18 Test (org.testng.annotations.Test)14 Date (java.util.Date)11 Sms (org.mobicents.smsc.library.Sms)11 AddressString (org.mobicents.protocols.ss7.map.api.primitives.AddressString)9 ISDNAddressString (org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString)9 UserDataHeader (org.mobicents.protocols.ss7.map.api.smstpdu.UserDataHeader)9 ByteBuffer (java.nio.ByteBuffer)8 SmsSet (org.mobicents.smsc.library.SmsSet)8 SM_RP_DA (org.mobicents.protocols.ss7.map.api.service.sms.SM_RP_DA)7 SmsSignalInfo (org.mobicents.protocols.ss7.map.api.service.sms.SmsSignalInfo)7 AddressField (org.mobicents.protocols.ss7.map.api.smstpdu.AddressField)7 ProtocolIdentifier (org.mobicents.protocols.ss7.map.api.smstpdu.ProtocolIdentifier)7 UserData (org.mobicents.protocols.ss7.map.api.smstpdu.UserData)7 ISDNAddressStringImpl (org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl)7 SmsSignalInfoImpl (org.mobicents.protocols.ss7.map.service.sms.SmsSignalInfoImpl)7 AddressFieldImpl (org.mobicents.protocols.ss7.map.smstpdu.AddressFieldImpl)7 ProtocolIdentifierImpl (org.mobicents.protocols.ss7.map.smstpdu.ProtocolIdentifierImpl)7 UserDataImpl (org.mobicents.protocols.ss7.map.smstpdu.UserDataImpl)7