users@grizzly.java.net

grizzly custom FilterChain

From: Fodor Peter <fodpeter_at_gmail.com>
Date: Mon, 3 Oct 2011 22:16:15 +0200

Hi everyone,

I wrote a grizzly based message transfer protocol, and now I would
like to port it to HTTP. (some of our customers have paranoid
firewalls and proxies which let through only HTTP traffic). The base
idea is using HTTP posts and long polling to transfer data fragments.
(like websockets. Websocket is great technology, but it is blocked by
proxies)
I use the FilterChains and found them extremely useful, so I would
like to use them. The dataflow is something like this: The HTTP
requests arrive to FilterChain A and I would like to map and redirect
their data to FilterChain B.

FilterChain for real TCP connections:
A: TransportFilter -> HTTPFilter -> Mapping requests to virtual connections

FilterChain of virtual connections:
B: SSLFilter -> GzipFilter -> Custom parser -> Custom protocol

The problem is that I can not push data to FilterChain, because the
API is protected and it uses Connection object for AttributeHolding
etc. The message transfer protocol works with plain TCP sockets and
with FilterChain B.

I see some solutions, but none of them seems easy:
1. Dropping FilterChain B and reimplement SSL, Gzip and custom parser
from zero (This is not a real option)
2. Using the TCP loopback connection to redirect data. (This seems
easy, but it can not work on client PC, because of local firewalls)
3. Using java pipes as loopback interface (I'm working on this, but
contains lot of copy-paste and refactor)
4. Reimplementing DefaultFilterChain and somehow push ByteBuffers to
them (but every API is protected)

Did you met such problem? Am I missing something obvious?
How could I use FilterChain without a real connection?

Thanks and best regards
  Peter