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 16:54:44 +0800

Hi,

It almost works as expected after I replace grizzly-framework-1.8.0-rc1.jar
with svn trunk source code. This is the 2nd time replacing the framework
implementation to solve strange problems :-(. The only remain problem is
sometimes ConnectorHandler.read(buffer, true) gets part of the response
instead of a whole one. This is only occur when requesting a remote http
server. For a local http server, it is ok.
For the remote http server case in my environment, packets capturing shows
that size of the whole response (http body and http header) is 7574 bytes
and the server respond it completely.

Regards,
-Yi Bing

2008/6/17 JianXing Yi <jianxing.yi_at_gmail.com>:

> 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
>>
>>
>