Example usage for io.netty.handler.codec.http DefaultFullHttpRequest toString

List of usage examples for io.netty.handler.codec.http DefaultFullHttpRequest toString

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:eu.smartenit.sbox.interfaces.sboxsdn.SboxSdnClient.java

License:Apache License

/**
 * The method that prepares the HTTP request header.
 * /*  ww  w  . ja  v  a2s . c o  m*/
 * @param uri
 *            The URI of the SDN controller REST API
 * @param content
 *            The content to be sent, as plain text
 */
public DefaultFullHttpRequest prepareHttpRequest(URI uri, String content) {
    logger.debug("Preparing the http request.");
    // Create the HTTP content bytes.
    /*
    ByteBuf buffer = ByteBufUtil.encodeString(ByteBufAllocator.DEFAULT,
    CharBuffer.wrap(content), CharsetUtil.UTF_8);
    */

    // Prepare the HTTP request.
    // Set the HTTP protocol version, method, uri and content.
    /*
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(
    HttpVersion.HTTP_1_1, HttpMethod.POST, uri.getRawPath(), buffer);
    */
    DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
            uri.getRawPath(), Unpooled.wrappedBuffer(content.getBytes()));

    // Set certain header parameters.
    request.headers().set(HttpHeaders.Names.HOST, uri.getHost());
    request.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    request.headers().set(HttpHeaders.Names.ACCEPT, "application/json; q=0.9,*/*;q=0.8");
    request.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, content.length());
    request.headers().set(HttpHeaders.Names.PRAGMA, HttpHeaders.Values.NO_CACHE);
    request.headers().set(HttpHeaders.Names.CACHE_CONTROL, HttpHeaders.Values.NO_CACHE);

    // Set some example cookies.
    request.headers().set(HttpHeaders.Names.COOKIE,
            ClientCookieEncoder.encode(new DefaultCookie("smartenit-cookie", "smartenit")));
    logger.debug("Prepared the following HTTP request to be sent: \n" + request.toString() + "\n"
            + request.content().toString(CharsetUtil.UTF_8));
    return request;
}