RESTEASY003145:找不到内容类型 application/json 和类型类 org.keycloak.representations.AccessTokenResponse 的 Mess

Posted

技术标签:

【中文标题】RESTEASY003145:找不到内容类型 application/json 和类型类 org.keycloak.representations.AccessTokenResponse 的 MessageBodyReader【英文标题】:RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse 【发布时间】:2017-02-13 04:28:18 【问题描述】:

我正在尝试测试 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>

有什么线索吗?

【问题讨论】:

你解决了吗?我收到了同样的信息... 你解决了吗? RestEasy - Unable to find MessageBodyReader?的可能重复 【参考方案1】:

就我而言,我将问题的根源追溯到我切换到CompletableFuture这一事实。

使用的客户端版本可能已过时或其他原因,当它在 eclipse 中运行时,从外部可执行文件中它会因此错误而崩溃。

我可能会发布一个修复程序,但可能是:更新库或停止在此库上使用 CompletableFuture。

【讨论】:

或者如果可能的话从 Resteasy 切换到其他东西【参考方案2】:

在 wildfly 11 / Keycloak 上下文中,以下内容使其适用于 RestEasyClientBuilder

ResteasyClientBuilder builder = new ResteasyClientBuilder();
ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
builder.providerFactory(providerFactory);

使用您的 Resteasy 版本仔细检查 ResteasyProviderFactory 是否默认为 true。如果没有,请手动设置内置函数:

ResteasyProviderFactory.setRegisterBuiltinByDefault(true);
// or if ResteasyProviderFactory was already instantiated
RegisterBuiltin.register(providerFactory);

【讨论】:

你用你的第一部分回答拯救了我的一周。非常感谢!【参考方案3】:

我遇到了MatteoM 指出的问题。我用 maven-shade-plugin 和 transforms 标签解决了。也许它可以帮助某人。

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>de.example.MainClass</Main-Class>
                                    <X-Compile-Source-JDK>1.8</X-Compile-Source-JDK>
                                    <X-Compile-Target-JDK>1.8</X-Compile-Target-JDK>
                                </manifestEntries>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/javax.ws.rs.ext.Providers</resource>
                            </transformer>
                        </transformers>
                        <artifactSet/>
                        <outputFile>$project.build.directory/$project.artifactId-$project.version-fat.jar</outputFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

【讨论】:

META-INF/services/javax.ws.rs.ext.Providers 添加变压器工作。【参考方案4】:

为我添加 Dmitry pointed out here 会导致以下警告:

WARN: RESTEASY002155: Provider class org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider is already registered.  2nd registration is being ignored.

可能as Bacon said提供者是通过简单的添加依赖自动注册的:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson2-provider</artifactId>
        <version>$resteasy.version</version>
    </dependency>

【讨论】:

【参考方案5】:

或者,如果您使用代理创建客户端,那么最好在此之前初始化提供程序工厂:

    ResteasyProviderFactory instance=ResteasyProviderFactory.getInstance();
    RegisterBuiltin.register(instance);
    instance.registerProvider(ResteasyJackson2Provider.class);

【讨论】:

【参考方案6】:

我使用依赖来解决这个问题

   <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson2-provider</artifactId>
        <version>3.1.0.Final</version>
    </dependency>

【讨论】:

【参考方案7】:

我解决了!! 您必须将 org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider 添加到 META-INF/services/javax.ws.rs.ext.Providers 文件中,然后运行您的可执行 jar。

【讨论】:

或 org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider 使用maven的时候有解决办法吗? 同样的问题。我已经在 pom 中添加了 resteasy-jackson2-provider 仍然有这个问题。

以上是关于RESTEASY003145:找不到内容类型 application/json 和类型类 org.keycloak.representations.AccessTokenResponse 的 Mess的主要内容,如果未能解决你的问题,请参考以下文章

org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure:找不到响应对象类型的 MessageBodyWriter

RESTEASY003900:找不到公共构造函数 - 我错过了啥?

Kerberos - 找不到适当类型的密钥来解密 AP REP - RC4 与 HMAC

找不到适当类型的密钥来解密 AP REP - AES256 CTS 模式与 HMAC SHA1-96

在 xamarin for ios 上调试时找不到应用程序的有效“aps-environment”权利字符串

仅在发布版本中找不到适用于应用程序的有效“aps-environment”权利字符串