我正在尝试测试Keycloak REST API。安装了版本2.1.0.Final。我可以通过SSL浏览器访问管理员没有问题。
我使用上面的代码:
Keycloak keycloakClient = KeycloakBuilder.builder()
.serverUrl("https://keycloak.intra.rps.com.br/auth")
.realm("testrealm")
.username("development")
.password("development")
.clientId("admin-cli")
.resteasyClient(new ResteasyClientBuilder().connectionPoolSize(10).build())
.build();
List<RealmRepresentation> rr = keycloakClient.realms().findAll();
并得到了错误:
javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse
javax.ws.rs.client.ResponseProcessingException: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:141)
at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:60)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy20.grantToken(Unknown Source)
at org.keycloak.admin.client.token.TokenManager.grantToken(TokenManager.java:85)
at org.keycloak.admin.client.token.TokenManager.getAccessToken(TokenManager.java:65)
at org.keycloak.admin.client.token.TokenManager.getAccessTokenString(TokenManager.java:60)
at org.keycloak.admin.client.resource.BearerAuthFilter.filter(BearerAuthFilter.java:52)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.invoke(ClientInvocation.java:413)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:102)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy22.findAll(Unknown Source)
at br.com.rps.itsm.sd.SgpKeycloakClient.doGet(SgpKeycloakClient.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:284)
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:263)
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:174)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:793)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.ws.rs.ProcessingException: RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse
at org.jboss.resteasy.core.interception.ClientReaderInterceptorContext.throwReaderNotFound(ClientReaderInterceptorContext.java:42)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.getReader(AbstractReaderInterceptorContext.java:75)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:52)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.aroundReadFrom(GZIPDecodingInterceptor.java:59)
at org.jboss.resteasy.core.interception.AbstractReaderInterceptorContext.proceed(AbstractReaderInterceptorContext.java:55)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readFrom(ClientResponse.java:251)
at org.jboss.resteasy.client.jaxrs.internal.ClientResponse.readEntity(ClientResponse.java:181)
at org.jboss.resteasy.specimpl.BuiltResponse.readEntity(BuiltResponse.java:213)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:105)
我添加了上面的依赖项,但没有解决我的问题:
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.19.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson-provider</artifactId>
<version>3.0.19.Final</version>
</dependency>
有线索吗?
8条答案
按热度按时间4bbkushb1#
我使用依赖关系解决了此问题
a64a0gku2#
我解决了!!你必须添加org.jboss.resteasy.plugins.providers.Jackson. reteasyjacksonProvider到META-INF/services/javax.ws.rs.ext.Providers文件中,然后运行你的可执行文件jar。
csbfibhn3#
或者,如果您使用代理创建客户端,则最好在以下操作之前初始化提供程序工厂:
vd8tlhqk4#
添加Dmitry pointed out here for me会导致以下警告:
as Bacon said提供程序可能通过简单地添加依赖项来自动注册:
46qrfjad5#
MatteoM指出,我遇到了这个问题。我用maven shade插件和transformes标签解决了这个问题。也许它能帮助一些人。
4ngedf3f6#
在wildfly 11 / Keycloak上下文中,下面的代码使其与
RestEasyClientBuilder
一起工作。请仔细检查您的Resteasy版本中
ResteasyProviderFactory
是否默认为true
。如果不是,请手动设置内置:bxpogfeg7#
在我的例子中,我将根本问题追溯到我切换到
CompletableFuture
的事实。使用的客户端版本可能是过时的或什么的,当它在eclipse中工作时,从外部可执行文件中,它会崩溃并出现此错误。
我可能会发布一个修复程序,但它要么是:请更新库或停止在此库上使用CompletableFuture。
aij0ehis8#
在创建目标/客户端时,您是否注册了
@Provider
的示例?我发现您没有。在我的例子中,我从Resteasy 3转移到了Resteasy 4,并且接收到了
text/plain
类型的内容。在Resteasy-jaxrs 3中,我使用了ResteasyJackson2Provider
,它实现了MessageBodyReader
和MessageBodyWriter
,并且成功了。现在,在Resteasy 4中,这个同名类的isReadable()
只接受null
的Content-Type
或包含json
。当我收到text/plain
时,它不再工作。对于阅读纯文本,我建议使用
StringTextStar
。这是Resteasy 4.7.5中的一个新类,看起来很有效。读取inputstream并以字符串形式写入,这正是我所需要的。检查它的impl。我觉得你很好。