# How to use quarkus-rest-client-reactive-jackson in a Keycloak custom SPI

**URL:** https://forum.keycloak.org/t/how-to-use-quarkus-rest-client-reactive-jackson-in-a-keycloak-custom-spi/24275
**Category:** Extending the server
**Created:** [January 29, 2024, 5:19pm UTC](https://forum.keycloak.org/t/how-to-use-quarkus-rest-client-reactive-jackson-in-a-keycloak-custom-spi/24275 "2024-01-29T17:19:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jemonra](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@jemonra](https://forum.keycloak.org/u/jemonra)
#### Post date: [January 29, 2024, 5:19pm UTC](https://forum.keycloak.org/t/how-to-use-quarkus-rest-client-reactive-jackson-in-a-keycloak-custom-spi/24275/1 "2024-01-29T17:19:00Z")

</div>

I’m building a Keycloak custom provider (SPI) that adds claims to the access tokens generated by Keycloak. These claims should be obtained by performing external REST API calls. For the REST client I would like to use `quarkus-rest-client-reactive-jackson` because it allows creating REST clients with interfaces (using the `@RegisterRestClient` annotation), which is very fast and easy (actually, this comes from Eclipse Microprofiles). The problem is that when I call some REST endpoint I get the error `Uncaught server error: java.lang.NoClassDefFoundError: org/eclipse/microprofile/rest/client/RestClientBuilder`. I have done some research and it seems that the dependency `quarkus-rest-client-reactive-jackson` is not present in the Keycloak server (that is a Quarkus)… so I have to include it somehow.

The `dependencies` part of my `pom.xml` is the following:

```xml
    <dependencies>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-core</artifactId>
            <scope>provided</scope>
            <version>${keycloak.version}</version>
        </dependency>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-server-spi</artifactId>
            <scope>provided</scope>
            <version>${keycloak.version}</version>
        </dependency>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-server-spi-private</artifactId>
            <scope>provided</scope>
            <version>${keycloak.version}</version>
        </dependency>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-services</artifactId>
            <scope>provided</scope>
            <version>${keycloak.version}</version>
        </dependency>
        <dependency>
            <groupId>org.keycloak</groupId>
            <artifactId>keycloak-model-jpa</artifactId>
            <scope>provided</scope>
            <version>${keycloak.version}</version>
        </dependency>

        <dependency>
            <groupId>jakarta.persistence</groupId>
            <artifactId>jakarta.persistence-api</artifactId>
            <scope>provided</scope>
            <version>3.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>jakarta.json.bind</groupId>
            <artifactId>jakarta.json.bind-api</artifactId>
            <version>3.0.0</version>
        </dependency>
        <dependency>
            <groupId>jakarta.json</groupId>
            <artifactId>jakarta.json-api</artifactId>
            <version>2.1.3</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.quarkus/quarkus-rest-client-reactive-jackson -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-client-reactive-jackson</artifactId>
            <version>3.6.3</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

```

Focus on the last part, the `quarkus-rest-client-reactive-jackson` dependency.

The REST client I’m using (implemented as an interface) is this one:

```java
@RegisterRestClient()
@Path("/my-path")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public interface TokenRestInterface{
    @POST
    @Path("/token")
    TokenDtoResponse getToken(@HeaderParam("User-Id") Integer userId, @FormParam("client_id") String clientId, @FormParam("client_secret") String clientSecret, @FormParam("grant_type") String grantType);
}

```

The part of the code where I call the REST client is the following:

```java
TokenRestInterface tokenRestInterface = null;
try {
    tokenRestInterface = RestClientBuilder.newBuilder().baseUrl(new URL("http://localhost:8080/")).build(TokenRestInterface.class);
} catch (MalformedURLException e) {
    throw new RuntimeException(e);
}
TokenDtoResponse tokenDtoResponse = keycloakRestInterface.getToken(userId, CLIENT_ID, CLIENT_SECRET, "client_credentials");
return tokenDtoResponse.getAccess_token();

```

The error I get when the previous code gets executed is:  
`2023-12-19 11:47:43,443 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-1) Uncaught server error: java.lang.NoClassDefFoundError: org/eclipse/microprofile/rest/client/RestClientBuilder`.

Based on this, I suppose the exception is thrown in the line: `RestClientBuilder.newBuilder()...`.

Note that I included both jars (my provider and the dependency jar) in the `providers` folder of Keycloak.

[![folder of my Keycloak server](https://global.discourse-cdn.com/free1/uploads/keycloak/original/2X/3/368f8d7953d4aa7cf3f99e1e90737a36cffa5c67.png)](https://i.stack.imgur.com/QfYc3.png)

(Note that `metacontratas-keycloak-provider` is the name of my project, my custom Keycloak provider)

Could you please explain to me how to solve this error? This is, do you know how to add correctly the dependency I’m using into the Keycloak service?  
Thanks!

---

<div class="post-metadata">

### Author: ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)
#### Post date: [January 29, 2024, 5:20pm UTC](https://forum.keycloak.org/t/how-to-use-quarkus-rest-client-reactive-jackson-in-a-keycloak-custom-spi/24275/2 "2024-01-29T17:20:17Z")

</div>

I filed a bug, and the issue is discussed here:

> <https://github.com/keycloak/keycloak/issues/25589>
>
> \### Before reporting an issue
> 
> \- \[X\] I have read and understood the above terms …for submitting issues, and I understand that my issue may be closed without action if I do not follow them.
> 
> \### Area
> 
> admin/client/java
> 
> \### Describe the bug
> 
> Sometimes extensions include the use of \`keycloak-admin-client\`, which depends on \`resteasy-jackson2-provider\`. \>=23, after the upgrade to resteasy reactive, this seems to cause a build problem 
> 
> \### Version
> 
> 23
> 
> \### Expected behavior
> 
> This should allow the \`resteasy-jackson2-provider\` jar to be included in the \`providers/\` dir.
> 
> \### Actual behavior
> 
> \`\`\`
> \#0 3.859 Caused by: java.lang.NullPointerException: Cannot invoke "org.jboss.jandex.ClassInfo.name()" because "currentClazz" is null
> \#0 3.859 at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor.createTypedAnnotationInstance(ResteasyReactiveProcessor.java:850)
> \#0 3.859 at io.quarkus.resteasy.reactive.server.deployment.ResteasyReactiveProcessor$6.transform(ResteasyReactiveProcessor.java:832)
> \#0 3.859 at io.quarkus.arc.processor.AnnotationStore.transform(AnnotationStore.java:108)
> \#0 3.859 at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1740)
> \#0 3.859 at io.quarkus.arc.processor.AnnotationStore.getAnnotations(AnnotationStore.java:61)
> \#0 3.859 at io.quarkus.arc.processor.AnnotationStore.hasAnnotation(AnnotationStore.java:85)
> \#0 3.859 at io.quarkus.arc.processor.BeanDeployment.isVetoed(BeanDeployment.java:1277)
> \#0 3.859 at io.quarkus.arc.processor.BeanDeployment.findBeans(BeanDeployment.java:1000)
> \#0 3.859 at io.quarkus.arc.processor.BeanDeployment.registerBeans(BeanDeployment.java:271)
> \#0 3.859 at io.quarkus.arc.processor.BeanProcessor.registerBeans(BeanProcessor.java:141)
> \#0 3.859 at io.quarkus.arc.deployment.ArcProcessor.registerBeans(ArcProcessor.java:419)
> \#0 3.859 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> \#0 3.859 at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
> \#0 3.859 at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> \#0 3.859 at java.base/java.lang.reflect.Method.invoke(Method.java:568)
> \#0 3.859 at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:864)
> \#0 3.860 at io.quarkus.builder.BuildContext.run(BuildContext.java:282)
> \#0 3.860 at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
> \#0 3.860 at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
> \#0 3.860 at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
> \#0 3.860 at java.base/java.lang.Thread.run(Thread.java:840)
> \#0 3.860 at org.jboss.threads.JBossThread.run(JBossThread.java:501)
> \`\`\`
> 
> \### How to Reproduce?
> 
> Create a \`Dockerfile\` that extends the base image with the \`resteasy-jackson2-provider\` jar in the \`providers/\` dir and then runs \`build\`.
> 
> \`\`\`
> COPY ./org.jboss.resteasy-resteasy-jackson2-provider-6.2.4.Final.jar /opt/keycloak/providers/
> 
> RUN /opt/keycloak/bin/kc.sh --verbose build
> \`\`\`
> 
> 
> 
> \### Anything else?
> 
> Already noticed here https://github.com/keycloak/keycloak/discussions/25265
> 
> Tried on \`nightly\`.

There is a workaround, but it is not ideal.

---

<div class="post-metadata">

### Author: ![jemonra](https://avatars.discourse-cdn.com/v4/letter/j/d9b06d/32.png) [@jemonra](https://forum.keycloak.org/u/jemonra)
#### Post date: [January 30, 2024, 7:18am UTC](https://forum.keycloak.org/t/how-to-use-quarkus-rest-client-reactive-jackson-in-a-keycloak-custom-spi/24275/3 "2024-01-30T07:18:39Z")

</div>

> [@xgp](#):
>
> I filed a bug, and the issue is discussed here:

But the issue you are mentioning is related to RestEasy Classic (not reactive), right? I’m referring to RestEasy Reactive which is contained by `quarkus-rest-client-reactive-jackson` (Quarkus RESTEasy Reactive’s REST Client Jackson).

---

<div class="post-metadata">

### Author: ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)
#### Post date: [January 30, 2024, 7:42am UTC](https://forum.keycloak.org/t/how-to-use-quarkus-rest-client-reactive-jackson-in-a-keycloak-custom-spi/24275/4 "2024-01-30T07:42:40Z")

</div>

Yes, however, I think both are effected in the same way. You have to custom build it in order to get it loaded. I’d suggest trying to add the dependency into ` quarkus/deployment/pom.xml` and `quarkus/runtime/pom.xml` as indicated in the discussion and seeing if that works for your use case.
