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


Java HttpContent.content方法代码示例

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


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

示例1: channelRead0

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) {  
    StringUtils.Pair url = HttpUtils.parseUriIntoUrlBaseAndPath(msg.uri());
    HttpRequest request = new HttpRequest();
    if (url.left == null) {
        String requestScheme = provider.isSsl() ? "https" : "http";
        String host = msg.headers().get(HttpUtils.HEADER_HOST);
        request.setUrlBase(requestScheme + "://" + host);
    } else {
        request.setUrlBase(url.left);            
    }                                
    request.setUri(url.right);
    request.setMethod(msg.method().name());
    msg.headers().forEach(h -> request.addHeader(h.getKey(), h.getValue()));
    QueryStringDecoder decoder = new QueryStringDecoder(url.right);                
    decoder.parameters().forEach((k, v) -> request.putParam(k, v));
    HttpContent httpContent = (HttpContent) msg;
    ByteBuf content = httpContent.content();
    if (content.isReadable()) {
        byte[] bytes = new byte[content.readableBytes()];
        content.readBytes(bytes);
        request.setBody(bytes);
    }
    writeResponse(request, ctx);
    ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:intuit,项目名称:karate,代码行数:27,代码来源:FeatureServerHandler.java

示例2: handleChunk

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
private void handleChunk(HttpContent chunk,//
        final Channel channel,//
        final NettyResponseFuture<?> future,//
        AsyncHandler<?> handler) throws IOException, Exception {

    boolean interrupt = false;
    boolean last = chunk instanceof LastHttpContent;

    // Netty 4: the last chunk is not empty
    if (last) {
        LastHttpContent lastChunk = (LastHttpContent) chunk;
        HttpHeaders trailingHeaders = lastChunk.trailingHeaders();
        if (!trailingHeaders.isEmpty()) {
            interrupt = handler.onHeadersReceived(new HttpResponseHeaders(trailingHeaders, true)) != State.CONTINUE;
        }
    }

    ByteBuf buf = chunk.content();
    if (!interrupt && !(handler instanceof StreamedAsyncHandler) && (buf.readableBytes() > 0 || last)) {
        HttpResponseBodyPart part = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last);
        interrupt = updateBodyAndInterrupt(future, handler, part);
    }

    if (interrupt || last)
        finishUpdate(future, channel, !last);
}
 
开发者ID:amaralDaniel,项目名称:megaphone,代码行数:27,代码来源:HttpHandler.java

示例3: channelRead0

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg)
        throws Exception {
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;
        RandomAccessFile output = null;
        FileChannel oc = null;
        try {
            output = new RandomAccessFile(file, "rw");
            oc = output.getChannel();
            oc.position(oc.size());
            ByteBuf buffer = content.content();
            for (int i = 0, len = buffer.nioBufferCount(); i < len; i++) {
                oc.write(buffer.nioBuffers()[i]);
            }
        } finally {
            IOUtils.closeQuietly(oc);
            IOUtils.closeQuietly(output);
        }
        if (content instanceof LastHttpContent) {
            ctx.close();
        }
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:25,代码来源:NettyClient_NoHttps.java

示例4: receive

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
void receive(HttpContent content) {
  // Consume the response body.
  ByteBuf byteBuf = content.content();
  for (int toRead; (toRead = byteBuf.readableBytes()) > 0; ) {
    byteBuf.readBytes(buffer, 0, Math.min(buffer.length, toRead));
    total += toRead;
  }

  if (VERBOSE && content instanceof LastHttpContent) {
    long finish = System.nanoTime();
    System.out.println(String.format("Transferred % 8d bytes in %4d ms",
        total, TimeUnit.NANOSECONDS.toMillis(finish - start)));
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:NettyHttpClient.java

示例5: loadPostReqParams

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
public static Map<String,Object> loadPostReqParams(HttpContent content){

        Map<String,Object> params =null;

        try {
            Gson gson = new Gson();
            Type paraMap = new TypeToken<Map<String, JsonElement>>(){}.getType();
            ByteBufInputStream in = new ByteBufInputStream(content.content());
            String rawJson = IOUtils.readAll(in);
            params = gson.fromJson(rawJson,paraMap);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return params;
    }
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:16,代码来源:NettyUtils.java

示例6: channelRead

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
        throws Exception {
    if (msg instanceof HttpRequest) {
        request = (HttpRequest) msg;

        String uri = request.getUri();
        System.out.println("Uri:" + uri);
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;
        ByteBuf buf = content.content();
        System.out.println(buf.toString(io.netty.util.CharsetUtil.UTF_8));
        buf.release();

        String res = "I am OK";
        FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1,
                OK, Unpooled.wrappedBuffer(res.getBytes("UTF-8")));
        response.headers().set(CONTENT_TYPE, "text/plain");
        response.headers().set(CONTENT_LENGTH,
                response.content().readableBytes());
        if (HttpHeaders.isKeepAlive(request)) {
            response.headers().set(CONNECTION, Values.KEEP_ALIVE);
        }
        ctx.write(response);
        ctx.flush();
    }
}
 
开发者ID:janzolau1987,项目名称:study-netty,代码行数:29,代码来源:HttpServerInboundHandler.java

示例7: channelRead

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof HttpResponse) 
    {
        HttpResponse response = (HttpResponse) msg;
        System.out.println("CONTENT_TYPE:" + response.headers().get(HttpHeaders.Names.CONTENT_TYPE));
    }
    if(msg instanceof HttpContent)
    {
        HttpContent content = (HttpContent)msg;
        ByteBuf buf = content.content();
        System.out.println(buf.toString(io.netty.util.CharsetUtil.UTF_8));
        buf.release();
    }
}
 
开发者ID:janzolau1987,项目名称:study-netty,代码行数:16,代码来源:HttpClientInboundHandler.java

示例8: onContent

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
public void onContent(HttpContent httpContent) throws IOException {
    ByteBuf content = httpContent.content();

    if (content.isReadable()) {
        getNettyEntityStream().onContent(content, httpContent instanceof LastHttpContent);
    }
}
 
开发者ID:restlet,项目名称:restlet-framework,代码行数:8,代码来源:NettyServerCall.java

示例9: captureRequestSize

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
/**
 * Adds the size of this httpContent to the requestBodySize.
 *
 * @param httpContent HttpContent to size
 */
protected void captureRequestSize(HttpContent httpContent) {
    Log.e("InnerHandle", "captureRequestSize " + harEntry.getId());
    ByteBuf bufferedContent = httpContent.content();
    int contentSize = bufferedContent.readableBytes();
    requestBodySize.addAndGet(contentSize);
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:12,代码来源:HarCaptureFilter.java

示例10: captureResponseSize

import io.netty.handler.codec.http.HttpContent; //导入方法依赖的package包/类
/**
 * Adds the size of this httpContent to the responseBodySize.
 *
 * @param httpContent HttpContent to size
 */
protected void captureResponseSize(HttpContent httpContent) {
    Log.e("InnerHandle", "captureResponseSize " + harEntry.getId());
    ByteBuf bufferedContent = httpContent.content();
    int contentSize = bufferedContent.readableBytes();
    responseBodySize.addAndGet(contentSize);
    proxyManager.dataReceived(contentSize);
}
 
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:13,代码来源:HarCaptureFilter.java


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