Example usage for io.netty.handler.codec.http.multipart HttpPostRequestDecoder HttpPostRequestDecoder

List of usage examples for io.netty.handler.codec.http.multipart HttpPostRequestDecoder HttpPostRequestDecoder

Introduction

In this page you can find the example usage for io.netty.handler.codec.http.multipart HttpPostRequestDecoder HttpPostRequestDecoder.

Prototype

public HttpPostRequestDecoder(HttpDataFactory factory, HttpRequest request) 

Source Link

Usage

From source file:HttpUploadServerHandler.java

License:Apache License

@Override
public void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HttpRequest) {
        HttpRequest request = this.request = (HttpRequest) msg;
        URI uri = new URI(request.getUri());
        if (!uri.getPath().startsWith("/form")) {
            // Write Menu
            writeMenu(ctx);/*from w  w w. j  a v  a 2  s.c  o m*/
            return;
        }
        responseContent.setLength(0);
        responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
        responseContent.append("===================================\r\n");

        responseContent.append("VERSION: " + request.getProtocolVersion().text() + "\r\n");

        responseContent.append("REQUEST_URI: " + request.getUri() + "\r\n\r\n");
        responseContent.append("\r\n\r\n");

        // new getMethod
        List<Entry<String, String>> headers = request.headers().entries();
        for (Entry<String, String> entry : headers) {
            responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        // new getMethod
        Set<Cookie> cookies;
        String value = request.headers().get(COOKIE);
        if (value == null) {
            cookies = Collections.emptySet();
        } else {
            cookies = CookieDecoder.decode(value);
        }
        for (Cookie cookie : cookies) {
            responseContent.append("COOKIE: " + cookie.toString() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        QueryStringDecoder decoderQuery = new QueryStringDecoder(request.getUri());
        Map<String, List<String>> uriAttributes = decoderQuery.parameters();
        for (Entry<String, List<String>> attr : uriAttributes.entrySet()) {
            for (String attrVal : attr.getValue()) {
                responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");
            }
        }
        responseContent.append("\r\n\r\n");

        // if GET Method: should not try to create a HttpPostRequestDecoder
        try {
            decoder = new HttpPostRequestDecoder(factory, request);
        } catch (ErrorDataDecoderException e1) {
            e1.printStackTrace();
            responseContent.append(e1.getMessage());
            writeResponse(ctx.channel());
            ctx.channel().close();
            return;
        } catch (IncompatibleDataDecoderException e1) {
            // GET Method: should not try to create a HttpPostRequestDecoder
            // So OK but stop here
            responseContent.append(e1.getMessage());
            responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
            writeResponse(ctx.channel());
            return;
        }

        readingChunks = HttpHeaders.isTransferEncodingChunked(request);
        responseContent.append("Is Chunked: " + readingChunks + "\r\n");
        responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
        if (readingChunks) {
            // Chunk version
            responseContent.append("Chunks: ");
            readingChunks = true;
        }
    }

    // check if the decoder was constructed before
    // if not it handles the form get
    if (decoder != null) {
        if (msg instanceof HttpContent) {
            // New chunk is received
            HttpContent chunk = (HttpContent) msg;
            try {
                decoder.offer(chunk);
            } catch (ErrorDataDecoderException e1) {
                e1.printStackTrace();
                responseContent.append(e1.getMessage());
                writeResponse(ctx.channel());
                ctx.channel().close();
                return;
            }
            responseContent.append('o');
            // example of reading chunk by chunk (minimize memory usage due to
            // Factory)
            readHttpDataChunkByChunk();
            // example of reading only if at the end
            if (chunk instanceof LastHttpContent) {
                readHttpDataAllReceive(ctx.channel());
                writeResponse(ctx.channel());
                readingChunks = false;

                reset();
            }
        }
    }
}

From source file:cc.blynk.core.http.handlers.UploadHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (msg instanceof HttpRequest) {
        HttpRequest req = (HttpRequest) msg;

        if (!accept(ctx, req)) {
            ctx.fireChannelRead(msg);//from w ww . j a  v  a  2 s.  c o m
            return;
        }

        try {
            log.debug("Incoming {} {}", req.method(), req.uri());
            decoder = new HttpPostRequestDecoder(factory, req);
        } catch (ErrorDataDecoderException e) {
            log.error("Error creating http post request decoder.", e);
            ctx.writeAndFlush(badRequest(e.getMessage()));
            return;
        }

    }

    if (decoder != null && msg instanceof HttpContent) {
        // New chunk is received
        HttpContent chunk = (HttpContent) msg;
        try {
            decoder.offer(chunk);
        } catch (ErrorDataDecoderException e) {
            log.error("Error creating http post offer.", e);
            ctx.writeAndFlush(badRequest(e.getMessage()));
            return;
        } finally {
            chunk.release();
        }

        // example of reading only if at the end
        if (chunk instanceof LastHttpContent) {
            Response response;
            try {
                String path = finishUpload();
                if (path != null) {
                    response = afterUpload(ctx, path);
                } else {
                    response = serverError("Can't find binary data in request.");
                }
            } catch (NoSuchFileException e) {
                log.error("Unable to copy uploaded file to static folder. Reason : {}", e.getMessage());
                response = (serverError());
            } catch (Exception e) {
                log.error("Error during file upload.", e);
                response = (serverError());
            }
            ctx.writeAndFlush(response);
        }
    }
}

From source file:cc.io.lessons.server.HttpUploadServerHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {

    if (msg instanceof HttpRequest) {
        System.out.println(msg.toString());
    } else {//from w w  w.j av a  2  s.  c o  m
        System.out.println(ByteBufUtil.hexDump(((HttpContent) msg).content()));
        //System.out.println(((HttpContent) msg).content().toString(Charset.defaultCharset()));
    }

    if (msg instanceof HttpRequest) {
        HttpRequest request = this.request = (HttpRequest) msg;
        URI uri = new URI(request.getUri());
        if (!uri.getPath().startsWith("/form")) {
            // Write Menu
            writeMenu(ctx);
            return;
        }
        responseContent.setLength(0);
        responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
        responseContent.append("===================================\r\n");

        responseContent.append("VERSION: " + request.getProtocolVersion().text() + "\r\n");

        responseContent.append("REQUEST_URI: " + request.getUri() + "\r\n\r\n");
        responseContent.append("\r\n\r\n");

        // new getMethod
        List<Entry<String, String>> headers = request.headers().entries();
        for (Entry<String, String> entry : headers) {
            responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        // new getMethod
        Set<Cookie> cookies;
        String value = request.headers().get(COOKIE);
        if (value == null) {
            cookies = Collections.emptySet();
        } else {
            cookies = CookieDecoder.decode(value);
        }
        for (Cookie cookie : cookies) {
            responseContent.append("COOKIE: " + cookie.toString() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        QueryStringDecoder decoderQuery = new QueryStringDecoder(request.getUri());
        Map<String, List<String>> uriAttributes = decoderQuery.parameters();
        for (Entry<String, List<String>> attr : uriAttributes.entrySet()) {
            for (String attrVal : attr.getValue()) {
                responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");
            }
        }
        responseContent.append("\r\n\r\n");

        // if GET Method: should not try to create a HttpPostRequestDecoder
        try {
            decoder = new HttpPostRequestDecoder(factory, request);
        } catch (ErrorDataDecoderException e1) {
            e1.printStackTrace();
            responseContent.append(e1.getMessage());
            writeResponse(ctx.channel());
            ctx.channel().close();
            return;
        } catch (IncompatibleDataDecoderException e1) {
            // GET Method: should not try to create a HttpPostRequestDecoder
            // So OK but stop here
            responseContent.append(e1.getMessage());
            responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
            writeResponse(ctx.channel());
            return;
        }

        readingChunks = HttpHeaders.isTransferEncodingChunked(request);
        responseContent.append("Is Chunked: " + readingChunks + "\r\n");
        responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
        if (readingChunks) {
            // Chunk version
            responseContent.append("Chunks: ");
            readingChunks = true;
        }
    }

    // check if the decoder was constructed before
    // if not it handles the form get
    if (decoder != null) {
        if (msg instanceof HttpContent) {
            // New chunk is received
            HttpContent chunk = (HttpContent) msg;
            try {
                decoder.offer(chunk);
            } catch (ErrorDataDecoderException e1) {
                e1.printStackTrace();
                responseContent.append(e1.getMessage());
                writeResponse(ctx.channel());
                ctx.channel().close();
                return;
            }
            responseContent.append('o');
            // example of reading chunk by chunk (minimize memory usage due to
            // Factory)
            readHttpDataChunkByChunk();
            // example of reading only if at the end
            if (chunk instanceof LastHttpContent) {
                writeResponse(ctx.channel());
                readingChunks = false;

                reset();
            }
        }
    }
}

From source file:com.bay1ts.bay.core.Request.java

License:Apache License

/**
 * ?Content-Type:application/x-www-form-urlencoded post body ?(htmlform)
 *
 * @param name ??form post inputname//from  w  w w .j  a va2 s  .c  o m
 * @return value
 */
public String postBody(String name) {
    HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(
            new DefaultHttpDataFactory(false), this.fullHttpRequest);
    InterfaceHttpData data = httpPostRequestDecoder.getBodyHttpData(name);
    if (data != null && data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
        Attribute attribute = (Attribute) data;
        String value = null;
        try {
            value = attribute.getValue();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            data.release();
        }
        return value;
    }
    return null;
}

From source file:com.bay1ts.bay.core.Request.java

License:Apache License

public Set<String> postBodyNames() {
    Set<String> set = new HashSet<>();
    HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(
            new DefaultHttpDataFactory(false), this.fullHttpRequest);
    for (InterfaceHttpData data : httpPostRequestDecoder.getBodyHttpDatas()) {
        data = httpPostRequestDecoder.next();
        set.add(data.getName());// w  w  w. j  av  a 2s  . c o  m
        data.release();
        //            if (data!=null){
        //                try {
        //                    Attribute attribute=(Attribute) data;
        //                    set.add(attribute.getName());
        //                }finally {
        //                    data.release();
        //                }
        //            }
    }
    return set;
}

From source file:com.bay1ts.bay.core.Request.java

License:Apache License

public Set<String> postBodyValues() {
    HttpPostRequestDecoder httpPostRequestDecoder = new HttpPostRequestDecoder(
            new DefaultHttpDataFactory(false), this.fullHttpRequest);
    Set<String> set = new HashSet<>();
    for (; httpPostRequestDecoder.hasNext();) {
        InterfaceHttpData data = httpPostRequestDecoder.next();
        if (data != null) {
            try {
                Attribute attribute = (Attribute) data;
                set.add(attribute.getValue());
            } catch (IOException e) {
                e.printStackTrace();//from w  ww . ja v a 2s  . c o m
            } finally {
                data.release();
            }
        }
    }
    return set;
}

From source file:com.chiorichan.http.HttpHandler.java

License:Mozilla Public License

@Override
protected void messageReceived(ChannelHandlerContext ctx, Object msg) throws Exception {
    Timings.start(this);

    if (msg instanceof FullHttpRequest) {
        if (AppLoader.instances().get(0).runLevel() != RunLevel.RUNNING) {
            // Outputs a very crude raw message if we are running in a low level mode a.k.a. Startup or Reload.
            // While in the mode, much of the server API is potentially unavailable, that is why we do this.

            StringBuilder sb = new StringBuilder();
            sb.append("<h1>503 - Service Unavailable</h1>\n");
            sb.append(/* w  ww . j  a v a 2 s  .c o m*/
                    "<p>I'm sorry to have to be the one to tell you this but the server is currently unavailable.</p>\n");
            sb.append(
                    "<p>This is most likely due to many possibilities, most commonly being it's currently booting up. Which would be great news because it means your request should succeed if you try again.</p>\n");
            sb.append(
                    "<p>But it is also possible that the server is actually running in a low level mode or could be offline for some other reason. If you feel this is a mistake, might I suggest you talk with the server admin.</p>\n");
            sb.append("<p><i>You have a good day now and we will see you again soon. :)</i></p>\n");
            sb.append("<hr>\n");
            sb.append("<small>Running <a href=\"https://github.com/ChioriGreene/ChioriWebServer\">"
                    + Versioning.getProduct() + "</a> Version " + Versioning.getVersion() + " (Build #"
                    + Versioning.getBuildNumber() + ")<br />" + Versioning.getCopyright() + "</small>");

            FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
                    HttpResponseStatus.valueOf(503), Unpooled.wrappedBuffer(sb.toString().getBytes()));
            ctx.write(response);

            return;
        }

        requestFinished = false;
        requestOrig = (FullHttpRequest) msg;
        request = new HttpRequestWrapper(ctx.channel(), requestOrig, this, ssl, log);
        response = request.getResponse();

        String threadName = Thread.currentThread().getName();

        if (threadName.length() > 10)
            threadName = threadName.substring(0, 2) + ".." + threadName.substring(threadName.length() - 6);
        else if (threadName.length() < 10)
            threadName = threadName + Strings.repeat(" ", 10 - threadName.length());

        log.header("&7[&d%s&7] %s %s [&9%s:%s&7] -> [&a%s:%s&7]", threadName,
                dateFormat.format(Timings.millis()), timeFormat.format(Timings.millis()), request.getIpAddr(),
                request.getRemotePort(), request.getLocalIpAddr(), request.getLocalPort());

        if (HttpHeaderUtil.is100ContinueExpected((HttpRequest) msg))
            send100Continue(ctx);

        if (NetworkSecurity.isIpBanned(request.getIpAddr())) {
            response.sendError(403);
            return;
        }

        Site currentSite = request.getLocation();

        File tmpFileDirectory = currentSite != null ? currentSite.directoryTemp()
                : AppConfig.get().getDirectoryCache();

        setTempDirectory(tmpFileDirectory);

        if (request.isWebsocketRequest()) {
            try {
                WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
                        request.getWebSocketLocation(requestOrig), null, true);
                handshaker = wsFactory.newHandshaker(requestOrig);
                if (handshaker == null)
                    WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
                else
                    handshaker.handshake(ctx.channel(), requestOrig);
            } catch (WebSocketHandshakeException e) {
                NetworkManager.getLogger().severe(
                        "A request was made on the websocket uri '/fw/websocket' but it failed to handshake for reason '"
                                + e.getMessage() + "'.");
                response.sendError(500, null, "This URI is for websocket requests only<br />" + e.getMessage());
            }
            return;
        }

        if (request.method() != HttpMethod.GET)
            try {
                decoder = new HttpPostRequestDecoder(factory, requestOrig);
            } catch (ErrorDataDecoderException e) {
                e.printStackTrace();
                response.sendException(e);
                return;
            }

        request.contentSize += requestOrig.content().readableBytes();

        if (decoder != null) {
            try {
                decoder.offer(requestOrig);
            } catch (ErrorDataDecoderException e) {
                e.printStackTrace();
                response.sendError(e);
                // ctx.channel().close();
                return;
            } catch (IllegalArgumentException e) {
                // TODO Handle this further? maybe?
                // java.lang.IllegalArgumentException: empty name
            }
            readHttpDataChunkByChunk();
        }

        handleHttp();

        finish();
    } else if (msg instanceof WebSocketFrame) {
        WebSocketFrame frame = (WebSocketFrame) msg;

        // Check for closing frame
        if (frame instanceof CloseWebSocketFrame) {
            handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame.retain());
            return;
        }

        if (frame instanceof PingWebSocketFrame) {
            ctx.channel().write(new PongWebSocketFrame(frame.content().retain()));
            return;
        }

        if (!(frame instanceof TextWebSocketFrame))
            throw new UnsupportedOperationException(
                    String.format("%s frame types are not supported", frame.getClass().getName()));

        String request = ((TextWebSocketFrame) frame).text();
        NetworkManager.getLogger()
                .fine("Received '" + request + "' over WebSocket connection '" + ctx.channel() + "'");
        ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
    } else if (msg instanceof DefaultHttpRequest) {
        // Do Nothing!
    } else
        NetworkManager.getLogger().warning(
                "Received Object '" + msg.getClass() + "' and had nothing to do with it, is this a bug?");
}

From source file:com.cmz.http.upload.HttpUploadServerHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (msg instanceof HttpRequest) {
        HttpRequest request = this.request = (HttpRequest) msg;
        URI uri = new URI(request.uri());
        if (!uri.getPath().startsWith("/form")) {
            // Write Menu
            writeMenu(ctx);//from   w  ww.ja v a  2  s .c  o m
            return;
        }
        responseContent.setLength(0);
        responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
        responseContent.append("===================================\r\n");

        responseContent.append("VERSION: " + request.protocolVersion().text() + "\r\n");

        responseContent.append("REQUEST_URI: " + request.uri() + "\r\n\r\n");
        responseContent.append("\r\n\r\n");

        // new getMethod
        for (Entry<String, String> entry : request.headers()) {
            responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        // new getMethod
        Set<Cookie> cookies;
        String value = request.headers().get(HttpHeaderNames.COOKIE);
        if (value == null) {
            cookies = Collections.emptySet();
        } else {
            cookies = ServerCookieDecoder.STRICT.decode(value);
        }
        for (Cookie cookie : cookies) {
            responseContent.append("COOKIE: " + cookie + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri());
        Map<String, List<String>> uriAttributes = decoderQuery.parameters();
        for (Entry<String, List<String>> attr : uriAttributes.entrySet()) {
            for (String attrVal : attr.getValue()) {
                responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");
            }
        }
        responseContent.append("\r\n\r\n");

        // if GET Method: should not try to create a HttpPostRequestDecoder
        if (request.method().equals(HttpMethod.GET)) {
            // GET Method: should not try to create a HttpPostRequestDecoder
            // So stop here
            responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
            // Not now: LastHttpContent will be sent writeResponse(ctx.channel());
            return;
        }
        try {
            decoder = new HttpPostRequestDecoder(factory, request);
        } catch (ErrorDataDecoderException e1) {
            e1.printStackTrace();
            responseContent.append(e1.getMessage());
            writeResponse(ctx.channel());
            ctx.channel().close();
            return;
        }

        readingChunks = HttpUtil.isTransferEncodingChunked(request);
        responseContent.append("Is Chunked: " + readingChunks + "\r\n");
        responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
        if (readingChunks) {
            // Chunk version
            responseContent.append("Chunks: ");
            readingChunks = true;
        }
    }

    // check if the decoder was constructed before
    // if not it handles the form get
    if (decoder != null) {
        if (msg instanceof HttpContent) {
            // New chunk is received
            HttpContent chunk = (HttpContent) msg;
            try {
                decoder.offer(chunk);
            } catch (ErrorDataDecoderException e1) {
                e1.printStackTrace();
                responseContent.append(e1.getMessage());
                writeResponse(ctx.channel());
                ctx.channel().close();
                return;
            }
            responseContent.append('o');
            // example of reading chunk by chunk (minimize memory usage due to
            // Factory)
            readHttpDataChunkByChunk();
            // example of reading only if at the end
            if (chunk instanceof LastHttpContent) {
                writeResponse(ctx.channel());
                readingChunks = false;

                reset();
            }
        }
    } else {
        writeResponse(ctx.channel());
    }
}

From source file:com.fire.login.http.HttpInboundHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HttpRequest) {
        HttpRequest req = (HttpRequest) msg;
        URI uri = URI.create(req.getUri());
        ctx.channel().attr(KEY_PATH).set(uri.getPath());

        if (req.getMethod().equals(HttpMethod.GET)) {
            QueryStringDecoder decoder = new QueryStringDecoder(URI.create(req.getUri()));
            Map<String, List<String>> parameter = decoder.parameters();
            dispatch(ctx.channel(), parameter);
            return;
        }//from ww  w . ja v  a2  s.  c o m

        decoder = new HttpPostRequestDecoder(factory, req);
    }

    if (decoder != null) {
        if (msg instanceof HttpContent) {
            HttpContent chunk = (HttpContent) msg;
            decoder.offer(chunk);

            List<InterfaceHttpData> list = decoder.getBodyHttpDatas();
            Map<String, List<String>> parameter = new HashMap<>();
            for (InterfaceHttpData data : list) {
                if (data.getHttpDataType() == HttpDataType.Attribute) {
                    Attribute attribute = (Attribute) data;
                    addParameter(attribute.getName(), attribute.getValue(), parameter);
                }
            }

            if (chunk instanceof LastHttpContent) {
                reset();
                dispatch(ctx.channel(), parameter);
            }
        }
    }
}

