Netty data processing

With such a client

StringBody body = new StringBody("form_username", Charset.forName("UTF-8"));
multipart.addPart("username", body);
ByteArrayBody bBody = new ByteArrayBody(bs, "form_command.dat");
multipart.addPart("data", bBody);
httppost.setEntity(multipart);

Like the values ​​to be received on the network server. I already have an HttpRequestDecoder added to the pipeline. And messageReceived is handled this way

HttpRequest request = (HttpRequest) e.getMessage();
    this.mRequest = request;


    if (is100ContinueExpected(request)) {
        send100Continue(e);
    }

    ChannelBuffer content = request.getContent();
    if (content.readable()) {

        System.out.println("Content()\n" + content.toString(CharsetUtil.UTF_8) + "\r\n");


    }

Printout.

Content()
--Xdq2t6unVsUp191MKhpR6BXz5P7Eoo
Content-Disposition: form-data; name="username"
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

form_username
--Xdq2t6unVsUp191MKhpR6BXz5P7Eoo
Content-Disposition: form-data; name="data"; filename="form_command.dat"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary



--Xdq2t6unVsUp191MKhpR6BXz5P7Eoo--


End of contents
+3
source share
1 answer

You need to use the new HttpPostRequestDecoder . This is only available in the upcoming Netty 3.5 (3 branches) and Netty 4 (main branch).

Here is an example usage .

If you need to use it now, you can simply copy the files mentioned in this pull request into the project namespace and use it.

Hope this helps.

+1

All Articles