Search in sources :

Example 1 with CompleteEvent

use of com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent in project zuul by Netflix.

the class OriginResponseReceiver method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof CompleteEvent) {
        final CompleteReason reason = ((CompleteEvent) evt).getReason();
        if ((reason != SESSION_COMPLETE) && (edgeProxy != null)) {
            LOG.error("Origin request completed with reason other than COMPLETE: {}, {}", reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
            final ZuulException ze = new ZuulException("CompleteEvent", reason.name(), true);
            edgeProxy.errorFromOrigin(ze);
        }
        // See channelWrite() where these vars are first set onto the channel.
        try {
            super.userEventTriggered(ctx, evt);
        } finally {
            postCompleteHook(ctx, evt);
        }
    } else if (evt instanceof SslHandshakeCompletionEvent && !((SslHandshakeCompletionEvent) evt).isSuccess()) {
        Throwable cause = ((SslHandshakeCompletionEvent) evt).cause();
        ctx.channel().attr(SSL_HANDSHAKE_UNSUCCESS_FROM_ORIGIN_THROWABLE).set(cause);
    } else if (evt instanceof IdleStateEvent) {
        if (edgeProxy != null) {
            LOG.error("Origin request received IDLE event: {}", ChannelUtils.channelInfoForLogging(ctx.channel()));
            edgeProxy.errorFromOrigin(new OutboundException(READ_TIMEOUT, edgeProxy.getRequestAttempts()));
        }
        super.userEventTriggered(ctx, evt);
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) SslHandshakeCompletionEvent(io.netty.handler.ssl.SslHandshakeCompletionEvent) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) ZuulException(com.netflix.zuul.exception.ZuulException) CompleteReason(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason) OutboundException(com.netflix.zuul.exception.OutboundException)

Example 2 with CompleteEvent

use of com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent in project zuul by Netflix.

the class ClientRequestReceiver method userEventTriggered.

@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof CompleteEvent) {
        final CompleteReason reason = ((CompleteEvent) evt).getReason();
        if (zuulRequest != null) {
            zuulRequest.getContext().cancel();
            zuulRequest.disposeBufferedBody();
            final CurrentPassport passport = CurrentPassport.fromSessionContext(zuulRequest.getContext());
            if ((passport != null) && (passport.findState(PassportState.OUT_RESP_LAST_CONTENT_SENT) == null)) {
                // Only log this state if the response does not seem to have completed normally.
                passport.add(PassportState.IN_REQ_CANCELLED);
            }
        }
        if (reason == CompleteReason.INACTIVE && zuulRequest != null) {
            // Client closed connection prematurely.
            StatusCategoryUtils.setStatusCategory(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_CANCELLED);
        }
        if (reason == CompleteReason.PIPELINE_REJECT && zuulRequest != null) {
            StatusCategoryUtils.setStatusCategory(zuulRequest.getContext(), ZuulStatusCategory.FAILURE_CLIENT_PIPELINE_REJECT);
        }
        if (reason != SESSION_COMPLETE && zuulRequest != null) {
            final SessionContext zuulCtx = zuulRequest.getContext();
            if (clientRequest != null) {
                if (LOG.isInfoEnabled()) {
                    // thats ok, so don't log in that case.
                    if (!"HTTP/2".equals(zuulRequest.getProtocol())) {
                        LOG.debug("Client {} request UUID {} to {} completed with reason = {}, {}", clientRequest.method(), zuulCtx.getUUID(), clientRequest.uri(), reason.name(), ChannelUtils.channelInfoForLogging(ctx.channel()));
                    }
                }
            }
            if (zuulCtx.debugRequest()) {
                LOG.debug("Endpoint = {}", zuulCtx.getEndpoint());
                dumpDebugInfo(Debug.getRequestDebug(zuulCtx));
                dumpDebugInfo(Debug.getRoutingDebug(zuulCtx));
            }
        }
        if (zuulRequest == null) {
            Spectator.globalRegistry().counter("zuul.client.complete.null", "reason", String.valueOf(reason)).increment();
        }
        clientRequest = null;
        zuulRequest = null;
    }
    super.userEventTriggered(ctx, evt);
    if (evt instanceof CompleteEvent) {
        final Channel channel = ctx.channel();
        channel.attr(ATTR_ZUUL_REQ).set(null);
        channel.attr(ATTR_ZUUL_RESP).set(null);
        channel.attr(ATTR_LAST_CONTENT_RECEIVED).set(null);
    }
}
Also used : CurrentPassport(com.netflix.zuul.passport.CurrentPassport) Channel(io.netty.channel.Channel) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) SessionContext(com.netflix.zuul.context.SessionContext) CompleteReason(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)

