Keycloak 24 Official Example Rest Endpoints Not Working

Keycloak Rest Example

it is the official rest example.It is not working!

Note: Sorry, new users can upload only one image for each topic.

I reviewed multiple times I tried everything like putting @Provider annotation or using @AutoService(RealmResourceProviderFactory.class). None of them is working.

{
“error”: “Unable to find matching target resource method”,
“error_description”: “For more on this error consult the server log at the debug level.”
}

I spent one week for this. Can you help me?

Did you do this? Starting Keycloak with log level debug, then try again and see what errors are shown in the server log… What is shown there?

You are calling the endpoint with /auth in your context path… Have you configured this in the server explicitly? If not, try to call the endpoint without /auth. If it works and you have the URL from the docs, don’t complain, write an issue/pull request to improve the docs, help the community.


P.S.: Providing source code not through screen shots, but pasted here as text or linking some GitHub repo is easier to read for most people. Large screenshots only fit to large monitors, don’t expect everyone to have the same size as you. Formatting options here are pretty good.

I’ve already enabled debug level log but I cannot understand anything.

Keycloak throws
Error response 404: jakarta.ws.rs.NotFoundException: Unable to find matching target resource method

2024-11-21 17:00:06,623 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (Timer-0) JtaTransactionWrapper end

2024-11-21 17:00:09,295 DEBUG [WebApplicationException] (vert.x-eventloop-thread-7) Restarting handler chain for exception exception: jakarta.ws.rs.NotFoundException: Unable to find matching target resource method

at org.jboss.resteasy.reactive.server.handlers.ClassRoutingHandler.throwNotFound(ClassRoutingHandler.java:233)

at org.jboss.resteasy.reactive.server.handlers.ClassRoutingHandler.handle(ClassRoutingHandler.java:102)

at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:123)

at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)

at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:48)

at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:23)

at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:10)

at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)

at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)

at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:62)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:40)

at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)

at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)

at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)

at io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder$13.handle(ResteasyReactiveRecorder.java:339)

at io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder$13.handle(ResteasyReactiveRecorder.java:332)

at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)

at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)

at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)

at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:68)

at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:37)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$2.handle(HttpServerCommonHandlers.java:86)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$2.handle(HttpServerCommonHandlers.java:69)

at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:147)

at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:123)

at io.vertx.core.impl.ContextImpl.emit(ContextImpl.java:328)

at io.vertx.core.impl.DuplicatedContext.emit(DuplicatedContext.java:166)

at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:174)

at io.vertx.core.net.impl.ConnectionBase.read(ConnectionBase.java:159)

at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:153)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:124)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)

at io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)

at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)

at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)

at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)

at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)

at java.base/java.lang.Thread.run(Thread.java:842)

2024-11-21 17:00:09,297 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (vert.x-eventloop-thread-7) new JtaTransactionWrapper

2024-11-21 17:00:09,297 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (vert.x-eventloop-thread-7) was existing? false

2024-11-21 17:00:09,297 DEBUG [org.keycloak.services.error.KeycloakErrorHandler] (vert.x-eventloop-thread-7) Error response 404: jakarta.ws.rs.NotFoundException: Unable to find matching target resource method

at org.jboss.resteasy.reactive.server.handlers.ClassRoutingHandler.throwNotFound(ClassRoutingHandler.java:233)

at org.jboss.resteasy.reactive.server.handlers.ClassRoutingHandler.handle(ClassRoutingHandler.java:102)

at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:123)

at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:147)

at org.jboss.resteasy.reactive.server.handlers.RestInitialHandler.beginProcessing(RestInitialHandler.java:48)

at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:23)

at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:10)

at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)

at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)

at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:62)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$1.handle(HttpServerCommonHandlers.java:40)

at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)

at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)

at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)

at io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder$13.handle(ResteasyReactiveRecorder.java:339)

at io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder$13.handle(ResteasyReactiveRecorder.java:332)

at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1285)

at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:177)

at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:137)

at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:68)

at io.vertx.ext.web.impl.RouterImpl.handle(RouterImpl.java:37)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$2.handle(HttpServerCommonHandlers.java:86)

at io.quarkus.vertx.http.runtime.options.HttpServerCommonHandlers$2.handle(HttpServerCommonHandlers.java:69)

