use of javolution.xml.stream.XMLStreamException 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());
}
}
use of javolution.xml.stream.XMLStreamException in project smscgateway by RestComm.
the class Sms method setExtraData.
public void setExtraData(String extraData) {
if (extraData == null || extraData.length() == 0) {
this.extraData.clear();
} else {
// deserializing of extraData
try {
StringReader sr = new StringReader(extraData);
XMLObjectReader reader = XMLObjectReader.newInstance(sr);
SmsExtraData copy = reader.read("extraData", SmsExtraData.class);
if (copy != null) {
this.extraData = copy;
}
} catch (XMLStreamException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of javolution.xml.stream.XMLStreamException 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;
}
}
}
use of javolution.xml.stream.XMLStreamException in project smscgateway by RestComm.
the class SipManagement method load.
/**
* Load and create LinkSets and Link from persisted file
*
* @throws Exception
*/
public void load() throws FileNotFoundException {
XMLObjectReader reader = null;
try {
reader = XMLObjectReader.newInstance(new FileInputStream(persistFile.toString()));
reader.setBinding(binding);
this.sips = reader.read(SIP_LIST, FastList.class);
// Populate cluster
for (FastList.Node<Sip> n = this.sips.head(), end = this.sips.tail(); (n = n.getNext()) != end; ) {
Sip sip = n.getValue();
sip.sipManagement = this;
String sipClusterName = sip.getClusterName();
}
reader.close();
} catch (XMLStreamException ex) {
// this.logger.info(
// "Error while re-creating Linksets from persisted file", ex);
}
}
use of javolution.xml.stream.XMLStreamException in project smscgateway by RestComm.
the class HomeRoutingManagement method loadCorrId.
public synchronized void loadCorrId() {
XMLObjectReader reader = null;
try {
reader = XMLObjectReader.newInstance(new FileInputStream(persistFileCorrId.toString()));
try {
reader.setBinding(binding);
correlationId = reader.read(CC_CORR_ID, Long.class);
correlationId += CORR_ID_LAG;
loadedCorrelationId = -1;
logger.info("Successfully loaded home routing corrId: " + persistFile);
} finally {
reader.close();
}
} catch (FileNotFoundException ex) {
logger.warn("home routing corrId value: file not found: " + persistFile.toString());
logger.warn("CcMccmnsCollection: file not found: " + persistFile.toString());
try {
this.storeCorrId();
} catch (Exception e) {
}
} catch (XMLStreamException ex) {
logger.error("Error while loading home routing corrId value from file" + persistFile.toString(), ex);
}
}
Aggregations