users@grizzly.java.net

Re: How to implement the client's message flow based on async read/write?

From: John ROM <snake-john_at_gmx.de>
Date: Mon, 16 Jun 2008 16:53:03 +0200

Hello Ji,
for me it works how it should.
Could you write again what you exactly expect to happen?

I get the following output when doing a get on www.google.com

>> HttpRequestFilter.execute()
>> HttpRequestFilter.execute()
,,,<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.de/">here</A>.
</BODY></HTML>

>> HttpRequestFilter.execute()
java.nio.channels.ClosedChannelException

I am using
public class HttpCallback implements CallbackHandler<Context> {
    public static final String ATTIB_CONNECTION = "connection";
    private TCPConnectorHandler connectorHandler;

    public HttpCallback(TCPConnectorHandler ch) {
        connectorHandler = ch;
    }

    public void onConnect(IOEvent<Context> ioEvent) {
        Context ctx = ioEvent.attachment();
        try {
            connectorHandler.finishConnect(ctx.getSelectionKey());
        } catch (IOException e) {
            e.printStackTrace();
        }
        ctx.getSelectorHandler().register(ctx.getSelectionKey(),
                SelectionKey.OP_WRITE); // Depends on your

    }

    public void onRead(IOEvent<Context> ioEvent) {
        callFilterChain(ioEvent.attachment());
    }

    public void onWrite(IOEvent<Context> ioEvent) {
        callFilterChain(ioEvent.attachment());
    }

    private void callFilterChain(Context ctx) {
        AttributeHolder ah =
                ctx.getAttributeHolderByScope(AttributeScope.CONNECTION);
        if (ah == null) {
            ah = ((WorkerThread) Thread.currentThread()).getAttachment();
            ctx.getSelectionKey().attach(ah);
        }
        ah.setAttribute(ATTIB_CONNECTION, connectorHandler);
        try {
            ctx.getProtocolChain().execute(ctx);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

-- 
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx