Announcement Announcement Module
Collapse
No announcement yet.
Serialization for http Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Serialization for http

    Hi,

    I am receiving http messages over a TCP socket. This is not using a servlet as we use a persistant socket between 2 processes for communication. I am having trouble figuring out which serializer to use to get the http message from the TCP stream. I have tried ByteArrayCrLfSerializer, ByteArrayRawSerializer and ByteArrayLengthHeaderSerializer. But I either get no message or just 1 line of the message.

    Can someone point me to a serializer that will work with a http message or should I write on myself?

    Thanks,

    Frank

  • #2
    You need to write your own.

    If you are only doing HTTP GETs, it's quite easy, because there is no body and all you need is a stateless deserializer that looks for "\r\n\r\n". Just clone the CrLfSerializer and change it to look for "\r\n\r\n" instead of "\r\n".

    Or, you can use the CrLfSerializer to get each header, with the end being indicated by an empty String.

    POSTs etc are a little more tricky because the deserializer needs to maintain state - am I decoding headers? or the body? Plus, the HTTP body can be complex - multi-part mime, content-length header etc, etc. Writing a fully compliant HTTP parser is fairly complex.

    The current deserializers are all stateless. You could maintain state in a Map, keyed by the InputStream, but you'd need some mechanism to clean up the map if you receive a half-baked message any time.

    It's not too bad if you know exactly how the client will construct the body - just wait until you get "\r\n\r\n" and you know you are done with the headers. But you will still need to know when the body has been fully received.

    Hope that helps.

    If you get something working, you might want to submit it to the extensions repository.

    Comment

    Working...
    X