I want to add that I want to have a streaming connection that will send
data (client) and receive data (server). Like a websocket connection.
In my case the data sent by the client will be string, so I will prefer to
be notify when a String is received and not playing with bytes array.
On Oct 3, 2012 10:18 AM, "Sebastien Dionne" <survivant00_at_gmail.com> wrote:
> ---------- 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);
>
> }
>
>