Revision: 98314683dd9e
Author:   [email protected] <[email protected]>
Date:     Wed Aug 22 14:20:24 2012
Log: Issue 10: Every new request gets IllegalStateException when calling
EventsSerializeFactory.deserialize once previous request fails.
http://code.google.com/p/ussdgateway/source/detail?r=98314683dd9e

Modified:
/core/xml/src/main/java/org/mobicents/ussdgateway/EventsSerializeFactory.java

=======================================
--- /core/xml/src/main/java/org/mobicents/ussdgateway/EventsSerializeFactory.java Mon May 21 13:34:47 2012 +++ /core/xml/src/main/java/org/mobicents/ussdgateway/EventsSerializeFactory.java Wed Aug 22 14:20:24 2012
@@ -20,50 +20,55 @@

        private final XMLObjectWriter writer;
        private final ByteArrayOutputStream baos;
-
+
        private final XMLObjectReader reader;
-

        public EventsSerializeFactory() throws XMLStreamException {
                this.binding.setAlias(Dialog.class, "dialog");
                this.binding.setClassAttribute("type");
                this.baos = new ByteArrayOutputStream();
-
+
                this.writer = new XMLObjectWriter();
-
+
                this.reader = new XMLObjectReader();
        }
-
-       private void resetWriter() throws XMLStreamException{
+
+       private void resetWriter() throws XMLStreamException {
                this.writer.reset();
                this.baos.reset();
-               this.writer.setBinding(binding);
-               this.writer.setIndentation("\t");
+               this.writer.setBinding(binding);
+               this.writer.setIndentation("\t");
                this.writer.setOutput(this.baos);
        }

        public byte[] serialize(Dialog dialog) throws XMLStreamException {
                this.resetWriter();
-
+
                this.writer.write(dialog, "dialog", Dialog.class);
                this.writer.flush();
                byte[] data = baos.toByteArray();
-
+
                return data;
        }
-
+
        public Dialog deserialize(byte[] data) throws XMLStreamException {
-               ByteArrayInputStream bais = new ByteArrayInputStream(data);
-               this.reader.setInput(bais);
-               Dialog dialog = this.reader.read("dialog", Dialog.class);
-               this.reader.reset();
-               return dialog;
+               try {
+                       ByteArrayInputStream bais = new 
ByteArrayInputStream(data);
+                       this.reader.setInput(bais);
+                       Dialog dialog = this.reader.read("dialog", 
Dialog.class);
+                       return dialog;
+               } finally {
+                       this.reader.reset();
+               }
        }
-
+
        public Dialog deserialize(InputStream is) throws XMLStreamException {
-               this.reader.setInput(is);
-               Dialog dialog = this.reader.read("dialog", Dialog.class);
-               this.reader.reset();
-               return dialog;
+               try {
+                       this.reader.setInput(is);
+                       Dialog dialog = this.reader.read("dialog", 
Dialog.class);
+                       return dialog;
+               } finally {
+                       this.reader.reset();
+               }
        }
 }

Reply via email to