Thanks Maarten. That has helped me to clarify my thinking about what
protocol to use.

regards


Neill

On 7/18/06, Maarten Bosteels <[EMAIL PROTECTED]> wrote:
I forget some clarification:
* the decoder reads complete requests and turns them into byte arrays.
(because I do not know the character encoding used by the document)
* the byte array is then fed to the xml parser (xmlbeans in my case)
* for outgoing messages, I use ByteArrayEncoder:

public class ByteArrayEncoder implements ProtocolEncoder {

  protected final Log logger = LogFactory.getLog(getClass());

  public void encode(ProtocolSession session, Object message,
ProtocolEncoderOutput out) throws ProtocolViolationException {

    byte[] bytes = (byte[]) message;
    int totalLength = bytes.length + 4;
    logger.debug ("encoding message with total length " + totalLength);

    ByteBuffer buf = ByteBuffer.allocate( totalLength );
    buf.putInt(totalLength);
    buf.put(bytes);
    buf.flip();
    out.write (buf);
  }

good luck,
Maarten


On 7/18/06, Maarten Bosteels <[EMAIL PROTECTED]> wrote:
>
> Hello Neill,
>
> I have no experience with XML-RPC, but I have implemented an EPP server,
> using MINA.
> http://www.rfc-archive.org/getrfc.php?rfc=3734
>
> It is an request-response protocol, and both request and response are XML
> documents.
> The first 4 bytes of every message (both incoming and outgoing) indicates
> the total number of bytes of the
> message. Prefixing the message, with the length of the message is a common
> idiom and very easy to implement.
>
> My implementation is still based on mina 0.8.x, so it might not be very
> usefull to you.
>
> Maarten
>
> public class ByteArrayDecoder extends CumulativeProtocolDecoder {
>
>   protected final Log logger = LogFactory.getLog(getClass());
>
>   public ByteArrayDecoder() {
>     super(2048);
>   }
>
>   protected boolean doDecode(ProtocolSession protocolSession, ByteBuffer
> in, ProtocolDecoderOutput out) throws ProtocolViolationException {
>       int len;
>       if (in.remaining() > 4)
>       {
>         len = in.getInt();
>         int dataLength = len - 4;
>
>         if (dataLength <= 0 || dataLength > 8000) {
>           throw new ProtocolViolationException("Invalid message length: "
> + len);
>         }
>
>         if (in.remaining() >= dataLength)
>         {
>           byte[] data = new byte[dataLength];
>           in.get(data);
>           out.write(data);
>           return true;
>         }
>         else
>         {
>           // put length back until message is complete
>           logger.info("put length back: " + len);
>           in.putInt(len);
>           return false;
>         }
>       }
>       else
>       {
>         return false;
>
>       }
>   }
> }
>
>
> On 7/18/06, Neill Alexander < [EMAIL PROTECTED]> wrote:
> >
> > I have written a custom server using Mina which handles XML requests
> > from clients, and sends XML responses. Version 1.0 of the server has a
> > very primitive (i.e. non-existent) protocol i.e. it expects a raw xml
> > message with no http headers etc. Since the server does not know the
> > length of the message up front, it must check the data as it comes in
> > to ensure it gets a complete xml document. As the load on the server
> > increases, I suspect that this will cause us performance problems.
> >
> > Put this down to inexperience on my behalf when it comes to writing
> > servers from scratch.
> >
> > I'm now looking for a good protocol to use to handle requests, and
> > XML-RPC looks a likely candidate. I want to investigate how difficult
> > it will prove to take our existing server and re-engineer it to use
> > XML-RPC.
> >
> > Does anyone on this mailing list have any hints or tips as to how I
> > could go about doing this? Could I use the Apache XML-RPC library to
> > re-engineer the server, for example?
> >
> > Any hints, tips, words of advice or warning greatly appreciated.
> >
> > Thanks and regards,
> >
> >
> > Neill
> >
> > [Some additional background on the server. It works in 2 modes - a
> > request / response mode, and also a notification mode whereby a client
> > can subscribe to listen for events in the system. In the notification
> > mode the client keeps a connection to the server open. The server
> > writes to this connection whenever it has information that will
> > interest the client.]
> >
>
>


Reply via email to