RESTEASY003145: Unable to find a MessageBodyReader of content-type application/json and type class org.keycloak.representations.AccessTokenResponse

前端 未结 6 1448
滥情空心
滥情空心 2020-12-20 12:45

I\'m trying to test Keycloak REST API. Instaled the version 2.1.0.Final. I can access the admin through browser with SSL without problems.

I\'m using the code above:

相关标签:
6条回答
  • 2020-12-20 12:59

    I had the problem, that MatteoM pointed out. I solved with maven-shade-plugin and the transformes tag. Maybe it helps someone.

     <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 讨论(0)
  • 2020-12-20 13:04

    Or if you create client with proxy then better to initialize provider factory before:

        ResteasyProviderFactory instance=ResteasyProviderFactory.getInstance();
        RegisterBuiltin.register(instance);
        instance.registerProvider(ResteasyJackson2Provider.class);
    
    0 讨论(0)
  • Adding what Dmitry pointed out here for me causes the following warning:

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

    Probably as Bacon said the provider is automatically registered by simply adding the dependency:

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <version>${resteasy.version}</version>
        </dependency>
    
    0 讨论(0)
  • 2020-12-20 13:14

    I solved !! You must add org.jboss.resteasy.plugins.providers.jackson.ResteasyJacksonProvider into META-INF/services/javax.ws.rs.ext.Providers file then run your executable jar.

    0 讨论(0)
  • 2020-12-20 13:20

    On a wildfly 11 / Keycloak context, the following made it work with the RestEasyClientBuilder.

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

    Double check if ResteasyProviderFactory defaults to true with your Resteasy version. If not, set the builtIns manually:

    ResteasyProviderFactory.setRegisterBuiltinByDefault(true);
    // or if ResteasyProviderFactory was already instantiated
    RegisterBuiltin.register(providerFactory);
    
    0 讨论(0)
  • 2020-12-20 13:22

    I used the dependency to fix this issue

       <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jackson2-provider</artifactId>
            <version>3.1.0.Final</version>
        </dependency>
    
    0 讨论(0)
提交回复
热议问题