users@grizzly.java.net

Fwd: grizzly2 -httpserver- parse HTML request

From: Sebastien Dionne <survivant00_at_gmail.com>
Date: Wed, 3 Oct 2012 10:18:59 -0400

---------- Forwarded message ----------
From: "Sébastien Dionne" <sebastien.dionne_at_gmail.com>
Date: Oct 3, 2012 10:17 AM
Subject: Fwd: grizzly2 -httpserver- parse HTML request
To: "Survivant 00" <survivant00_at_gmail.com>

---------- Forwarded message ----------
From: <sebastien.dionne_at_scd.desjardins.com>
Date: Oct 3, 2012 10:16 AM
Subject: grizzly2 -httpserver- parse HTML request
To: <sebastien.dionne_at_gmail.com>


Hello,

I'm looking for a sample to parse HTML request with Grizzly 2 HttpServer
 like the NIOEchoHandler but in HTML format.

Is it possible to receive a builded request in the HttpServer and work with
that directly ?


here the sample that I looked :


MY SERVER

/**
       * @param args
       * @throws InterruptedException
       */
      public static void main(String[] args) throws InterruptedException {
            // create a basic server that listens on port 8080.
        HttpServer server = HttpServer.createSimpleServer();

        final ServerConfiguration config = server.getServerConfiguration();

        // Map the path, /echo, to the NonBlockingEchoHandler
        config.addHttpHandler(new NonBlockingEchoHandler(), "/echo");

      // myabe these lines are not required

        NetworkListener networkListener = new NetworkListener("aaa");

        // Construct filter chain
        FilterChainBuilder serverFilterChainBuilder =
FilterChainBuilder.stateless();
        // Add transport filter
        serverFilterChainBuilder.add(new TransportFilter());
        // Add HttpServerFilter, which transforms Buffer <-> HttpContent
        serverFilterChainBuilder.add(new HttpServerFilter());

        networkListener.setFilterChain(serverFilterChainBuilder.build());

        server.addListener(networkListener);

        try {
            server.start();
            Client client = new Client();
            client.run();
        } catch (IOException ioe) {
             ioe.printStackTrace();
        } finally {
            //server.stop();
        }

       Thread.sleep(300000);
       server.stop();

      }


but in NonBlockingEchoHandler, I would like to receive a pre-build request
 and not parsing it myself

I would like to replace

private void echoAvailableData(NIOReader in, NIOWriter out, char[] buf)
                throws IOException {

            while(in.isReady()) {
                int len = in.read(buf);
                out.write(buf, 0, len);
            }
        }

by something like


private void echoAvailableData(HttpRequest request, NIOWriter out)
                throws IOException {

      String content = request.getText(); // something that return the
headers + content

               out.write(content);

        }