<?xml version="1.0" encoding="UTF-8"?> is just an indication of which
version and encoding to be used.
Many applications omit this as well, and still this works.
Just to summarize what I understood from this thread
1. Need an XML Decoder/Encoder for a MINA based application :-)
2. Multiple XML documents can be received. The client code may be
multiplexing all messages to a server. Though this is a very typical
behavior indicating that Clients are asynchronous, they don't wait
for
a response, else wouldn't have sent the next xml
I believe the solution has been discussed. Look for Start tag and end
tag. I worked out a sample using CumulativeProtocolDecoder and it
seems to work fine for simple cases. Its really a bad piece of code
and won't like to scare away anyone :-)
These are the logical steps
1. Find the root element
2. Once found, keep looking till you get the end element, and return
false from doDecode()
if you don't receive it plan to throw away the message, as per some
strategy not known to me
3. Once you get the end element, write to the ProtocolDecoderOutput
and return true from doDecode(). Now you IoHandler shall see the
complete xml. Just get the bytes from IoBuffer and create a new
String. Use any XML parser either in IoHandler or in another filter.
4. Keep XML parsing in a filter if you can really ensure your
IoHandler can easily detect the incoming Object (Logic of which
object
to choose should be simple)
Done
Just to make life a little more complicated, here are the things I
got
stuck
1. Large packets get fragment. I used MINA's pom.xml and tested it,
got 4 read operations. Now the question is how should I detect and
reassemble out of order packets? I my code I simply appended to the
buffer for each read. MINA experts to guide on guide on this.
2. To create a generic XML Decoder, we need to have functionality as
per XML spec. for simple xml easy solution would do. My program
failed
coz, pom.xml had comment after <?xml version="1.0" encoding="UTF-8"?>
<!-- --> :-(
3. If have 2 xml messages in my decoder, how to pass one to handler
and keep other withing decoder till its get completed. Basically
generating 2 message received at IoHandler?
We could overcome problem 2 using some regular expression and
implementing basic XML parser functionality. Alternatively for a very
robust implementation we may use implementation similar to AsyncWeb's
DecodingState parsing of HTTP.
I have been blogging about MINA for a while. Trustin and Mike have
already been there. Not sure whether to share them here or not? The
post are the simple example programs that I worked out using MINA.
Forum admins can guide me on this.
thanks
ashish
On Wed, Oct 22, 2008 at 4:03 AM, Andres Martinez Quijano
<[EMAIL PROTECTED]> wrote:
so the <?xml version="1.0" encoding="UTF-8"?> tag uniquely describes
the begining of a new document
On Tue, Oct 21, 2008 at 6:37 PM, newToMina <[EMAIL PROTECTED]>
wrote:
The messages will of the following format.
<?xml version="1.0" encoding="UTF-8"?>
<Message>
<MessageType>XYZ</MessageType>
<MessageId>1212</StoreNum>
<DateTime>20070510132500</DateTime>
.
.
.
.
</Message>
The </Message> tag indicates the end of a document.
--
thanks
ashish
Blog: http://www.ashishpaliwal.com/blog
My Photo Galleries: http://www.pbase.com/ashishpaliwal