I am unable to get request body from this HttpAsyncRequestProducer
of org.apache.http.nio.protocol
.
I also want to read the request body multiple times.
My Usecase:
I am intercepting execute method of InternalHttpAsyncClient
of org.apache.http.impl.nio.client
(which has an argument called HttpAsyncRequestProducer
) using Bytebuddy and trying to capture request and response and save it.
Since ElasticSearch using High level rest-client is ultimately using this client's method only. So, for this purpose I want to read the request body multiple times.
public <T> Future<T> execute(HttpAsyncRequestProducer requestProducer, HttpAsyncResponseConsumer<T> responseConsumer, HttpContext context, FutureCallback<T> callback) {
this.ensureRunning();
BasicFuture<T> future = new BasicFuture(callback);
HttpClientContext localcontext = HttpClientContext.adapt((HttpContext)(context != null ? context : new BasicHttpContext()));
this.setupContext(localcontext);
DefaultClientExchangeHandlerImpl<T> handler = new DefaultClientExchangeHandlerImpl(this.log, requestProducer, responseConsumer, localcontext, future, this.connmgr, this.connReuseStrategy, this.keepaliveStrategy, this.exec);
try {
handler.start();
} catch (Exception var9) {
handler.failed(var9);
}
return new FutureWrapper(future, handler);
}
Above is the actual method i am intercepting with the below interceptor.
@RuntimeType
public static Future<Object> doProceed(@Origin Method method, @SuperCall Callable<Future<Object>> callable, @AllArguments Object[] args) throws Exception {
System.out.println("Inside ElasticSearchInterceptor");
System.out.println("ElasticSearchInterceptor: Method-> " + method);
int i = 0;
for (Object obj : args) {
System.out.println("Argument[" + i + "]: " + obj);
i++;
}
HttpAsyncRequestProducer requestProducer = (HttpAsyncRequestProducer) args[0];
// how to read the request body?????
HttpRequest httpRequest = requestProducer.generateRequest();
System.out.println("ElasticSearchInterceptor: Request Headers-> " + Arrays.toString(httpRequest.getAllHeaders()));
System.out.println("ElasticSearchInterceptor: Before call");
Future<Object> call = callable.call();
HttpResponse res = (HttpResponse) call.get();
System.out.println("Response in elastic search " + res);
System.out.println("ElasticSearchInterceptor: After call");
return call;
}
Any help would be appreciated.