How to migrate a custom keycloak provider from resteasy-client
Asked Answered
H

1

6

The custom provider uses code with the resteasy-client like this in keycloak 21:

UriBuilder url = UriBuilder.fromPath(baseURL);
ResteasyClient client = (ResteasyClient) ClientBuilder.newClient();
ResteasyWebTarget target = client.target(url);
this.proxy = target.proxy(MyClientInterface.class);

This fails in Keycloak 25 because the resteasy libraries do no longer exist. I've tried to add the dependency org.jboss.resteasy:resteasy-client:6.2.9.Final but it fails with an error like this:

2024-08-05 11:05:03,822 ERROR [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-5) Uncaught server error: java.lang.ClassCastException: class org.jboss.resteasy.reactive.server.jaxrs.ContainerRequestContextImpl cannot be cast to class org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext (org.jboss.resteasy.reactive.server.jaxrs.ContainerRequestContextImpl and org.jboss.resteasy.core.interception.jaxrs.PostMatchContainerRequestContext are in unnamed module of loader io.quarkus.bootstrap.runner.RunnerClassLoader @51cdd8a)
    at org.jboss.resteasy.plugins.providers.sse.SseEventSinkInterceptor.filter(SseEventSinkInterceptor.java:24)
    at org.jboss.resteasy.reactive.server.handlers.ResourceRequestFilterHandler.handle(ResourceRequestFilterHandler.java:48)
    at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:131)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)
    at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:582)
    at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
    at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
    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:1583)

The keycloak upgrade guide just mentions "Migration will be needed" at https://www.keycloak.org/docs/latest/upgrading/index.html#resteeasy-reactive without providing any details what to do to accomplish this.

How do I migrate my code to Keycloak 25? What code changes are needed? Which dependencies do I have to add to Keycloak?

Hereditary answered 5/8 at 9:17 Comment(4)
One option is might be to use the MicroProfile REST Client API instead of using RESTEasy directly.Justin
I tried it but it lead to errors like ClassCastException in keycloak's internal code. I need some sample code with proper dependencies that really works.Hereditary
After some problems, I preferred to use java.net.http.HttpClient as a workaround.Boomerang
This approach is a reasonable alternative if no real answer can be found.Hereditary
P
0

As a workaround I downgraded the two org.jboss.resteasy artifacts resteasy-jackson2-provider and resteasy-core to version 5.0.9.Final and it works. Seems to be a regression bug between Keycloak and Resteasy.

And I had to register ResteasyJackson2Provider.class in the JAX-RS code:

target.register(ResteasyJackson2Provider.class).request().get()
Phospholipide answered 8/10 at 14:7 Comment(1)
Thanks! This sounds interesting. But I have migrated the code to java.net.http.HttpClient as a workaround and I have dropped the dependency on resteasy-client.Hereditary

© 2022 - 2024 — McMap. All rights reserved.