Example usage for io.netty.handler.codec.http HttpResponse getProtocolVersion

List of usage examples for io.netty.handler.codec.http HttpResponse getProtocolVersion

Introduction

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

Prototype

@Deprecated
HttpVersion getProtocolVersion();

Source Link

Usage

From source file:HttpUploadClientHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;

        System.err.println("STATUS: " + response.getStatus());
        System.err.println("VERSION: " + response.getProtocolVersion());

        if (!response.headers().isEmpty()) {
            for (String name : response.headers().names()) {
                for (String value : response.headers().getAll(name)) {
                    System.err.println("HEADER: " + name + " = " + value);
                }//  w  w w .  j  a  v  a 2s  . c  om
            }
        }

        if (response.getStatus().code() == 200 && response.headers()
                .contains(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED, true)) {
            readingChunks = true;
            System.err.println("CHUNKED CONTENT {");
        } else {
            System.err.println("CONTENT {");
        }
    }
    if (msg instanceof HttpContent) {
        HttpContent chunk = (HttpContent) msg;
        System.err.println(chunk.content().toString(CharsetUtil.UTF_8));

        if (chunk instanceof LastHttpContent) {
            if (readingChunks) {
                System.err.println("} END OF CHUNKED CONTENT");
            } else {
                System.err.println("} END OF CONTENT");
            }
            readingChunks = false;
        } else {
            System.err.println(chunk.content().toString(CharsetUtil.UTF_8));
        }
    }
}

From source file:com.ahanda.techops.noty.clientTest.ClientHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
    assert msg instanceof FullHttpResponse;
    l.info(" Got a message from server !!! {}", msg);
    ++state;/*  www. j a v  a  2 s.co m*/

    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;

        System.out.println("STATUS: " + response.getStatus());
        System.out.println("VERSION: " + response.getProtocolVersion());
        System.out.println();

        if (!response.headers().isEmpty()) {
            for (String name : response.headers().names()) {
                for (String value : response.headers().getAll(name)) {
                    System.out.println("HEADER: " + name + " = " + value);
                }
            }
            System.out.println();
        }

        if (HttpHeaders.isTransferEncodingChunked(response)) {
            System.out.println("CHUNKED CONTENT {");
        } else {
            System.out.println("CONTENT {");
        }
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;

        System.out.print(content.content().toString(CharsetUtil.UTF_8));
        System.out.flush();

        if (content instanceof LastHttpContent) {
            System.out.println("} END OF CONTENT");
        }
    }

    switch (state) {
    case 1:
        FullHttpResponse resp = (FullHttpResponse) msg;
        for (String cookiestr : resp.headers().getAll(HttpHeaders.Names.SET_COOKIE)) {
            Set<Cookie> tmp = CookieDecoder.decode(cookiestr);
            sessCookies = tmp;
        }
        //login( ctx.channel(), credential );
        pubEvent(ctx.channel(), event, (FullHttpResponse) msg);
        break;
    case 2:
        getEvents(ctx.channel(), (FullHttpResponse) msg);
        break;
    case 3:
        logout(ctx.channel());
        break;
    default:
        ctx.close();
        break;
    }
}

From source file:com.andrewkroh.cisco.xmlservices.XmlResponseChannelHandler.java

License:Apache License

@Override
public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    IpPhone phone = ctx.channel().attr(phoneAttributeKey).get();

    if (msg instanceof HttpResponse && LOGGER.isDebugEnabled()) {
        HttpResponse response = (HttpResponse) msg;

        StringBuilder responseInfo = new StringBuilder();
        responseInfo.append("Source=");
        responseInfo.append(phone.getHostname());
        responseInfo.append(", ");
        responseInfo.append("Status=");
        responseInfo.append(response.getStatus());
        responseInfo.append(", ");
        responseInfo.append("Version=");
        responseInfo.append(response.getProtocolVersion());

        for (String name : response.headers().names()) {
            for (String value : response.headers().getAll(name)) {
                responseInfo.append(", ");
                responseInfo.append(name);
                responseInfo.append('=');
                responseInfo.append(value);
            }//  w ww . j  a  va  2s  .c  o m
        }

        LOGGER.debug(responseInfo.toString());
    }

    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;

        SettableFuture<XmlPushResponse> responseFuture = ctx.channel().attr(responseAttributeKey).get();

        // The default charset for HTTP is ISO-8859-1. None
        // of the Cisco phones I've seen to date were actually
        // setting the charset so use the default. We could
        // improve here by checking the header for the value.
        String xmlContent = content.content().toString(CharsetUtil.ISO_8859_1);

        CiscoIPPhoneResponse xmlResponse = XmlMarshaller.unmarshal(xmlContent, CiscoIPPhoneResponse.class);
        responseFuture.set(new DefaultXmlPushResponse(phone, xmlResponse));

        // Cleanup:
        ctx.close();
        ctx.channel().close();
    }
}

