Search code examples
javamavenquarkusquarkus-rest-client

java.lang.IllegalArgumentException: Unable to determine the proper baseUrl/baseUri


I'm facing the same issue as mentionned on this link : https://github.com/quarkusio/quarkus/issues/17807)

I'm trying to send a POST request using Quarkus and the Rest Client. My configuration registered in my application.yml does not seem to be binded in my @RegisteredRestClient's annoted interface.

Here a part of my pom.xml :

<properties>
    <compiler-plugin.version>3.8.1</compiler-plugin.version>
    <maven.compiler.release>17</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
    <quarkus.platform.version>2.7.6.Final</quarkus.platform.version>
    <skipITs>true</skipITs>
    <surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>${quarkus.platform.artifact-id}</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-rest-client</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-rest-client-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-config-yaml</artifactId>
    </dependency>

The interface I want to use:

package org.mapstruct.restclient;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.mapstruct.dto.Product;

@Path("/v1")
@RegisterRestClient(configKey= "product-client")
public interface ProductSender {
    
    @POST
    @Path("sendProduct")
    Response sendProduct(Product product);
}

Here is my application.yml:

quarkus:
  http:
    port: 8080
  rest-client:
    product-client:
      url: http://localhost:9090/api
      scope: javax.inject.Singleton 

The full stack trace :

ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-0) HTTP Request to /product/controller/sendProduct failed, error id: 964a05b3-c18e-4412-ae20-5f58a8ecac48-1: org.jboss.resteasy.spi.UnhandledException: java.lang.RuntimeException: Error injecting org.mapstruct.restclient.ProductSender org.mapstruct.service.ProductSenderService.sender
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:105)
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:359)
        at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:519)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
        at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
        at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
        at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:151)
        at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:91)
        at io.quarkus.vertx.core.runtime.VertxCoreRecorder$13.runWith(VertxCoreRecorder.java:545)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
        at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.RuntimeException: Error injecting org.mapstruct.restclient.ProductSender org.mapstruct.service.ProductSenderService.sender
        at org.mapstruct.service.ProductSenderService_Bean.create(Unknown Source)
        at org.mapstruct.service.ProductSenderService_Bean.create(Unknown Source)
        at io.quarkus.arc.impl.RequestContext.getIfActive(RequestContext.java:74)
        at io.quarkus.arc.impl.ClientProxies.getDelegate(ClientProxies.java:27)
        at org.mapstruct.service.ProductSenderService_ClientProxy.arc$delegate(Unknown Source)
        at org.mapstruct.service.ProductSenderService_ClientProxy.sendProductToMySecondApp(Unknown Source)
        at org.mapstruct.controller.ProductController.sendProduct(ProductController.java:51)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
        at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
        at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
        at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
        ... 15 more
Caused by: java.lang.IllegalArgumentException: Unable to determine the proper baseUrl/baseUri. Consider registering using @RegisterRestClient(baseUri="someuri"), @RegisterRestClient(configKey="orkey"), or by adding 'quarkus.rest-client."productSender".url' or 'quarkus.rest-client."productSender".uri' to your Quarkus configuration
        at io.quarkus.restclient.runtime.RestClientBase.configureBaseUrl(RestClientBase.java:294)
        at io.quarkus.restclient.runtime.RestClientBase.create(RestClientBase.java:58)
        at org.mapstruct.restclient.ProductSender_7723bcd3d207234cae80053c1b7d507eb8298d56_Synthetic_Bean.create(Unknown Source)
        at org.mapstruct.restclient.ProductSender_7723bcd3d207234cae80053c1b7d507eb8298d56_Synthetic_Bean.get(Unknown Source)
        at org.mapstruct.restclient.ProductSender_7723bcd3d207234cae80053c1b7d507eb8298d56_Synthetic_Bean.get(Unknown Source)
        at io.quarkus.arc.impl.CurrentInjectionPointProvider.get(CurrentInjectionPointProvider.java:52)
        ... 37 more

I've already tried to use the configKey value as you can see, because mentioning the full name of the class results in the same mistake.

I'm following the guide: https://quarkus.io/guides/rest-client#create-the-configuration

Additionnaly, some conf i use :

mvn -vcommand:

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)
Maven home: C:\Users\****\apache-maven-3.8.5
Java version: 17.0.2, vendor: Oracle Corporation, runtime: C:\Users\****\.jdks\openjdk-17.0.2
Default locale: fr_FR, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

java --version command :

openjdk 17.0.4.1 2022-08-12
OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build 17.0.4.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (build 17.0.4.1+1, mixed mode, sharing)

I am waiting for your questions / answers. Thanks in advance


Solution

  • Solution was my application.yml not correctly written. Here is the solution with the standard MicroProfile Rest Client properties notation:

    quarkus:
      http:
        port: 8080
    
    product-client/mp-rest/url: http://127.0.0.1:9090/api/v1
    product-client/mp-rest/scope: javax.inject.Singleton
    

    product-client being my config key passed as a parameter to my @RegisterRestClient annotation.