HttpTransactionContext.bind(httpCtx, httpTxCtx); requestPacket.getProcessingState().setHttpContext(httpCtx); httpCtx.attach(ctx); requestPacket.setConnection(ctx.getConnection()); httpTxCtx.payloadGenerator = payloadGenerator; if (LOGGER.isDebugEnabled()) { LOGGER.debug("REQUEST: " + requestPacket.toString()); LOGGER.debug("REQUEST: " + requestPacket.toString()); ctx.write(requestPacket, ctx.getTransportContext().getCompletionHandler());
static void bind(final HttpContext httpCtx, final HttpTransactionContext httpTxContext) { httpCtx.getCloseable().addCloseListener(httpTxContext.listener); REQUEST_STATE_ATTR.set(httpCtx, httpTxContext); }
@Override public void completed(HttpTransactionContext context) { if (!context.isReuseConnection()) { final Connection c = (Connection) httpContext.getCloseable(); if (!httpContext.getRequest().getProcessingState().isStayAlive()) { if (notKeepAliveReason == null) { notKeepAliveReason = new IOException("HTTP keep-alive was disabled for this connection"); } c.closeWithReason(notKeepAliveReason); } else { final ConnectionManager cm = context.provider.getConnectionManager(); cm.returnConnection(c); } } } });
if (ctx.getConnection().isOpen()) { final HttpContext context = HttpContext.get(ctx); final HttpRequestPacket httpRequest = context.getRequest(); keepAliveContextAttr.get(context); httpRequest.getProcessingState().isKeepAlive(); return ctx.getStopAction(); return ctx.getInvokeAction();
final Connection connection = ctx.getConnection(); HttpResponsePacket httpResponse = httpResponseInProcessAttr.get(connection); httpResponseInProcessAttr.set(connection, httpResponse); final HttpRequestPacket request = httpResponse.getRequest(); httpCtx = request.getProcessingState().getHttpContext(); if (httpCtx == null) { httpCtx = HttpContext.newInstance(connection, connection, connection, request); request.getProcessingState().setHttpContext(httpCtx); httpCtx = HttpContext.newInstance(connection, connection, connection, null); httpCtx.attach(ctx); return handleRead(ctx, httpResponse);
boolean checkIfHttp2StreamChain(final FilterChainContext ctx) throws IOException { final Object message = ctx.getMessage(); if (message == null) { // If message == null - it means it's initiated by blocking ctx.read() call // we have to check Http2Stream associated input queue if there are any data we can return // otherwise block until input data is available final Http2Stream http2Stream = (Http2Stream) HttpContext.get(ctx).getContextStorage(); ctx.setMessage(http2Stream.pollInputData()); return true; } final HttpContent httpContent = (HttpContent) message; final HttpHeader httpHeader = httpContent.getHttpHeader(); // if the stream is assigned - it means we process HTTP/2.0 request // in the upstream (HTTP2 stream chain) return Http2Stream.getStreamFor(httpHeader) != null; }
private void sendMoreDataRequestIfNeeded(final FilterChainContext ctx) throws IOException { final Connection connection = ctx.getConnection(); final HttpContext context = HttpContext.get(ctx); // Check if message is still in process if (httpRequestInProcessAttr.isSet(context)) { final MemoryManager mm = connection.getTransport().getMemoryManager(); final Buffer buffer = mm.allocate(7); buffer.put((byte) 'A'); buffer.put((byte) 'B'); buffer.putShort((short) 3); buffer.put(AjpConstants.JK_AJP13_GET_BODY_CHUNK); buffer.putShort(AjpConstants.SUGGESTED_MAX_PAYLOAD_SIZE); buffer.flip(); buffer.allowBufferDispose(true); ctx.write(buffer); } }
void sendMessageUpstreamWithParseNotify(final Http2Stream stream, final HttpContent httpContent) { final FilterChainContext upstreamContext = http2StreamChain.obtainFilterChainContext(connection, stream); final HttpContext httpContext = httpContent.getHttpHeader() .getProcessingState().getHttpContext(); httpContext.attach(upstreamContext); handlerFilter.onHttpContentParsed(httpContent, upstreamContext); final HttpHeader header = httpContent.getHttpHeader(); if (httpContent.isLast()) { handlerFilter.onHttpPacketParsed(header, upstreamContext); } if (header.isSkipRemainder()) { return; } sendMessageUpstream(stream, httpContent, upstreamContext); }
private void commitAndCloseAsError(FilterChainContext ctx, HttpResponsePacket response) { final HttpContent errorHttpResponse = customizeErrorResponse(response); final Buffer resBuf = encodeHttpPacket(ctx, errorHttpResponse); ctx.write(resBuf); response.getProcessingState().getHttpContext().close(); }
@Override public NextAction handleEvent(final FilterChainContext ctx, final FilterChainEvent event) throws IOException { if (event.type() == GracefulCloseEvent.class) { // Connection was closed. // This event is fired only for responses, which don't have // associated transfer-encoding or content-length. // We have to complete such a request-response processing gracefully. final GracefulCloseEvent closeEvent = (GracefulCloseEvent) event; final HttpResponsePacket response = closeEvent.getHttpTxContext().responsePacket; response.getProcessingState().getHttpContext().attach(ctx); onHttpPacketParsed(response, ctx); return ctx.getStopAction(); } return ctx.getInvokeAction(); }
void sendMessageUpstream(final Http2Stream stream, final HttpPacket message) { final FilterChainContext upstreamContext = http2StreamChain.obtainFilterChainContext(connection, stream); final HttpContext httpContext = message.getHttpHeader() .getProcessingState().getHttpContext(); httpContext.attach(upstreamContext); sendMessageUpstream(stream, message, upstreamContext); }
public FileSendEntry(final FilterChainContext ctx, final HttpResponsePacket response, final FileInputStream fis, final FileChannel fc, final long size) { this.ctx = ctx; this.response = response; this.fis = fis; this.fc = fc; this.remaining = size; final HttpContext httpContext = response.getProcessingState().getHttpContext(); assert httpContext != null; output = httpContext.getOutputSink(); }
private void cleanup(final HttpContext httpCtx) { httpCtx.getCloseable().removeCloseListener(listener); REQUEST_STATE_ATTR.remove(httpCtx); }
void sendUpstream(final Http2Session http2Session, final Http2Stream stream, final HttpContent content) { final HttpRequestPacket request = stream.getRequest(); final HttpContext httpContext = HttpContext.newInstance(stream, stream, stream, request); request.getProcessingState().setHttpContext(httpContext); if (threadPool == null) { // mark this thread as a service to let filters upstream know, that // it must not be blocked, because otherwise entire HTTP2 connection // can stall Threads.setService(true); try { http2Session.sendMessageUpstream(stream, content); } finally { Threads.setService(false); } } else { threadPool.execute(new Runnable() { @Override public void run() { http2Session.sendMessageUpstream(stream, content); } }); } }
public void initialize(final Request request, final HttpResponsePacket response, final FilterChainContext ctx, final DelayedExecutor.DelayQueue<SuspendTimeout> delayQueue, final HttpServerFilter serverFilter) { this.request = request; this.response = response; sendFileEnabled = ((serverFilter != null) && serverFilter.getConfiguration().isSendFileEnabled()); outputBuffer.initialize(this, ctx); this.ctx = ctx; this.httpContext = HttpContext.get(ctx); this.delayQueue = delayQueue; }
public static HttpContext newInstance( final AttributeStorage attributeStorage, final OutputSink outputSink, final Closeable closeable, final HttpRequestPacket request) { return new HttpContext(attributeStorage, outputSink, closeable, request); }
public void detach() { final OutputBuffer obLocal = outputBuffer; if (obLocal != null) { outputBuffer = null; // call in the current thread, because otherwise handler executed // in the different thread may deal with recycled Request/Response objects onError0(obLocal, obLocal.httpContext.getCloseable().isOpen() ? new CancellationException() : new EOFException()); } }
if (ctx.getConnection().isOpen()) { final HttpContext context = HttpContext.get(ctx); final HttpRequestPacket httpRequest = context.getRequest(); keepAliveContextAttr.get(context); httpRequest.getProcessingState().isKeepAlive(); return ctx.getStopAction(); return ctx.getInvokeAction();
final Connection connection = ctx.getConnection(); HttpResponsePacket httpResponse = httpResponseInProcessAttr.get(connection); httpResponseInProcessAttr.set(connection, httpResponse); final HttpRequestPacket request = httpResponse.getRequest(); httpCtx = request.getProcessingState().getHttpContext(); if (httpCtx == null) { httpCtx = HttpContext.newInstance(connection, connection, connection, request); request.getProcessingState().setHttpContext(httpCtx); httpCtx = HttpContext.newInstance(connection, connection, connection, null); httpCtx.attach(ctx); return handleRead(ctx, httpResponse);
boolean checkIfHttp2StreamChain(final FilterChainContext ctx) throws IOException { final Object message = ctx.getMessage(); if (message == null) { // If message == null - it means it's initiated by blocking ctx.read() call // we have to check Http2Stream associated input queue if there are any data we can return // otherwise block until input data is available final Http2Stream http2Stream = (Http2Stream) HttpContext.get(ctx).getContextStorage(); ctx.setMessage(http2Stream.pollInputData()); return true; } final HttpContent httpContent = (HttpContent) message; final HttpHeader httpHeader = httpContent.getHttpHeader(); // if the stream is assigned - it means we process HTTP/2.0 request // in the upstream (HTTP2 stream chain) return Http2Stream.getStreamFor(httpHeader) != null; }