From source file:com.buildria.mocking.builder.action.RawBodyAction.java

License:Open Source License

@Nonnull
@Override//w ww . j  a va2s.  c  o m
public HttpResponse apply(@Nonnull HttpRequest req, @Nonnull HttpResponse res) {
    Objects.requireNonNull(req);
    Objects.requireNonNull(res);
    ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(content.length);
    buffer.writeBytes(content);
    HttpResponse r = new DefaultFullHttpResponse(res.getProtocolVersion(), res.getStatus(), buffer);
    for (Map.Entry<String, String> entry : res.headers()) {
        r.headers().add(entry.getKey(), entry.getValue());
    }
    r.headers().remove(CONTENT_LENGTH);
    r.headers().add(CONTENT_LENGTH, content.length);
    return r;
}

From source file:com.digisky.innerproxy.testclient.HttpSnoopClientHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    TestTimer.add("channelRead0()::37");
    TestTimer.print();//from   w  ww  .  j  a v  a2s.c  o m
    System.out.println("http CLient received a package!");
    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;

        System.err.println("STATUS: " + response.getStatus());
        System.err.println("VERSION: " + response.getProtocolVersion());
        System.err.println();

        if (!response.headers().isEmpty()) {
            for (String name : response.headers().names()) {
                for (String value : response.headers().getAll(name)) {
                    System.err.println("HEADER: " + name + " = " + value);
                }
            }
            System.err.println();
        }

        if (HttpHeaders.isTransferEncodingChunked(response)) {
            System.err.println("CHUNKED CONTENT {");
        } else {
            System.err.println("CONTENT {");
        }
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;

        System.err.print(content.content().toString(CharsetUtil.UTF_8));
        System.err.flush();

        if (content instanceof LastHttpContent) {
            System.err.println("} END OF CONTENT");
            ctx.close();
        }
    }

}

From source file:com.digisky.stresstest.HttpSnoopClientHandler.java

License:Apache License

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    System.out.println("http CLient received a package!");
    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;

        System.err.println("STATUS: " + response.getStatus());
        System.err.println("VERSION: " + response.getProtocolVersion());
        System.err.println();//from   w ww  .  j  a v  a  2  s  .  c  om

        if (!response.headers().isEmpty()) {
            for (String name : response.headers().names()) {
                for (String value : response.headers().getAll(name)) {
                    System.err.println("HEADER: " + name + " = " + value);
                }
            }
            System.err.println();
        }

        if (HttpHeaders.isTransferEncodingChunked(response)) {
            System.err.println("CHUNKED CONTENT {");
        } else {
            System.err.println("CONTENT {");
        }
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;

        System.err.print(content.content().toString(CharsetUtil.UTF_8));
        System.err.flush();

        if (content instanceof LastHttpContent) {
            System.err.println("} END OF CONTENT");
            ctx.close();
        }
    }

}

From source file:com.github.mike10004.seleniumhelp.TrafficMonitorFilter.java

License:Apache License

