Search in sources :

Example 21 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class TxHttpServerSbb method getMessageIdStatus.

private void getMessageIdStatus(HttpServletRequestEvent event, HttpGetMessageIdStatusIncomingData incomingData, ActivityContextInterface aci) throws HttpApiException {
    if (logger.isFineEnabled()) {
        logger.fine("Received getMessageIdStatus = " + incomingData);
    }
    final Long messageId = incomingData.getMsgId();
    QuerySmResponse querySmResponse = null;
    MessageState messageState = null;
    HttpGetMessageIdStatusOutgoingData outgoingData;
    try {
        final long msgId = messageId.longValue();
        querySmResponse = persistence.c2_getQuerySmResponse(msgId);
        if (querySmResponse == null) {
            throw new HttpApiException("Cannot retrieve QuerySmResponse from database. Returned object is null.");
        }
        messageState = querySmResponse.getMessageState();
        outgoingData = new HttpGetMessageIdStatusOutgoingData();
        outgoingData.setStatus(Status.SUCCESS);
        outgoingData.setStatusMessage(messageState.toString());
        HttpUtils.sendOkResponseWithContent(logger, event.getResponse(), ResponseFormatter.format(outgoingData, incomingData.getFormat()), incomingData.getFormat());
    } catch (PersistenceException e) {
        throw new HttpApiException("PersistenceException while obtaining message status from the database for the " + "message with id: " + incomingData.getMsgId());
    } catch (IOException e) {
        throw new HttpApiException("IOException while trying to send response ok message with content");
    }
}
Also used : HttpApiException(org.mobicents.smsc.slee.services.http.server.tx.exceptions.HttpApiException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) IOException(java.io.IOException)

Example 22 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method doGetCurDueSlot.

private synchronized long doGetCurDueSlot() throws PersistenceException {
    if (currentDueSlot != 0)
        return currentDueSlot;
    try {
        try {
            // checking of CURRENT_SLOT_TABLE existence
            String sa = "SELECT \"" + Schema.COLUMN_NEXT_SLOT + "\" FROM \"" + Schema.FAMILY_CURRENT_SLOT_TABLE + "\" where \"" + Schema.COLUMN_ID + "\"=0;";
            PreparedStatement ps = session.prepare(sa);
        } catch (InvalidQueryException e) {
            StringBuilder sb = new StringBuilder();
            sb.append("CREATE TABLE \"");
            sb.append(Schema.FAMILY_CURRENT_SLOT_TABLE);
            sb.append("\" (");
            appendField(sb, Schema.COLUMN_ID, "int");
            appendField(sb, Schema.COLUMN_NEXT_SLOT, "bigint");
            sb.append("PRIMARY KEY (\"");
            sb.append(Schema.COLUMN_ID);
            sb.append("\"");
            sb.append("));");
            String s2 = sb.toString();
            PreparedStatement ps = session.prepare(s2);
            BoundStatement boundStatement = new BoundStatement(ps);
            ResultSet res = session.execute(boundStatement);
        }
    } catch (Exception e1) {
        String msg = "Failed to access or create table " + Schema.FAMILY_CURRENT_SLOT_TABLE + "!";
        throw new PersistenceException(msg, e1);
    }
    nextDueSlotTime = (new Date()).getTime() + millisecInDueSlot;
    return currentDueSlot;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) Date(java.util.Date)

Example 23 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method createRecord.

