You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by sy...@bnpparibas.com on 2006/01/06 13:22:36 UTC

[mina] sample with XML

Hi all

Is there any source code that implement XML parsing for Mina ?
my Aim is to implement an XML parsing (as a decoder) that transform XML in
object and send this objects to the handler.
Has anyone see some sample about that ?

regards


This message and any attachments (the "message") is
intended solely for the addressees and is confidential. 
If you receive this message in error, please delete it and 
immediately notify the sender. Any use not in accord with 
its purpose, any dissemination or disclosure, either whole 
or partial, is prohibited except formal approval. The internet
can not guarantee the integrity of this message. 
BNP PARIBAS (and its subsidiaries) shall (will) not 
therefore be liable for the message if modified. 

                ---------------------------------------------

Ce message et toutes les pieces jointes (ci-apres le 
"message") sont etablis a l'intention exclusive de ses 
destinataires et sont confidentiels. Si vous recevez ce 
message par erreur, merci de le detruire et d'en avertir 
immediatement l'expediteur. Toute utilisation de ce 
message non conforme a sa destination, toute diffusion 
ou toute publication, totale ou partielle, est interdite, sauf 
autorisation expresse. L'internet ne permettant pas 
d'assurer l'integrite de ce message, BNP PARIBAS (et ses
filiales) decline(nt) toute responsabilite au titre de ce 
message, dans l'hypothese ou il aurait ete modifie.


Re: [mina] sample with XML

Posted by Alex Cruise <al...@cluonflux.com>.
Justin Johnson wrote:

> 3. Insert length of XML packet information at the beginning for the 
> XML data.

You could always include your length info into the payload, and make 
implementors promise to put it in the first 1KB (for example) of the 
stream.  Something like this:

<metaFile len="12345" xmlns="urn:microsoft.com:graphics:wmf">
    <setAbort len="1">shpl0itz!</setAbort>
</metaFile>

Please remember that you can't fully trust this kind of number that 
comes in over the wire, and it makes no difference whether it's in- or 
out-of-band.  Luckily we have ArrayIndexOutOfBoundsException... :)

-0xe1a

Re: [mina] sample with XML

Posted by Justin Johnson <ju...@ntlworld.com>.
There are a couple of solutions to this:

1. Your XML is a single open stream.  That is, there's an open tag right 
at the start and an end tag and the end which signifies to close the 
connection.  The Jabber protocol works this way.   You have to adopt 
strict namespacing conventions and have to do some work with xml parsers.

2. Append each packet of XML data with a null terminator '/0'.  Flash 
XML handling works this way.

3. Insert length of XML packet information at the beginning for the XML 
data.

