web-dev-qa-db-ja.com

RESTEASY003145:content-type application / jsonおよびtype class org.keycloak.representations.AccessTokenResponseのMessageBodyReaderが見つかりません

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>

手がかりはありますか?

解決しました!! org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProviderをMETA-INF/services/javax.ws.rs.ext.Providersファイルに追加して、実行可能なjarを実行する必要があります。

7
MatteoM

この問題を修正するために依存関係を使用しました

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

または、プロキシを使用してクライアントを作成する場合は、前にプロバイダーファクトリを初期化することをお勧めします。

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

Dmitryがここで指摘した を追加すると、次の警告が表示されます。

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

おそらく ベーコンが言ったように 依存関係を追加するだけでプロバイダーは自動的に登録されます:

    <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson2-provider</artifactId>
        <version>${resteasy.version}</version>
    </dependency>
1
Igorski

MatteoM が指摘する問題がありました。私はmaven-shade-pluginとtransformesタグで解決しました。多分それは誰かを助ける。

 <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>
0
Torsten