protected void captureResponse(HttpResponse httpResponse, HarResponse harResponse) {
    harResponse.setStatus(httpResponse.getStatus().code());
    harResponse.setStatusText(httpResponse.getStatus().reasonPhrase());
    harResponse.setHttpVersion(httpResponse.getProtocolVersion().text());
    captureResponseHeaderSize(httpResponse, harResponse);
    captureResponseMimeType(httpResponse, harResponse);
    captureResponseHeaders(httpResponse, harResponse);
    if (BrowserMobHttpUtil.isRedirect(httpResponse)) {
        captureRedirectUrl(httpResponse, harResponse);
    }/*from   www.  j  a  v a  2  s.c  om*/
}

From source file:com.github.mike10004.seleniumhelp.TrafficMonitorFilter.java

License:Apache License

protected void captureResponseHeaderSize(HttpResponse httpResponse, HarResponse harResponse) {
    String statusLine = httpResponse.getProtocolVersion().toString() + ' '
            + httpResponse.getStatus().toString();
    // +2 => CRLF after status line, +4 => header/data separation
    long responseHeadersSize = statusLine.length() + 6;
    HttpHeaders headers = httpResponse.headers();
    responseHeadersSize += BrowserMobHttpUtil.getHeaderSize(headers);

    harResponse.setHeadersSize(responseHeadersSize);
}

From source file:com.gw.services.client.HttpsClientHandler.java

License:Apache License

@Override
public void messageReceived(ChannelHandlerContext ctx, HttpObject msg) {
    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;

        System.err.println("STATUS: " + response.getStatus());
        System.err.println("VERSION: " + response.getProtocolVersion());
        System.err.println();// w  ww.j a v  a 2 s .c o  m

        if (!response.headers().isEmpty()) {
            for (String name : response.headers().names()) {
                for (String value : response.headers().getAll(name)) {
                    System.err.println("HEADER: " + name + " = " + value);
                }
            }
            System.err.println();
        }
        System.err.println("CONTENT {");
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;

        System.err.print(content.content().toString(CharsetUtil.UTF_8));
        System.err.flush();

        if (content instanceof LastHttpContent) {
            System.err.println("} END OF CONTENT");
            ctx.close();
        }
    }
}

From source file:com.jcm.auto.sys.analyze.SiteParserHandler.java

License:Apache License

@Override
public void messageReceived(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
    if (msg instanceof HttpResponse) {
        HttpResponse response = (HttpResponse) msg;

        System.out.println("STATUS: " + response.getStatus());
        System.out.println("VERSION: " + response.getProtocolVersion());
        System.out.println();/*from   w ww.j a v a 2s  . c  o  m*/

        if (!response.headers().isEmpty()) {
            for (String name : response.headers().names()) {
                for (String value : response.headers().getAll(name)) {
                    System.out.println("HEADER: " + name + " = " + value);
                }
            }
            System.out.println();
        }

        if (HttpHeaders.isTransferEncodingChunked(response)) {
            System.out.println("CHUNKED CONTENT {");
        } else {
            System.out.println("CONTENT {");
        }
    }
    if (msg instanceof HttpContent) {
        HttpContent content = (HttpContent) msg;

        sb.append(content.content().toString(Charset.forName(site.getContentEncoding())));
        //            ByteBuf chunk = content.content();
        //           ByteBuf tmp = Unpooled.buffer(chunk.writerIndex());
        //            if (chunk.isDirect()) {
        //               chunk.readBytes(tmp);
        //            } else {
        //               tmp = chunk;
        //            }
        //            if (contentBuf == null) {
        //               contentBuf = tmp;
        //            } else {
        //               contentBuf = Unpooled.wrappedBuffer(contentBuf, tmp);
        //            }

        if (content instanceof LastHttpContent) {
            //               ctx.channel().closeFuture();
            //               System.out.println(site.getParseSite());
            AbstractParser parser = ParserManager.getParser(site.getParser());
            if (parser != null) {
                parser.parseAndSave(site, sb.toString());
                //                  parser.parseHtml(site, contentBuf.toString(Charset.forName(site.getContentEncoding())));
            }
            // parse????
            ParserManager.taskComplete();
            // ??????taskComplete
            taskCompleted = true;
            ParserManager.log.info(
                    String.format("?%s???%s", site.getParseSite(), site.getName()));
            //                System.out.println("} END OF CONTENT");
        }
    }
}