// SCHEMA 1 ************************
public void createRecord(long dueSlot, Sms sms) throws PersistenceException {
    PreparedStatementCollection2 psc = getStatementCollection(sms.getSubmitDate());
    try {
        PreparedStatement ps = psc.createRecordData;
        BoundStatement boundStatement = new BoundStatement(ps);
        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());
        boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
        boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
        boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
        if (sms.getSourceAddr() != null) {
            boundStatement.setString(Schema.COLUMN_ADDR_SRC_DIGITS, sms.getSourceAddr());
        }
        boundStatement.setInt(Schema.COLUMN_ADDR_SRC_TON, sms.getSourceAddrTon());
        boundStatement.setInt(Schema.COLUMN_ADDR_SRC_NPI, sms.getSourceAddrNpi());
        boundStatement.setInt(Schema.COLUMN_DUE_DELAY, sms.getSmsSet().getDueDelay());
        if (sms.getSmsSet().getStatus() != null)
            boundStatement.setInt(Schema.COLUMN_SM_STATUS, sms.getSmsSet().getStatus().getCode());
        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());
        }
        if (sms.getOrigSystemId() != null) {
            boundStatement.setString(Schema.COLUMN_ORIG_SYSTEM_ID, sms.getOrigSystemId());
        }
        if (sms.getSubmitDate() != null) {
            DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_SUBMIT_DATE, sms.getSubmitDate());
        }
        if (sms.getServiceType() != null) {
            boundStatement.setString(Schema.COLUMN_SERVICE_TYPE, sms.getServiceType());
        }
        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.getDataCoding());
        boundStatement.setInt(Schema.COLUMN_DEFAULT_MSG_ID, sms.getDefaultMsgId());
        if (sms.getShortMessage() != null) {
            boundStatement.setBytes(Schema.COLUMN_MESSAGE, ByteBuffer.wrap(sms.getShortMessage()));
        }
        if (sms.getScheduleDeliveryTime() != null) {
            DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_SCHEDULE_DELIVERY_TIME, sms.getScheduleDeliveryTime());
        }
        if (sms.getValidityPeriod() != null) {
            DBOperations.setBoundStatementDate(boundStatement, Schema.COLUMN_VALIDITY_PERIOD, sms.getValidityPeriod());
        }
        boundStatement.setInt(Schema.COLUMN_DELIVERY_COUNT, sms.getDeliveryCount());
        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);
            }
        }
        ResultSet res = session.execute(boundStatement);
        ps = psc.createRecordSlots;
        boundStatement = new BoundStatement(ps);
        boundStatement.setLong(Schema.COLUMN_DUE_SLOT, dueSlot);
        boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
        res = session.execute(boundStatement);
        ps = psc.createRecordDests;
        boundStatement = new BoundStatement(ps);
        boundStatement.setString(Schema.COLUMN_TARGET_ID, sms.getSmsSet().getTargetId());
        boundStatement.setUUID(Schema.COLUMN_ID, sms.getDbId());
        boundStatement.setBool(Schema.COLUMN_SENT, false);
        res = session.execute(boundStatement);
    } catch (Exception e1) {
        String msg = "Failed createRecord !";
        throw new PersistenceException(msg, e1);
    }
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) XMLObjectWriter(javolution.xml.XMLObjectWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 24 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method doGetStatementCollection4.

private synchronized PreparedStatementCollection4 doGetStatementCollection4(String tName) throws PersistenceException {
    PreparedStatementCollection4 psc = dataTableRead4.get(tName);
    if (psc != null)
        return psc;
    try {
        try {
            // checking if a datatable exists
            String s1 = "SELECT * FROM \"" + Schema.FAMILY_DST_SLOT_TABLE + tName + "\";";
            PreparedStatement ps = session.prepare(s1);
        } catch (InvalidQueryException e) {
            // datatable does not exist
            // DST_SLOT_TABLE
            StringBuilder sb = new StringBuilder();
            sb.append("CREATE TABLE \"" + Schema.FAMILY_DST_SLOT_TABLE);
            sb.append(tName);
            sb.append("\" (");
            appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
            appendField(sb, Schema.COLUMN_DUE_SLOT, "bigint");
            sb.append("PRIMARY KEY (\"");
            sb.append(Schema.COLUMN_TARGET_ID);
            sb.append("\"");
            sb.append("));");
            String s2 = sb.toString();
            PreparedStatement ps = session.prepare(s2);
            BoundStatement boundStatement = new BoundStatement(ps);
            ResultSet res = session.execute(boundStatement);
        // // MESSAGES
        // sb = new StringBuilder();
        // sb.append("CREATE TABLE \"" + Schema.FAMILY_SLOTS);
        // sb.append(tName);
        // sb.append("\" (");
        // 
        // appendField(sb, Schema.COLUMN_DUE_SLOT, "bigint");
        // appendField(sb, Schema.COLUMN_TARGET_ID, "ascii");
        // 
        // // !!!!- temproary - delete it
        // appendField(sb, "PROCESSED", "boolean");
        // // !!!!- temproary - delete it
        // 
        // sb.append("PRIMARY KEY (\"");
        // sb.append(Schema.COLUMN_DUE_SLOT);
        // sb.append("\", \"");
        // sb.append(Schema.COLUMN_TARGET_ID);
        // sb.append("\"");
        // sb.append("));");
        // 
        // s2 = sb.toString();
        // ps = session.prepare(s2);
        // boundStatement = new BoundStatement(ps);
        // res = session.execute(boundStatement);
        }
    } catch (Exception e1) {
        String msg = "Failed to access or create table " + tName + "!";
        throw new PersistenceException(msg, e1);
    }
    psc = new PreparedStatementCollection4(tName);
    dataTableRead4.putEntry(tName, psc);
    return psc;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 25 with PersistenceException

use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.

the class NN_DBOper method getTargetIdListForDueSlot.

public List<NN_LoadedTargetId> getTargetIdListForDueSlot(Date[] dtt, long dueSlot, long newDueSlot, int maxRecordCount) throws PersistenceException {
    List<NN_LoadedTargetId> lst = new ArrayList<NN_LoadedTargetId>();
    for (Date dt : dtt) {
        PreparedStatementCollection2 psc = getStatementCollection(dt);
        try {
            // reading a set of TARGET_ID
            String sa = "SELECT \"" + Schema.COLUMN_TARGET_ID + "\" FROM \"" + Schema.FAMILY_SLOTS + psc.tName + "\" where \"" + Schema.COLUMN_DUE_SLOT + "\"=? limit " + maxRecordCount + " allow filtering;";
            PreparedStatement ps = session.prepare(sa);
            BoundStatement boundStatement = new BoundStatement(ps);
            boundStatement.bind(dueSlot);
            ResultSet res = session.execute(boundStatement);
            for (Row row : res) {
                String s = row.getString(0);
                lst.add(new NN_LoadedTargetId(s, dt, newDueSlot));
            }
        } catch (Exception e1) {
            String msg = "Failed reading a set of TARGET_ID from SLOTS for dueSlot " + dueSlot + " !";
            throw new PersistenceException(msg, e1);
        }
        // deleting TARGET_ID form SLOTS table and adding new one for later time
        String s1 = null;
        try {
            for (NN_LoadedTargetId ti : lst) {
                s1 = ti.getTargetId();
                PreparedStatement ps = psc.deleteRecordSlots;
                BoundStatement boundStatement = new BoundStatement(ps);
                boundStatement.bind(dueSlot, ti.getTargetId());
                ResultSet res = session.execute(boundStatement);
                ps = psc.createRecordSlots;
                boundStatement = new BoundStatement(ps);
                boundStatement.setLong(Schema.COLUMN_DUE_SLOT, newDueSlot);
                boundStatement.setString(Schema.COLUMN_TARGET_ID, ti.getTargetId());
                res = session.execute(boundStatement);
            }
        } catch (Exception e1) {
            logger.error("Failed removing a TARGET_ID from SLOTS " + s1 + " !", e1);
        }
        if (lst.size() > 0)
            break;
    }
    return lst;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(com.datastax.driver.core.ResultSet) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) BoundStatement(com.datastax.driver.core.BoundStatement) Date(java.util.Date) XMLStreamException(javolution.xml.stream.XMLStreamException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Aggregations

PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)28 BoundStatement (com.datastax.driver.core.BoundStatement)12 PreparedStatement (com.datastax.driver.core.PreparedStatement)12 ResultSet (com.datastax.driver.core.ResultSet)12 XMLStreamException (javolution.xml.stream.XMLStreamException)11 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)10 Sms (org.mobicents.smsc.library.Sms)9 Date (java.util.Date)6 SmsSet (org.mobicents.smsc.library.SmsSet)5 Row (com.datastax.driver.core.Row)4 CreateException (javax.slee.CreateException)4 EventType (org.mobicents.smsc.library.EventType)4 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)4 TargetAddress (org.mobicents.smsc.library.TargetAddress)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DbSmsRoutingRule (org.mobicents.smsc.library.DbSmsRoutingRule)3 MessageDeliveryResultResponseInterface (org.mobicents.smsc.library.MessageDeliveryResultResponseInterface)3 Esme (org.restcomm.smpp.Esme)3 EsmeManagement (org.restcomm.smpp.EsmeManagement)3