How to get current requested client URL in annotation interceptor?

42 Views Asked by At

I have a method where I am making an HTTP request through RxHttpClient and there is an annotation on the method. I want to get the URL to which my RxHttpClient instance is trying to connect.

The method is as follows:

@Singleton
public class SampleClient {

    @Inject
    @Client(value = "http://localhost:3002", path = "/sample", configuration = SampleConfiguration.class)
    RxHttpClient httpClient;

    // UrlMetrics is the custom annotation
    @UrlMetrics(metricsKey = "demo.geta")
    public Maybe<JsonNode> getA() {
        return httpClient.exchange(
                HttpRequest.GET("/a"), JsonNode.class
        ).firstElement().map(HttpResponse::body);
    }

The annotation is interceptor is written as follows:

import io.micronaut.aop.MethodInterceptor;
import io.micronaut.aop.MethodInvocationContext;

public class MetricsInterceptor implements MethodInterceptor<Object, Object> {
    @Override
    public Object intercept(MethodInvocationContext<Object, Object> context) {
        // within here I want the url where currently rxhttpClient is requesting
    }
0

There are 0 best solutions below