Search in sources :

Example 1 with RawBody

use of com.blade.mvc.http.RawBody in project blade by biezhi.

the class DefaultExceptionHandler method renderPage.

protected void renderPage(Response response, ModelAndView modelAndView) {
    var sw = new StringWriter();
    try {
        WebContext.blade().templateEngine().render(modelAndView, sw);
        ByteBuf buffer = Unpooled.wrappedBuffer(sw.toString().getBytes("utf-8"));
        FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode()), buffer);
        response.body(new RawBody(fullHttpResponse));
    } catch (Exception e) {
        log.error("Render view error", e);
    }
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) StringWriter(java.io.StringWriter) lombok.var(lombok.var) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) RawBody(com.blade.mvc.http.RawBody) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

RawBody (com.blade.mvc.http.RawBody)1 ByteBuf (io.netty.buffer.ByteBuf)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1 StringWriter (java.io.StringWriter)1 lombok.var (lombok.var)1