protected static boolean fireCompleteEventIfNotAlready(ChannelHandlerContext ctx, CompleteReason reason) { // Only allow this method to run once per request. Attribute<State> attr = ctx.channel().attr(ATTR_STATE); State state = attr.get(); if (state == null || state != State.STARTED) return false; attr.set(State.COMPLETED); HttpRequest request = ctx.channel().attr(ATTR_HTTP_REQ).get(); HttpResponse response = ctx.channel().attr(ATTR_HTTP_RESP).get(); // Cleanup channel attributes. ctx.channel().attr(ATTR_HTTP_REQ).set(null); ctx.channel().attr(ATTR_HTTP_RESP).set(null); // Fire the event to whole pipeline. ctx.pipeline().fireUserEventTriggered(new CompleteEvent(reason, request, response)); return true; }
HttpResponse response = ((CompleteEvent) evt).getResponse(); if (response != null) { if ("close".equalsIgnoreCase(response.headers().get("Connection"))) { final CompleteReason reason = completeEvent.getReason(); if (reason == SESSION_COMPLETE || reason == INACTIVE) { if (! closeConnection) {
@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();
HttpResponse response = ((CompleteEvent) evt).getResponse(); if (response != null) { if ("close".equalsIgnoreCase(response.headers().get("Connection"))) { final CompleteReason reason = completeEvent.getReason(); if (reason == SESSION_COMPLETE || reason == INACTIVE) { if (! closeConnection) {
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { // First let other handlers do their thing ... // super.userEventTriggered(ctx, evt); if (evt instanceof IdleStateEvent) { // Log some info about this. idleCounter.increment(); final String msg = "Origin channel for origin - " + originName + " - idle timeout has fired. " + ChannelUtils.channelInfoForLogging(ctx.channel()); closeConnection(ctx, msg); } else if (evt instanceof CompleteEvent) { // The HttpLifecycleChannelHandler instance will fire this event when either a response has finished being written, or // the channel is no longer active or disconnected. // Return the connection to pool. final CompleteReason reason = ((CompleteEvent) evt).getReason(); if (reason == SESSION_COMPLETE) { final PooledConnection conn = PooledConnection.getFromChannel(ctx.channel()); if (conn != null) { conn.setConnectionState(PooledConnection.ConnectionState.WRITE_READY); conn.release(); } } else { final String msg = "Origin channel for origin - " + originName + " - completed with reason " + reason.name() + ", " + ChannelUtils.channelInfoForLogging(ctx.channel()); closeConnection(ctx, msg); } } }
@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); } // First let this event propagate along the pipeline, before cleaning vars from the channel. // See channelWrite() where these vars are first set onto the channel. try { super.userEventTriggered(ctx, evt); } finally { postCompleteHook(ctx, evt); } } 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); } }
@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(); } else if (evt instanceof HttpLifecycleChannelHandler.RejectedPipeliningEvent) { sendResponse(FAILURE_CLIENT_PIPELINE_REJECT, 400, ctx); } super.userEventTriggered(ctx, evt); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof HttpLifecycleChannelHandler.CompleteEvent) { // Get the stored request, and remove the attr from channel to cleanup. RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); ctx.channel().attr(ATTR_REQ_STATE).set(null); // Response complete, so now write to access log. long durationNs = System.nanoTime() - state.startTimeNs; String remoteIp = ctx.channel().attr(SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS).get(); Integer localPort = ctx.channel().attr(SourceAddressChannelHandler.ATTR_LOCAL_PORT).get(); if (state.response == null) { LOG.debug("Response null in AccessLog, Complete reason={}, duration={}, url={}, method={}", ((HttpLifecycleChannelHandler.CompleteEvent)evt).getReason(), durationNs/(1000*1000), state.request != null ? state.request.uri() : "-", state.request != null ? state.request.method() : "-"); } publisher.log(ctx.channel(), state.request, state.response, state.dateTime, localPort, remoteIp, durationNs, state.requestBodySize, state.responseBodySize); } super.userEventTriggered(ctx, evt); } }
protected static boolean fireCompleteEventIfNotAlready(ChannelHandlerContext ctx, CompleteReason reason) { // Only allow this method to run once per request. Attribute<State> attr = ctx.channel().attr(ATTR_STATE); State state = attr.get(); if (state == null || state != State.STARTED) return false; attr.set(State.COMPLETED); HttpRequest request = ctx.channel().attr(ATTR_HTTP_REQ).get(); HttpResponse response = ctx.channel().attr(ATTR_HTTP_RESP).get(); // Cleanup channel attributes. ctx.channel().attr(ATTR_HTTP_REQ).set(null); ctx.channel().attr(ATTR_HTTP_RESP).set(null); // Fire the event to whole pipeline. ctx.pipeline().fireUserEventTriggered(new CompleteEvent(reason, request, response)); return true; }
HttpResponse response = ((CompleteEvent) evt).getResponse(); if (response != null) { if ("close".equalsIgnoreCase(response.headers().get("Connection"))) { final CompleteReason reason = completeEvent.getReason(); if (reason == SESSION_COMPLETE || reason == INACTIVE) { if (! closeConnection) {
@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();
@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();
@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); } // First let this event propagate along the pipeline, before cleaning vars from the channel. // See channelWrite() where these vars are first set onto the channel. try { super.userEventTriggered(ctx, evt); } finally { postCompleteHook(ctx, evt); } } 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); } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { // First let other handlers do their thing ... // super.userEventTriggered(ctx, evt); if (evt instanceof IdleStateEvent) { // Log some info about this. idleCounter.increment(); final String msg = "Origin channel for origin - " + originName + " - idle timeout has fired. " + ChannelUtils.channelInfoForLogging(ctx.channel()); closeConnection(ctx, msg); } else if (evt instanceof CompleteEvent) { // The HttpLifecycleChannelHandler instance will fire this event when either a response has finished being written, or // the channel is no longer active or disconnected. // Return the connection to pool. final CompleteReason reason = ((CompleteEvent) evt).getReason(); if (reason == SESSION_COMPLETE) { final PooledConnection conn = PooledConnection.getFromChannel(ctx.channel()); if (conn != null) { conn.setConnectionState(PooledConnection.ConnectionState.WRITE_READY); conn.release(); } } else { final String msg = "Origin channel for origin - " + originName + " - completed with reason " + reason.name() + ", " + ChannelUtils.channelInfoForLogging(ctx.channel()); closeConnection(ctx, msg); } } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { // First let other handlers do their thing ... // super.userEventTriggered(ctx, evt); if (evt instanceof IdleStateEvent) { // Log some info about this. idleCounter.increment(); final String msg = "Origin channel for origin - " + originName + " - idle timeout has fired. " + ChannelUtils.channelInfoForLogging(ctx.channel()); closeConnection(ctx, msg); } else if (evt instanceof CompleteEvent) { // The HttpLifecycleChannelHandler instance will fire this event when either a response has finished being written, or // the channel is no longer active or disconnected. // Return the connection to pool. final CompleteReason reason = ((CompleteEvent) evt).getReason(); if (reason == SESSION_COMPLETE) { final PooledConnection conn = PooledConnection.getFromChannel(ctx.channel()); if (conn != null) { conn.setConnectionState(PooledConnection.ConnectionState.WRITE_READY); conn.release(); } } else { final String msg = "Origin channel for origin - " + originName + " - completed with reason " + reason.name() + ", " + ChannelUtils.channelInfoForLogging(ctx.channel()); closeConnection(ctx, msg); } } }
@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); } // First let this event propagate along the pipeline, before cleaning vars from the channel. // See channelWrite() where these vars are first set onto the channel. try { super.userEventTriggered(ctx, evt); } finally { postCompleteHook(ctx, evt); } } 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); } }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof HttpLifecycleChannelHandler.CompleteEvent) { // Get the stored request, and remove the attr from channel to cleanup. RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); ctx.channel().attr(ATTR_REQ_STATE).set(null); // Response complete, so now write to access log. long durationNs = System.nanoTime() - state.startTimeNs; String remoteIp = ctx.channel().attr(SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS).get(); Integer localPort = ctx.channel().attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).get(); if (state.response == null) { LOG.debug("Response null in AccessLog, Complete reason={}, duration={}, url={}, method={}", ((HttpLifecycleChannelHandler.CompleteEvent)evt).getReason(), durationNs/(1000*1000), state.request != null ? state.request.uri() : "-", state.request != null ? state.request.method() : "-"); } publisher.log(ctx.channel(), state.request, state.response, state.dateTime, localPort, remoteIp, durationNs, state.requestBodySize, state.responseBodySize); } super.userEventTriggered(ctx, evt); } }
@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(); } else if (evt instanceof HttpLifecycleChannelHandler.RejectedPipeliningEvent) { sendResponse(FAILURE_CLIENT_PIPELINE_REJECT, 400, ctx); } super.userEventTriggered(ctx, evt); }
@Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof HttpLifecycleChannelHandler.CompleteEvent) { // Get the stored request, and remove the attr from channel to cleanup. RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); ctx.channel().attr(ATTR_REQ_STATE).set(null); // Response complete, so now write to access log. long durationNs = System.nanoTime() - state.startTimeNs; String remoteIp = ctx.channel().attr(SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS).get(); Integer localPort = ctx.channel().attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).get(); if (state.response == null) { LOG.debug("Response null in AccessLog, Complete reason={}, duration={}, url={}, method={}", ((HttpLifecycleChannelHandler.CompleteEvent)evt).getReason(), durationNs/(1000*1000), state.request != null ? state.request.uri() : "-", state.request != null ? state.request.method() : "-"); } publisher.log(ctx.channel(), state.request, state.response, state.dateTime, localPort, remoteIp, durationNs, state.requestBodySize, state.responseBodySize); } super.userEventTriggered(ctx, evt); } }
@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(); } else if (evt instanceof HttpLifecycleChannelHandler.RejectedPipeliningEvent) { sendResponse(FAILURE_CLIENT_PIPELINE_REJECT, 400, ctx); } super.userEventTriggered(ctx, evt); }