1

I am using vert.x extension with Quarkus and I want to subclass the WebClient

@Inject
Vertx vertx;

private CustomWebClient usersApiClient;

@PostConstruct
void initialize() {
    this.usersApiClient = (CustomWebClient) WebClient.create(vertx, new WebClientOptions()....)
}

For now the CustomWebClient is empty and just extends the web client

public class CustomWebClient extends io.vertx.mutiny.ext.web.client.WebClient {

But I get a ClassCastException at runtime (in quarkus:dev for instance)

Caused by: java.lang.ClassCastException: class io.vertx.mutiny.ext.web.client.WebClient
cannot be cast to class xxx.CustomWebClient (io.vertx.mutiny.ext.web.client.WebClient is in
unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @760f1081; 
xxx.CustomWebClient is in unnamed module of loader.
io.quarkus.bootstrap.classloading.QuarkusClassLoader @55be9b4e)

Do I need to register this class in the class loader or something ?

maxday
  • 1,322
  • 1
  • 16
  • 32
  • What makes you think the `WebClient.create()` call will return an instance of your class? I'm no Vert.x expert, but from what I see in your code (and briefly looking at the `io.vertx.mutiny.ext.web.client.WebClient` generated source code), there's no way how `WebClient` could instantiate you class. – Ladicek May 13 '20 at 06:22
  • 1
    Are you sure you need to subclass WebClient? Maybe using some WebClient related components (listener, observers or other similar things) you can get the desidered result. – Luca Basso Ricci May 13 '20 at 10:34
  • Actually I want to perform some header manipulation to each request which will go out. for instance Uni notificationData = usersApiClient.get("/hello").send() .For now I am using HttpRequest request = usersApiClient.get("/hello") then I do header manipulation in the request object and finally I send it with send(). The thing is don't want to do this each time for each query. That's why I am looking for doing this automatically using subclass I want to do an extra step (header manipulation) when instantiating or sending request. Hope this is more clear :) – maxday May 13 '20 at 13:12
  • Does this answer your question? [How can I add an http interceptor to a Quarkus application?](https://stackoverflow.com/questions/56448061/how-can-i-add-an-http-interceptor-to-a-quarkus-application) – Luca Basso Ricci May 14 '20 at 06:31
  • No :/ since it's outgoing traffic, those outgoing request does not go through this kind of interceptors – maxday May 14 '20 at 14:22
  • Maybe https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-2rd-edition/en/part1/chapter12/reader_and_writer_interceptors.html ? – Luca Basso Ricci May 15 '20 at 06:31

0 Answers0