I'm working on a springboot project where I need to intercept outgoing http requests and do something with it. I know we can use ClientHttpRequestInterceptor for the same and it works fine too.
But I need to know the java class type of the request body that is being sent in the http POST/PUT request. Currently this interceptor only provides a byte array representation of the request object. Doc here
Is there any way I can get to know the java class type of request object/body? Or is there any other better way to do this other than using the ClientHttpRequestInterceptor?
Updated code sample:
public class MyInterceptor implements ClientHttpRequestInterceptor {
@Override
public ClientHttpResponse intercept(HttpRequest request,
byte[] body,
ClientHttpRequestExecution execution)
throws IOException {
// Do something before service invocation
// I need to get request body's class type but it is just a byte[] here. And the 'HttpRequest' argument doesn't carry any info related to request class type.
ClientHttpResponse clientHttpResponse = execution.execute(request, body);
// Do something after service invocation
}
}