From source file:com.look.netty.demo.upload.HttpUploadServerHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (msg instanceof HttpRequest) {
        HttpRequest request = this.request = (HttpRequest) msg;
        URI uri = new URI(request.uri());
        if (!uri.getPath().startsWith("/form")) {
            // Write Menu
            writeMenu(ctx);/*from w w w.  j a va 2 s  .c o  m*/
            return;
        }
        responseContent.setLength(0);
        responseContent.append("WELCOME TO THE WILD WILD WEB SERVER\r\n");
        responseContent.append("===================================\r\n");

        responseContent.append("VERSION: " + request.protocolVersion().text() + "\r\n");

        responseContent.append("REQUEST_URI: " + request.uri() + "\r\n\r\n");
        responseContent.append("\r\n\r\n");

        // new getMethod
        for (Entry<String, String> entry : request.headers()) {
            responseContent.append("HEADER: " + entry.getKey() + '=' + entry.getValue() + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        // new getMethod
        Set<Cookie> cookies;
        String value = request.headers().get(HttpHeaderNames.COOKIE);
        if (value == null) {
            cookies = Collections.emptySet();
        } else {
            cookies = ServerCookieDecoder.STRICT.decode(value);
        }
        for (Cookie cookie : cookies) {
            responseContent.append("COOKIE: " + cookie + "\r\n");
        }
        responseContent.append("\r\n\r\n");

        QueryStringDecoder decoderQuery = new QueryStringDecoder(request.uri());
        Map<String, List<String>> uriAttributes = decoderQuery.parameters();
        for (Entry<String, List<String>> attr : uriAttributes.entrySet()) {
            for (String attrVal : attr.getValue()) {
                responseContent.append("URI: " + attr.getKey() + '=' + attrVal + "\r\n");
            }
        }
        responseContent.append("\r\n\r\n");

        // if GET Method: should not try to create a HttpPostRequestDecoder
        if (request.method().equals(HttpMethod.GET)) {
            // GET Method: should not try to create a HttpPostRequestDecoder
            // So stop here
            responseContent.append("\r\n\r\nEND OF GET CONTENT\r\n");
            // Not now: LastHttpContent will be sent writeResponse(ctx.channel());
            return;
        }
        try {
            decoder = new HttpPostRequestDecoder(factory, request);
        } catch (ErrorDataDecoderException e1) {
            e1.printStackTrace();
            responseContent.append(e1.getMessage());
            writeResponse(ctx.channel());
            ctx.channel().close();
            return;
        }

        readingChunks = HttpUtil.isTransferEncodingChunked(request);
        responseContent.append("Is Chunked: " + readingChunks + "\r\n");
        responseContent.append("IsMultipart: " + decoder.isMultipart() + "\r\n");
        if (readingChunks) {
            // Chunk version
            responseContent.append("Chunks: ");
            readingChunks = true;
        }
    }

    // check if the decoder was constructed before
    // if not it handles the form get
    if (decoder != null) {
        if (msg instanceof HttpContent) {
            // New chunk is received
            HttpContent chunk = (HttpContent) msg;
            try {
                decoder.offer(chunk);
            } catch (ErrorDataDecoderException e1) {
                e1.printStackTrace();
                responseContent.append(e1.getMessage());
                writeResponse(ctx.channel());
                ctx.channel().close();
                return;
            }
            responseContent.append('o');
            // example of reading chunk by chunk (minimize memory usage due to
            // Factory)
            readHttpDataChunkByChunk();
            System.err.println(new String(responseContent.toString().getBytes(), "UTF-8"));
            // example of reading only if at the end
            if (chunk instanceof LastHttpContent) {
                writeResponse(ctx.channel());
                readingChunks = false;

                reset();
            }
        }
    } else {
        writeResponse(ctx.channel());
    }
}