private void processJettyRequest(Request jettyRequest, Response jettyResponse, Callback callback) {
        var context = contextSupplier.get();
        var connector = RequestUtils.getConnector(jettyRequest);
        jettyRequest.setAttribute(JDiscServerConnector.REQUEST_ATTRIBUTE, connector);

        var metricContext = connector.createRequestMetricContext(jettyRequest);
        context.metric().add(MetricDefinitions.NUM_REQUESTS, 1, metricContext);
        context.metric().add(MetricDefinitions.JDISC_HTTP_REQUESTS, 1, metricContext);

        var accessLogEntry = new AccessLogEntry();
        jettyRequest.setAttribute(ATTRIBUTE_NAME_ACCESS_LOG_ENTRY, accessLogEntry);

        if (!SUPPORTED_METHODS.contains(jettyRequest.getMethod().toUpperCase())) {
            Response.writeError(jettyRequest, jettyResponse, callback, HttpStatus.METHOD_NOT_ALLOWED_405);
            return;
        }
        var requestHandler = newRequestHandler(context, accessLogEntry, jettyRequest);
        var metricReporter = new RequestMetricReporter(context.metric(), metricContext, Request.getTimeStamp(jettyRequest));
        var responseWriter = new JettyResponseWriter(jettyRequest, jettyResponse, metricReporter);
        shutdownConnectionGracefullyIfThresholdReached(connector, jettyRequest);
        metricReporter.uriLength(jettyRequest.getHttpURI().getPath().length());

        var requestCompletion = new CompletableFuture<Void>();

        // Create jdisc http request
        ResourceReference requestRef = null;
        HttpRequest jdiscRequest;
        try {
            jdiscRequest = HttpRequestFactory.newJDiscRequest(context.container(), jettyRequest);
            requestRef = References.fromResource(jdiscRequest);
        } catch (Throwable error) {
            // Fail if an exception is thrown when constructing the jdisc request
            requestCompletion.completeExceptionally(error);
            return;
        } finally {
            // Prepare async wiring of request completion (success and failure)
            final var finalRequestRef = requestRef;
            requestCompletion
                    .whenComplete((result, error) -> {
                        if (error != null) {
                            onFailure(metricReporter, responseWriter, jettyRequest, callback, error, context.developerMode(), finalRequestRef);
                        } else {
                            onSuccess(metricReporter, callback, finalRequestRef);
                        }
                    });
        }

        // Invoke request handler
        JettyRequestContentReader contentReader;
        try {
            var requestContentChannel = requestHandler.handleRequest(jdiscRequest, responseWriter);
            contentReader = new JettyRequestContentReader(
                    metricReporter, context.janitor(), jettyRequest, requestContentChannel);
        } catch (Throwable error) {
            // Fail if an exception is thrown when constructing the jdisc request or in the request handler
            requestCompletion.completeExceptionally(error);
            return;
        }

        // Propagate exceptions when either write or read pipeline fails
        var readCompletion = contentReader.readCompletion().exceptionally(error -> {
            requestCompletion.completeExceptionally(error);
            return null;
        });
        var writeCompletion = responseWriter.writeCompletion().exceptionally(error -> {
            requestCompletion.completeExceptionally(error);
            return null;
        });

        // Complete when both request reading and response writing are done
        CompletableFuture.allOf(readCompletion, writeCompletion)
                .whenComplete((result, error) -> {
                    if (error == null) requestCompletion.complete(null);
                });

        // Start content reading
        contentReader.start();
    }
Implementation of a Jetty {@link Handler} that dispatches requests to JDisc's {@link com.yahoo.jdisc.handler.RequestHandler}.

@author bjorncs
container-core/src/main/java/com/yahoo/jdisc/http/server/jetty/JdiscDispatchingHandler.java