Search in sources :

Example 1 with XMLObjectWriter

use of javolution.xml.XMLObjectWriter 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 XMLObjectWriter

use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.

the class SmsExtraDataTest method testXMLSerialize.

@Test(groups = { "SmsSet" })
public void testXMLSerialize() throws Exception {
    SmsExtraData original = new SmsExtraData();
    // Writes the area to a file.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLObjectWriter writer = XMLObjectWriter.newInstance(baos);
    writer.setIndentation("\t");
    writer.write(original, "smsExtraData", SmsExtraData.class);
    writer.close();
    byte[] rawData = baos.toByteArray();
    String serializedEvent = new String(rawData);
    System.out.println(serializedEvent);
    ByteArrayInputStream bais = new ByteArrayInputStream(rawData);
    XMLObjectReader reader = XMLObjectReader.newInstance(bais);
    SmsExtraData copy = reader.read("smsExtraData", SmsExtraData.class);
    assertNull(copy.getMprocNotes());
    assertNull(copy.getOriginationType());
    assertNull(copy.getReceiptLocalMessageId());
    original = new SmsExtraData();
    original.setMprocNotes("111 222");
    original.setOriginationType(OriginationType.SMPP);
    original.setReceiptLocalMessageId(34567L);
    // Writes the area to a file.
    baos = new ByteArrayOutputStream();
    writer = XMLObjectWriter.newInstance(baos);
    writer.setIndentation("\t");
    writer.write(original, "smsExtraData", SmsExtraData.class);
    writer.close();
    rawData = baos.toByteArray();
    serializedEvent = new String(rawData);
    System.out.println(serializedEvent);
    bais = new ByteArrayInputStream(rawData);
    reader = XMLObjectReader.newInstance(bais);
    copy = reader.read("smsExtraData", SmsExtraData.class);
    assertEquals(copy.getMprocNotes(), "111 222");
    assertEquals(copy.getOriginationType(), OriginationType.SMPP);
    assertEquals((long) copy.getReceiptLocalMessageId(), 34567L);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLObjectReader(javolution.xml.XMLObjectReader) XMLObjectWriter(javolution.xml.XMLObjectWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 3 with XMLObjectWriter

use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.

the class Sms method getExtraData.

public String getExtraData() {
    if (this.extraData.isEmpty()) {
        return null;
    } else {
        // serializing of extraData
        try {
            StringWriter sw = new StringWriter();
            XMLObjectWriter writer = XMLObjectWriter.newInstance(sw);
            writer.setIndentation("\t");
            writer.write(this.extraData, "extraData", SmsExtraData.class);
            writer.close();
            return sw.toString();
        } catch (XMLStreamException e) {
            return null;
        }
    }
}
Also used : StringWriter(java.io.StringWriter) XMLStreamException(javolution.xml.stream.XMLStreamException) XMLObjectWriter(javolution.xml.XMLObjectWriter)

Example 4 with XMLObjectWriter

use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.

the class MProcManagement method store.

public void store() {
    try {
        XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream(persistFile.toString()));
        writer.setBinding(binding);
        writer.setIndentation(TAB_INDENT);
        writer.write(mprocs, MPROC_LIST, FastList.class);
        writer.close();
    } catch (Exception e) {
        logger.error("Error while persisting the MProcRule state in file", e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) XMLObjectWriter(javolution.xml.XMLObjectWriter) XMLStreamException(javolution.xml.stream.XMLStreamException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) FileNotFoundException(java.io.FileNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 5 with XMLObjectWriter

use of javolution.xml.XMLObjectWriter in project smscgateway by RestComm.

the class SipManagement method store.

/**
 * Persist
 */
public void store() {
    // everytime?
    try {
        XMLObjectWriter writer = XMLObjectWriter.newInstance(new FileOutputStream(persistFile.toString()));
        writer.setBinding(binding);
        // Enables cross-references.
        // writer.setReferenceResolver(new XMLReferenceResolver());
        writer.setIndentation(TAB_INDENT);
        writer.write(sips, SIP_LIST, FastList.class);
        writer.close();
    } catch (Exception e) {
        logger.error("Error while persisting the Rule state in file", e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) XMLObjectWriter(javolution.xml.XMLObjectWriter) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) XMLStreamException(javolution.xml.stream.XMLStreamException) FileNotFoundException(java.io.FileNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException)

Aggregations

XMLObjectWriter (javolution.xml.XMLObjectWriter)12 XMLStreamException (javolution.xml.stream.XMLStreamException)10 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 MBeanRegistrationException (javax.management.MBeanRegistrationException)3 MalformedObjectNameException (javax.management.MalformedObjectNameException)3 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)3 BoundStatement (com.datastax.driver.core.BoundStatement)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 ResultSet (com.datastax.driver.core.ResultSet)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 XMLObjectReader (javolution.xml.XMLObjectReader)2 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)2 Test (org.testng.annotations.Test)2 StringWriter (java.io.StringWriter)1