Search in sources :

Example 1 with NettyServletResponse

use of org.apache.cxf.transport.http.netty.server.servlet.NettyServletResponse in project cxf by apache.

the class NettyHttpServletHandler method handleHttpServletRequest.

protected void handleHttpServletRequest(ChannelHandlerContext ctx, HttpRequest request, NettyHttpContextHandler nettyHttpContextHandler) throws Exception {
    interceptOnRequestReceived(ctx, request);
    FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    NettyServletResponse nettyServletResponse = buildHttpServletResponse(response);
    NettyHttpServletRequest nettyServletRequest = buildHttpServletRequest(request, nettyHttpContextHandler.getContextPath(), ctx);
    nettyHttpContextHandler.handle(nettyServletRequest.getRequestURI(), nettyServletRequest, nettyServletResponse);
    interceptOnRequestSuccessed(ctx, response);
    nettyServletResponse.getWriter().flush();
    boolean keepAlive = HttpHeaders.isKeepAlive(request);
    if (keepAlive) {
        // Add 'Content-Length' header only for a keep-alive connection.
        response.headers().set(Names.CONTENT_LENGTH, response.content().readableBytes());
        // Add keep alive header as per:
        // -
        // http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01.html#Connection
        response.headers().set(Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    }
    // write response...
    ChannelFuture future = ctx.write(response);
    if (!keepAlive) {
        future.addListener(ChannelFutureListener.CLOSE);
    }
}
Also used : NettyServletResponse(org.apache.cxf.transport.http.netty.server.servlet.NettyServletResponse) ChannelFuture(io.netty.channel.ChannelFuture) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NettyHttpServletRequest(org.apache.cxf.transport.http.netty.server.servlet.NettyHttpServletRequest)

Aggregations

ChannelFuture (io.netty.channel.ChannelFuture)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1 NettyHttpServletRequest (org.apache.cxf.transport.http.netty.server.servlet.NettyHttpServletRequest)1 NettyServletResponse (org.apache.cxf.transport.http.netty.server.servlet.NettyServletResponse)1