users@grizzly.java.net

Re: Implementing custom StreamAlgorithm

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Tue, 19 Jun 2007 22:19:33 -0400

Hi Eric,

Eric Heaton wrote:
> Hi all,
>
> I wish to implement a custom StreamAlgorithm whose parse() method can
> potentially return false if the incoming request has not been received
> completely into the input buffer. (For the curious, I'm trying to write
> a custom protocol that handles the Typed Parameter Language
> (tpl.sourceforge.net)).
>
> However, when my StreamAlgorithm's parse() method returns false, the
> request is not processed. I tried inspecting the
> ContentLengthAlgorithm's parse() method, but found that this does not
> seem to work either. I create a simple SelectorThread for the
> ContentLengthAlgorithm and POST a request that's greater than the
> default buffer size of 8192 bytes. The request is never processed.

Hum...looks like a bug I've introduced in 1.5, as I've just tried with
1.0 and it worked.

>
> Here's a (hopefully) concise example:
>
> SelectorThread selectorThread = new SelectorThread() {
> protected void initAlgorithm()
> {
> setAlgorithmClassName(
> "com.sun.grizzly.http.algorithms.ContentLengthAlgorithm");
> super.initAlgorithm();
> }
> };
> selectorThread.setPort(80);
> selectorThread.setAdapter( new StaticResourcesAdapter());
> selectorThread.initEndpoint();
> selectorThread.startEndpoint();
>
> The client is:
>
> URL url = new URL("http://localhost/index.html");
> URLConnection conn = url.openConnection();
> conn.setDoOutput(true);
> PrintWriter writer = new PrintWriter(conn.getOutputStream());
> writer.print("param=");
> for( int i = 0; i < 8000; i++ )
> {
> writer.print("data");
> }
> writer.close();
>
> InputStream in = conn.getInputStream();
> while( in.read() > 0 ) { System.out.print("."); }
> System.out.println();
>
> Am I missing some vital piece of configuration here, or am I
> misunderstanding how the parse() method is supposed to work? By the way,
> I'm using Grizzly 1.5.1 and am relatively new to using it.

No you are absolutely right. The current http sub module has a bug that
prevent the StreamAlgorithm to work as expected. Now why do you need to
use the http submodule for your project? Would it be easier to use
directly the framework classes? This way you don't have the http overhead.

I will fix the StreamAlgorithm so it can work with http like it was in 1.5.

Thanks

-- Jeanfrancois



>
> Thanks,
> -Eric
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>