> Maarten Bosteels <m....@pandora.be> a écrit :
>
>> Hi,
>>
>> We use mina for transport and xmlbeans (http://xmlbeans.apache.org) 
>> to parse and generate xml documents.
>> Our ProtocolDecoder just reads an array of bytes
>> and the ProtocolHandler passes these bytes on to the xmlparser.
>>
>> The protocol (EPP) is pretty simple:
>> * 4 bytes indicating the total length of the message
>> * (length - 4) bytes of xml data
>>
>> Academic question:  If your protocol doesn't have a length header and 
>> you don't know the
>> byte encoding used by the incoming xml, how can you know when a 
>> message is complete ?
>
>
> Maarten,
>
> I use Mina (in Belgium too, for info) for a binary protocol, and we 
> add 4 bytes
> too. This makes our protocol more robust, and decoding easier.
>
> J-F
>
>> Maarten
>>
>> Chris Allen wrote:
>>
>>> Hi,
>>>
>>> I ended up using Jdom for paring the XML in my proxy server for Jabber
>>> using MINA.  It worked very well.  Basically you can create a
>>> ProtocolCodecFactory that uses a custom ProtocolDecoder.  The decoder
>>> will have to overwrite the decode() method where it will convert the
>>> ByteBuffer that it receives into an org.jdom.Document instance.  You
>>> can either do the parsing of the XML there or do it in your
>>> IoHandlerAdapter's messageReceived() method.
>>>
>>> There is a good example of using a ProtocolCodecFactory for converting
>>> the messages to Strings on the MINA website; it's basically the same
>>> thing, except you convert it into either a Jdom Document like I'm
>>> doing or one of the others that Vinod suggested.  Take a look at the
>>> package org.apache.mina.filter.codec.textline for an example:
>>> http://directory.apache.org/subprojects/network/xref/org/apache/mina/filter/codec/textline/package-summary.html 
>>>
>>>
>>> I hope that helps.
>>>
>>> -Chris
>>>
>>> On 1/6/06, Vinod Panicker <vi...@gmail.com> wrote:
>>>
>>>> On 1/6/06, sylvain.eche@bnpparibas.com 
>>>> <sy...@bnpparibas.com> wrote:
>>>>
>>>>> Hi all
>>>>>
>>>>> Is there any source code that implement XML parsing for Mina ?
>>>>> my Aim is to implement an XML parsing (as a decoder) that 
>>>>> transform XML in
>>>>> object and send this objects to the handler.
>>>>> Has anyone see some sample about that ?
>>>>>
>>>> Might sound silly, but have you considered using SAX / DOM / XPath for
>>>> your XML parsing?  That will give you ready made objects that you can
>>>> pass to your handler.
>>>>
>>>> Regards,
>>>> Vinod.
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>
>
>
>


Re: [mina] sample with XML

Posted by da...@daune-consult.com.
Maarten Bosteels <m....@pandora.be> a écrit :

> Hi,
>
> We use mina for transport and xmlbeans (http://xmlbeans.apache.org) 
> to parse and generate xml documents.
> Our ProtocolDecoder just reads an array of bytes
> and the ProtocolHandler passes these bytes on to the xmlparser.
>
> The protocol (EPP) is pretty simple:
> * 4 bytes indicating the total length of the message
> * (length - 4) bytes of xml data
>
> Academic question:  If your protocol doesn't have a length header and 
> you don't know the
> byte encoding used by the incoming xml, how can you know when a 
> message is complete ?

Maarten,

I use Mina (in Belgium too, for info) for a binary protocol, and we add 
4 bytes
too. This makes our protocol more robust, and decoding easier.

J-F

> Maarten
>
> Chris Allen wrote:
>
>> Hi,
>>
>> I ended up using Jdom for paring the XML in my proxy server for Jabber
>> using MINA.  It worked very well.  Basically you can create a
>> ProtocolCodecFactory that uses a custom ProtocolDecoder.  The decoder
>> will have to overwrite the decode() method where it will convert the
>> ByteBuffer that it receives into an org.jdom.Document instance.  You
>> can either do the parsing of the XML there or do it in your
>> IoHandlerAdapter's messageReceived() method.
>>
>> There is a good example of using a ProtocolCodecFactory for converting
>> the messages to Strings on the MINA website; it's basically the same
>> thing, except you convert it into either a Jdom Document like I'm
>> doing or one of the others that Vinod suggested.  Take a look at the
>> package org.apache.mina.filter.codec.textline for an example:
>> http://directory.apache.org/subprojects/network/xref/org/apache/mina/filter/codec/textline/package-summary.html
>>
>> I hope that helps.
>>
>> -Chris
>>
>> On 1/6/06, Vinod Panicker <vi...@gmail.com> wrote:
>>
>>> On 1/6/06, sylvain.eche@bnpparibas.com <sy...@bnpparibas.com> wrote:
>>>
>>>> Hi all
>>>>
>>>> Is there any source code that implement XML parsing for Mina ?
>>>> my Aim is to implement an XML parsing (as a decoder) that transform XML in
>>>> object and send this objects to the handler.
>>>> Has anyone see some sample about that ?
>>>>
>>> Might sound silly, but have you considered using SAX / DOM / XPath for
>>> your XML parsing?  That will give you ready made objects that you can
>>> pass to your handler.
>>>
>>> Regards,
>>> Vinod.
>>>
>>>
>>
>>
>>
>
>




Re: [mina] sample with XML

Posted by Maarten Bosteels <m....@pandora.be>.
Hi,

We use mina for transport and xmlbeans (http://xmlbeans.apache.org) to 
parse and generate xml documents.
Our ProtocolDecoder just reads an array of bytes
and the ProtocolHandler passes these bytes on to the xmlparser.

The protocol (EPP) is pretty simple:
* 4 bytes indicating the total length of the message
* (length - 4) bytes of xml data

Academic question:  If your protocol doesn't have a length header and 
you don't know the
byte encoding used by the incoming xml, how can you know when a message 
is complete ?

Maarten

Chris Allen wrote:

>Hi,
>
>I ended up using Jdom for paring the XML in my proxy server for Jabber
>using MINA.  It worked very well.  Basically you can create a
>ProtocolCodecFactory that uses a custom ProtocolDecoder.  The decoder
>will have to overwrite the decode() method where it will convert the
>ByteBuffer that it receives into an org.jdom.Document instance.  You
>can either do the parsing of the XML there or do it in your
>IoHandlerAdapter's messageReceived() method.
>
>There is a good example of using a ProtocolCodecFactory for converting
>the messages to Strings on the MINA website; it's basically the same
>thing, except you convert it into either a Jdom Document like I'm
>doing or one of the others that Vinod suggested.  Take a look at the
>package org.apache.mina.filter.codec.textline for an example:
>http://directory.apache.org/subprojects/network/xref/org/apache/mina/filter/codec/textline/package-summary.html
>
>I hope that helps.
>
>-Chris
>
>On 1/6/06, Vinod Panicker <vi...@gmail.com> wrote:
>  
>
>>On 1/6/06, sylvain.eche@bnpparibas.com <sy...@bnpparibas.com> wrote:
>>    
>>
>>>Hi all
>>>
>>>Is there any source code that implement XML parsing for Mina ?
>>>my Aim is to implement an XML parsing (as a decoder) that transform XML in
>>>object and send this objects to the handler.
>>>Has anyone see some sample about that ?
>>>      
>>>
>>Might sound silly, but have you considered using SAX / DOM / XPath for
>>your XML parsing?  That will give you ready made objects that you can
>>pass to your handler.
>>
>>Regards,
>>Vinod.
>>
>>    
>>
>
>
>  
>


Re: [mina] sample with XML

Posted by Chris Allen <mr...@gmail.com>.
Hi,

I ended up using Jdom for paring the XML in my proxy server for Jabber
using MINA.  It worked very well.  Basically you can create a
ProtocolCodecFactory that uses a custom ProtocolDecoder.  The decoder
will have to overwrite the decode() method where it will convert the
ByteBuffer that it receives into an org.jdom.Document instance.  You
can either do the parsing of the XML there or do it in your
IoHandlerAdapter's messageReceived() method.

There is a good example of using a ProtocolCodecFactory for converting
the messages to Strings on the MINA website; it's basically the same
thing, except you convert it into either a Jdom Document like I'm
doing or one of the others that Vinod suggested.  Take a look at the
package org.apache.mina.filter.codec.textline for an example:
http://directory.apache.org/subprojects/network/xref/org/apache/mina/filter/codec/textline/package-summary.html

I hope that helps.

-Chris

On 1/6/06, Vinod Panicker <vi...@gmail.com> wrote:
> On 1/6/06, sylvain.eche@bnpparibas.com <sy...@bnpparibas.com> wrote:
> > Hi all
> >
> > Is there any source code that implement XML parsing for Mina ?
> > my Aim is to implement an XML parsing (as a decoder) that transform XML in
> > object and send this objects to the handler.
> > Has anyone see some sample about that ?
>
> Might sound silly, but have you considered using SAX / DOM / XPath for
> your XML parsing?  That will give you ready made objects that you can
> pass to your handler.
>
> Regards,
> Vinod.
>

Re: [mina] sample with XML

Posted by Vinod Panicker <vi...@gmail.com>.
On 1/6/06, sylvain.eche@bnpparibas.com <sy...@bnpparibas.com> wrote:
> Hi all
>
> Is there any source code that implement XML parsing for Mina ?
> my Aim is to implement an XML parsing (as a decoder) that transform XML in
> object and send this objects to the handler.
> Has anyone see some sample about that ?

Might sound silly, but have you considered using SAX / DOM / XPath for
your XML parsing?  That will give you ready made objects that you can
pass to your handler.

Regards,
Vinod.