at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:147)

at io.quarkus.vertx.http.runtime.VertxHttpRecorder$1.handle(VertxHttpRecorder.java:123)

at io.vertx.core.impl.ContextImpl.emit(ContextImpl.java:328)

at io.vertx.core.impl.DuplicatedContext.emit(DuplicatedContext.java:166)

at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:174)

at io.vertx.core.net.impl.ConnectionBase.read(ConnectionBase.java:159)

at io.vertx.core.net.impl.VertxHandler.channelRead(VertxHandler.java:153)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.vertx.core.http.impl.Http1xUpgradeToH2CHandler.channelRead(Http1xUpgradeToH2CHandler.java:124)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)

at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.vertx.core.http.impl.Http1xOrH2CHandler.end(Http1xOrH2CHandler.java:61)

at io.vertx.core.http.impl.Http1xOrH2CHandler.channelRead(Http1xOrH2CHandler.java:38)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)

at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)

at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)

at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)

at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)

at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)

at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)

at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)

at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)

at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)

at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)

at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)

at java.base/java.lang.Thread.run(Thread.java:842)

2024-11-21 17:00:09,300 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (vert.x-eventloop-thread-7) JtaTransactionWrapper rollback

2024-11-21 17:00:09,300 DEBUG [org.keycloak.transaction.JtaTransactionWrapper] (vert.x-eventloop-thread-7) JtaTransactionWrapper end

When I try without auth

http://localhost:8080/realms/master/hello

response:
{
“error”: “HTTP 404 Not Found”,
“error_description”: “For more on this error consult the server log at the debug level.”
}

2024-11-21 17:04:05,586 DEBUG [WebApplicationException] (executor-thread-1) Restarting handler chain for exception exception: jakarta.ws.rs.NotFoundException: HTTP 404 Not Found
at org.keycloak.services.resources.RealmsResource.resolveRealmExtension(RealmsResource.java:272)
at org.keycloak.services.resources.RealmsResource$quarkusrestinvoker$resolveRealmExtension_c7e400748748bf35309bc60d82a4789f2a0e2d02.invoke(Unknown Source)
at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
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:842)

2024-11-21 17:04:05,587 DEBUG [org.keycloak.services.error.KeycloakErrorHandler] (executor-thread-1) Error response 404: jakarta.ws.rs.NotFoundException: HTTP 404 Not Found
at org.keycloak.services.resources.RealmsResource.resolveRealmExtension(RealmsResource.java:272)
at org.keycloak.services.resources.RealmsResource$quarkusrestinvoker$resolveRealmExtension_c7e400748748bf35309bc60d82a4789f2a0e2d02.invoke(Unknown Source)
at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:141)
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:842)

Your file in META-INF/services is named wrong.
Rename it to reflect the full qualified classname of the RestResourceProviderFactory.

Can you tell me where is the typo? It is not correct?

org.keycloak.examples.rest.HelloResourceProviderFactory

I checked the file name from the official example repo and it is different from the factory class name

org.keycloak.services.resource.RealmResourceProviderFactory

I found a debug log

2024-11-22 10:29:45,576 DEBUG [io.quarkus.arc.runtime.BeanContainerImpl] (main) No matching bean found for type class org.keycloak.examples.rest.HelloResourceProvider and qualifiers []. The bean might have been marked as unused and removed during build.

What can be the reason behind of this?

I can only repeat myself and the file name in the example is correct, you have to name it exactly to the same.
The file name must be org.keycloak.services.resource.RealmResourceProviderFactory, the content of the file must be org.keycloak.examples.rest.HelloResourceProviderFactory.
It uses the Service Loader standard in Java.

Sorry, but not fixed :frowning:

You never told us, if you have configured this context path or not, but you are still keeping it in your requests… :man_shrugging:

SOLVED. THANK YOU SO MUCH.

There are two points that I missed.

1: Service file name format or logic is not the same with other providers’ service file name. It’s static and it must be org.keycloak.services.resource.RealmResourceProviderFactory

2: The original example sends request with /auth prefix but it doesn’t mention about the keycloak context. Without custom context there is no need to add /auth or any other prefix.

Thank you so much for your help.