users@grizzly.java.net

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

From: JianXing Yi <jianxing.yi_at_gmail.com>
Date: Tue, 17 Jun 2008 09:37:17 +0800

Hello John,

In this case, what the exactly expectation is this:
HttpClient HttpServer
     |-----------------request--------------------->|
     |<----------------response-------------------|

Both the two versions of the HttpCallback implementation will work
*sometimes*, but not *always* :-(

  HttpCallback

Server type

Result

Old one

Localhost http server

Sometimes the HttpClient prints the html page correctly.

Sometimes there is no any output.

A remote http server

Sometimes print **part** of the requested html page.

New one

Localhost http server

Almost not work. I only got the requested html page once, debugging it in
step-running mode.

A remote http server

Sometimes there is no output.

what's more, I'm astonished by the HttpRequestFilter.execute() running more
than one time (both versions). Is this correct? or am I thinking about it in
a wrong way?

Thanks!

Regards,

-Yi Bing


2008/6/16 John ROM <snake-john_at_gmx.de>:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>
>