use of javolution.xml.XMLObjectReader 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);
}
use of javolution.xml.XMLObjectReader 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.XMLObjectReader 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.XMLObjectReader 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);
}
}
use of javolution.xml.XMLObjectReader in project smscgateway by RestComm.
the class HttpUsersManagement 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.httpUsers = reader.read(USER_LIST, FastList.class);
reader.close();
for (FastList.Node<HttpUser> n = httpUsers.head(), end = httpUsers.tail(); (n = n.getNext()) != end; ) {
HttpUser httpUser = n.getValue();
httpUser.httpUsersManagement = this;
}
} catch (XMLStreamException ex) {
// this.logger.info(
// "Error while re-creating Linksets from persisted file", ex);
}
}
Aggregations