Example 3 with CompleteEvent

use of com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent in project zuul by Netflix.

the class ClientRequestReceiverTest method setStatusCategoryForHttpPipelining.

@Test
public void setStatusCategoryForHttpPipelining() {
    EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null));
    channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "?ELhAWDLM1hwm8bhU0UT4", Unpooled.buffer());
    // Write the message and save a copy
    channel.writeInbound(request);
    final HttpRequestMessage inboundRequest = ClientRequestReceiver.getRequestFromChannel(channel);
    // Set the attr to emulate pipelining rejection
    channel.attr(HttpLifecycleChannelHandler.ATTR_HTTP_PIPELINE_REJECT).set(Boolean.TRUE);
    // Fire completion event
    channel.pipeline().fireUserEventTriggered(new CompleteEvent(CompleteReason.PIPELINE_REJECT, request, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)));
    channel.close();
    assertEquals(ZuulStatusCategory.FAILURE_CLIENT_PIPELINE_REJECT, StatusCategoryUtils.getStatusCategory(inboundRequest.getContext()));
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequestMessage(com.netflix.zuul.message.http.HttpRequestMessage) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent) Test(org.junit.Test)

Example 4 with CompleteEvent

use of com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent in project zuul by Netflix.

the class ZuulFilterChainHandler method userEventTriggered.

@Override
public final void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof CompleteEvent) {
        final CompleteEvent completeEvent = (CompleteEvent) evt;
        fireEndpointFinish(completeEvent.getReason() != SESSION_COMPLETE);
    } else if (evt instanceof HttpRequestReadTimeoutEvent) {
        sendResponse(FAILURE_CLIENT_TIMEOUT, 408, ctx);
    } else if (evt instanceof IdleStateEvent) {
        sendResponse(FAILURE_LOCAL_IDLE_TIMEOUT, 504, ctx);
    } else if (evt instanceof RequestCancelledEvent) {
        if (zuulRequest != null) {
            StatusCategoryUtils.storeStatusCategoryIfNotAlreadyFailure(zuulRequest.getContext(), FAILURE_CLIENT_CANCELLED);
        }
        fireEndpointFinish(true);
        ctx.close();
    }
    super.userEventTriggered(ctx, evt);
}
Also used : IdleStateEvent(io.netty.handler.timeout.IdleStateEvent) HttpRequestReadTimeoutEvent(com.netflix.netty.common.HttpRequestReadTimeoutEvent) RequestCancelledEvent(com.netflix.zuul.netty.RequestCancelledEvent) CompleteEvent(com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)

Aggregations

CompleteEvent (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteEvent)4 CompleteReason (com.netflix.netty.common.HttpLifecycleChannelHandler.CompleteReason)2 IdleStateEvent (io.netty.handler.timeout.IdleStateEvent)2 HttpRequestReadTimeoutEvent (com.netflix.netty.common.HttpRequestReadTimeoutEvent)1 SessionContext (com.netflix.zuul.context.SessionContext)1 OutboundException (com.netflix.zuul.exception.OutboundException)1 ZuulException (com.netflix.zuul.exception.ZuulException)1 HttpRequestMessage (com.netflix.zuul.message.http.HttpRequestMessage)1 RequestCancelledEvent (com.netflix.zuul.netty.RequestCancelledEvent)1 CurrentPassport (com.netflix.zuul.passport.CurrentPassport)1 Channel (io.netty.channel.Channel)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 SslHandshakeCompletionEvent (io.netty.handler.ssl.SslHandshakeCompletionEvent)1 Test (org.junit.Test)1