dev@grizzly.java.net

strange issue on gws 1.9.34-servlet

From: rama.rama <rama.rama_at_tiscali.it>
Date: Thu, 21 Apr 2011 15:00:17 +0200

Hello guys,

i am facing a strange problem with 1.9.34-servlet-http

as always, a test case at the end of the email will be useful to check it.

basically, that's what i have do
1. create a gws with async/std
2. add an empty async (that will just make request proceed)
3. add a normal adapter that will send out a file, wihtout too many chech


now, if you create an empty html, this will work like a charm.
if you create this html
<html>
<head>
    <link href="inc/css/text_content.css" rel="stylesheet" type="text/css" />
    <link href="inc/css/text_content_custom.css" rel="stylesheet" type="text/css" />

</head>
<body>

</body>
</html>

and do 2-3 request, everyhing stop to work...
probably because this will do 2 requests chained after the 1st one (html after begin parsed, ask for the 2 css)

ah, and no, the issue isn't that i am serving always the same file, nor is relative to the browser, i have try
with chrome, safari and ff 3 and 4.

I have simplify the test case, obviusly mine was a fully working webservices (working with 1.9.19)
here i have stiripped out a lot of stuff..
you can make it serve the 'correct' file using uri, but this isn't really necessary in this test.

hope that this small example help you to catch what's happen
(the code have some other testing stuff on it, sorry guys)

Rama

------------------------------------------------------------------------------------------------------------------------------------------------
public class DemoWebServer {

    static final AtomicInteger req = new AtomicInteger();

    public static void main(String args[]) {


        GrizzlyWebServer test = new GrizzlyWebServer(7777, "/Users/ramarama/IdeaProject/c2w_test/c2w/default/");
        test.addGrizzlyAdapter(new MyGrizzlyAdapter(), new String[]{"/"});
        test.getSelectorThread().setDisplayConfiguration(true);
        test.getSelectorThread().setCompression("on");
        test.getSelectorThread().setKeepAliveTimeoutInSeconds(-1);
        test.getSelectorThread().setMaxKeepAliveRequests(-1);
        test.addAsyncFilter(new MyAsyncFilter());

        try {
            test.start();
        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        while (true) {
            try {
                Thread.sleep(20500);
            } catch (Exception e) {

            }
        }
    }


    static class MyAsyncFilter implements AsyncFilter {
        public Result doFilter(final AsyncExecutor asyncExecutor) {
                try {
                    asyncExecutor.execute();
                    asyncExecutor.getAsyncTask().doTask();
                } catch (Exception e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                }
                return Result.FINISH;
        }
    }



    static class MyGrizzlyAdapter extends GrizzlyAdapter {
        public MyGrizzlyAdapter() {
            this.setHandleStaticResources(false);
        }

        public void service(GrizzlyRequest grizzlyRequest, GrizzlyResponse grizzlyResponse) {
            try {
                StringBuilder someJunk = new StringBuilder();
                grizzlyResponse.setContentType(MimeType.get("html"));



                for (int i = 0; i < 10; i++) someJunk.append(someJunk);

                FileInputStream fis = new FileInputStream(new File("/Users/ramarama/IdeaProject/c2w_test/c2w/default/test.html"));
                byte b[] = new byte[32768];
                ByteChunk chunk = new ByteChunk();
                int rd;
                while ((rd = fis.read(b)) > 0) {
                    chunk.setBytes(b, 0, rd);
                    grizzlyResponse.getResponse().doWrite(chunk);
                }


                req.incrementAndGet();
            } catch (IOException e) {

            }
        }
    }


}