Search in sources :

Example 1 with XMLObjectReader

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) XMLObjectReader(javolution.xml.XMLObjectReader) XMLObjectWriter(javolution.xml.XMLObjectWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Example 2 with XMLObjectReader

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();
        }
    }
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) StringReader(java.io.StringReader) XMLObjectReader(javolution.xml.XMLObjectReader)

Example 3 with XMLObjectReader

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);
    }
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) FastList(javolution.util.FastList) XMLObjectReader(javolution.xml.XMLObjectReader) FileInputStream(java.io.FileInputStream)

Example 4 with XMLObjectReader

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);
    }
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) FileNotFoundException(java.io.FileNotFoundException) XMLObjectReader(javolution.xml.XMLObjectReader) FileInputStream(java.io.FileInputStream) XMLStreamException(javolution.xml.stream.XMLStreamException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with XMLObjectReader

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);
    }
}
Also used : XMLStreamException(javolution.xml.stream.XMLStreamException) FastList(javolution.util.FastList) XMLObjectReader(javolution.xml.XMLObjectReader) FileInputStream(java.io.FileInputStream)

Aggregations

XMLObjectReader (javolution.xml.XMLObjectReader)11 XMLStreamException (javolution.xml.stream.XMLStreamException)9 FileInputStream (java.io.FileInputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 FastList (javolution.util.FastList)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 XMLObjectWriter (javolution.xml.XMLObjectWriter)2 Sms (org.mobicents.smsc.library.Sms)2 SmsSet (org.mobicents.smsc.library.SmsSet)2 TlvSet (org.restcomm.smpp.parameter.TlvSet)2 Test (org.testng.annotations.Test)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)1 StringReader (java.io.StringReader)1 CharBuffer (java.nio.CharBuffer)1 Charset (java.nio.charset.Charset)1 UUID (java.util.UUID)1 DataCodingScheme (org.mobicents.protocols.ss7.map.api.smstpdu.DataCodingScheme)1