Search in sources :

Example 1 with Request

use of info.xiancloud.nettyhttpserver.http.bean.Request in project xian by happyyangyuan.

the class RequestDecoderAux method decode.

@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception {
    LOG.debug("    httpRequest  ---->   UnitRequest Pojo");
    /*if (!HttpMethod.POST.equals(msg.method())) {
            throw new BadRequestException(new IllegalArgumentException("拒绝非POST请求!"));
        }*/
    DecoderResult result = msg.decoderResult();
    if (!result.isSuccess()) {
        throw new BadRequestException(result.cause());
    }
    updateLongConnectionStatus(msg, ctx);
    Request request = new Request(msg, MsgIdHolder.get());
    offerReqQueue(ctx, request);
    out.add(request);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Request(info.xiancloud.nettyhttpserver.http.bean.Request) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DecoderResult(io.netty.handler.codec.DecoderResult) BadRequestException(info.xiancloud.nettyhttpserver.http.bean.BadRequestException)

Example 2 with Request

use of info.xiancloud.nettyhttpserver.http.bean.Request in project xian by happyyangyuan.

the class IdleEventListener method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        LOG.info(ctx.channel().remoteAddress() + "超时类型:" + event.state().name());
        if (event.state() == IdleState.WRITER_IDLE) {
            List<Request> timeoutRequests = ctx.channel().attr(ReqQueue.REQ_QUEUE).get().removeTimeout();
            for (Request timeoutRequest : timeoutRequests) {
                timeoutRequest.getChannelHandlerContext().writeAndFlush(buildTimeoutResponse(timeoutRequest));
            }
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) Request(info.xiancloud.nettyhttpserver.http.bean.Request)

Example 3 with Request

use of info.xiancloud.nettyhttpserver.http.bean.Request in project xian by happyyangyuan.

the class BusinessHandler method channelRead.

@Override
public void channelRead(final ChannelHandlerContext ctx, final Object request0) throws Exception {
    Request request = (Request) request0;
    request.setChannelHandlerContext(ctx);
    forUseCase(ctx, request);
    ctx.fireChannelRead(request);
}
Also used : Request(info.xiancloud.nettyhttpserver.http.bean.Request)

Aggregations

Request (info.xiancloud.nettyhttpserver.http.bean.Request)3 BadRequestException (info.xiancloud.nettyhttpserver.http.bean.BadRequestException)1 DecoderResult (io.netty.handler.codec.DecoderResult)1 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)1