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:
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>
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);
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>
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.
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);
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>