Source:
private void handlePublishAsynchronously(HttpServletRequest request, HttpServletResponse response, Topic topic, String messageId) throws IOException { final MessageState messageState = new MessageState(); final AsyncContext asyncContext = request.startAsync(); final HttpResponder httpResponder = new HttpResponder(trackers, messageId, response, asyncContext, topic, errorSender, messageState, request.getRemoteHost()); asyncContext.addListener(new TimeoutAsyncListener(httpResponder, messageState)); asyncContext.addListener(new MetricsAsyncListener(hermesMetrics, topic.getName(), topic.getAck())); asyncContext.setTimeout(topic.isReplicationConfirmRequired() ? longAsyncTimeout : defaultAsyncTimeout); new MessageReader(request, chunkSize, topic.getName(), hermesMetrics, messageState, messageContent -> asyncContext.start(() -> { try { System.out.println("XXX READ XXX"); Message message = contentTypeEnforcer.enforce(request.getContentType(), new Message(messageId, messageContent, clock.getTime()), topic); System.out.println("XXX CHECKED XXX"); messageValidators.check(topic, message.getData()); asyncContext.addListener(new BrokerTimeoutAsyncListener(httpResponder, message, topic, messageState, listeners)); System.out.println("XXX PUBLISHING XXX"); messagePublisher.publish(message, topic, messageState, listeners, new AsyncContextExecutionCallback(asyncContext, new MessageStatePublishingCallback(messageState), new HttpPublishingCallback(httpResponder), new MetricsPublishingCallback(hermesMetrics, topic), new BrokerListenersPublishingCallback(listeners))); } catch (InvalidMessageException exception) { httpResponder.badRequest(exception); } catch (ConvertingException exception) { httpResponder.badRequest(exception, "Converting exception"); } }), input -> httpResponder.badRequest(input, "Validation error"), throwable -> httpResponder.internalError(throwable, "Error while reading request")); }

Target:
private void handlePublishAsynchronously(HttpServletRequest request, HttpServletResponse response, Topic topic, String messageId) throws IOException { final MessageState messageState = new MessageState(); final AsyncContext asyncContext = request.startAsync(); final HttpResponder httpResponder = new HttpResponder(trackers, messageId, response, asyncContext, topic, errorSender, messageState, request.getRemoteHost()); asyncContext.addListener(new TimeoutAsyncListener(httpResponder, messageState)); asyncContext.addListener(new MetricsAsyncListener(hermesMetrics, topic.getName(), topic.getAck())); asyncContext.setTimeout(topic.isReplicationConfirmRequired() ? longAsyncTimeout : defaultAsyncTimeout); new MessageReader(request, chunkSize, topic.getName(), hermesMetrics, messageState, messageContent -> asyncContext.start(() -> { try { Message message = contentTypeEnforcer.enforce(request.getContentType(), new Message(messageId, messageContent, clock.getTime()), topic); messageValidators.check(topic, message.getData()); message = metadataAddingMessageConverter.addMetadata(message, topic); asyncContext.addListener(new BrokerTimeoutAsyncListener(httpResponder, message, topic, messageState, listeners)); messagePublisher.publish(message, topic, messageState, listeners, new AsyncContextExecutionCallback(asyncContext, new MessageStatePublishingCallback(messageState), new HttpPublishingCallback(httpResponder), new MetricsPublishingCallback(hermesMetrics, topic), new BrokerListenersPublishingCallback(listeners))); } catch (InvalidMessageException exception) { httpResponder.badRequest(exception); } catch (ConvertingException exception) { httpResponder.badRequest(exception, "Converting exception"); } }), input -> httpResponder.badRequest(input, "Validation error"), throwable -> httpResponder.internalError(throwable, "Error while reading request")); }