当前位置: 首页>>代码示例>>Java>>正文


Java DefaultFullHttpRequest.setDecoderResult方法代码示例

本文整理汇总了Java中io.netty.handler.codec.http.DefaultFullHttpRequest.setDecoderResult方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultFullHttpRequest.setDecoderResult方法的具体用法?Java DefaultFullHttpRequest.setDecoderResult怎么用?Java DefaultFullHttpRequest.setDecoderResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.handler.codec.http.DefaultFullHttpRequest的用法示例。


在下文中一共展示了DefaultFullHttpRequest.setDecoderResult方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFullHttpRequestUpload

import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入方法依赖的package包/类
@Test
public void testFullHttpRequestUpload() throws Exception {
    final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

    final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "http://localhost");

    req.setDecoderResult(DecoderResult.SUCCESS);
    req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
    req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);

    // Force to use memory-based data.
    final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

    for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                        "Content-Type: image/gif\r\n" +
                        "\r\n" +
                        data + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
    }
    // Create decoder instance to test.
    final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
    assertFalse(decoder.getBodyHttpDatas().isEmpty());
    decoder.destroy();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:31,代码来源:HttpPostRequestDecoderTest.java

示例2: testQuotedBoundary

import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入方法依赖的package包/类
@Test
public void testQuotedBoundary() throws Exception {
    final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

    final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            "http://localhost");

    req.setDecoderResult(DecoderResult.SUCCESS);
    req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=\"" + boundary + '"');
    req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);

    // Force to use memory-based data.
    final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);

    for (String data : Arrays.asList("", "\r", "\r\r", "\r\r\r")) {
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" +
                        "Content-Type: image/gif\r\n" +
                        "\r\n" +
                        data + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
    }
    // Create decoder instance to test.
    final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
    assertFalse(decoder.getBodyHttpDatas().isEmpty());
    decoder.destroy();
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:31,代码来源:HttpPostRequestDecoderTest.java

示例3: testMultipartCodecWithCRasEndOfAttribute

import io.netty.handler.codec.http.DefaultFullHttpRequest; //导入方法依赖的package包/类
@Test
public void testMultipartCodecWithCRasEndOfAttribute() throws Exception {
    final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO";

    // Force to use memory-based data.
    final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false);
    // Build test case
    String extradata = "aaaa";
    String [] datas = new String[5];
    for (int i = 0; i < 4; i++) {
        datas[i] = extradata;
        for (int j = 0; j < i ; j++) {
            datas[i] += '\r';
        }
    }

    for (int i = 0; i < 4; i++) {
        final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                "http://localhost");
        req.setDecoderResult(DecoderResult.SUCCESS);
        req.headers().add(HttpHeaders.Names.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary);
        req.headers().add(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
        final String body =
                "--" + boundary + "\r\n" +
                        "Content-Disposition: form-data; name=\"file" + i + "\"\r\n" +
                        "Content-Type: image/gif\r\n" +
                        "\r\n" +
                        datas[i] + "\r\n" +
                        "--" + boundary + "--\r\n";

        req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8));
        // Create decoder instance to test.
        final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req);
        assertFalse(decoder.getBodyHttpDatas().isEmpty());
        // Check correctness: data size
        InterfaceHttpData httpdata = decoder.getBodyHttpData("file" + i);
        assertNotNull(httpdata);
        Attribute attribute = (Attribute) httpdata;
        byte []datar = attribute.get();
        assertNotNull(datar);
        assertEquals(datas[i].getBytes(CharsetUtil.UTF_8).length, datar.length);

        decoder.destroy();
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:46,代码来源:HttpPostRequestDecoderTest.java


注:本文中的io.netty.handler.codec.http.DefaultFullHttpRequest.setDecoderResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。