Update custom rest endpoint documentation and example
Add a mention about beans.xml and @Provider in the extending server documentation Add beans.xml in the rest provider example Add a mention about @Provider in the upgrading guides Closes #25882 Signed-off-by: zak905 <zakaria.amine88@gmail.com> Address suggested change for docs/documentation/server_development/topics/extensions.adoc Co-authored-by: Pedro Igor <pigor.craveiro@gmail.com> Address suggested change for docs/documentation/server_development/topics/extensions.adoc Co-authored-by: Pedro Igor <pigor.craveiro@gmail.com> Signed-off-by: zak905 <zakaria.amine88@gmail.com> Address suggested change for docs/documentation/upgrading/topics/keycloak/changes-22_0_0.adoc Co-authored-by: Pedro Igor <pigor.craveiro@gmail.com> Signed-off-by: zak905 <zakaria.amine88@gmail.com>
This commit is contained in:
parent
4d9f33efe3
commit
c7db7bd528
4 changed files with 7 additions and 11 deletions
|
@ -25,6 +25,9 @@ Object getResource();
|
|||
----
|
||||
|
||||
Use this method to return an object, which acts as a https://github.com/jax-rs[JAX-RS Resource]. For more details, see the Javadoc and our examples.
|
||||
Your JAX-RS resource is only recognized by the server and registered as a valid endpoint if it includes the following configuration:
|
||||
- adding an empty file named `beans.xml` under `META-INF`
|
||||
- annotating the JAX-RS class with the annotation `jakarta.ws.rs.ext.Provider`.
|
||||
There is a very simple example in the example distribution in `providers/rest` and there is a more advanced example in `providers/domain-extension`,
|
||||
which shows how to add an authenticated REST endpoint and other functionalities like <<_extensions_spi, Adding your own SPI>>
|
||||
or <<_extensions_jpa,Extending the datamodel with custom JPA entities>>.
|
||||
|
|
|
@ -334,6 +334,8 @@ If you are extending the server's REST APIs through the following SPIs:
|
|||
You need to add an empty `META-INF/beans.xml` to the JAR file where your custom providers are packaged. Otherwise, they are not recognized by the server
|
||||
at runtime.
|
||||
|
||||
If you are using `RealmResourceSPI` or `AdminRealmResourceSpi`, another alternative to adding an empty `beans.xml` under `META-INF` is annotating the JAX-RS resource classes with the annotation `jakarta.ws.rs.ext.Provider`.
|
||||
|
||||
You should also make sure your JAX-RS methods are declaring the expected media types for input and output by marking them with the `@Consumes` and `@Produces` annotations, respectively.
|
||||
|
||||
= Deprecated methods from data providers and models
|
||||
|
|
|
@ -1,16 +1,7 @@
|
|||
Example Realm REST Resource provider
|
||||
====================================
|
||||
|
||||
You can deploy as a module by running:
|
||||
You can deploy the provider by running: `mvn package` and dropping the jar under `$KEYCLOAK_HOME/providers`
|
||||
|
||||
$KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add --name=org.keycloak.examples.hello-rest-example --resources=target/hello-rest-example.jar --dependencies=org.keycloak.keycloak-core,org.keycloak.keycloak-server-spi,org.keycloak.keycloak-server-spi-private,javax.ws.rs.api"
|
||||
|
||||
Then registering the provider by editing `standalone/configuration/standalone.xml` and adding the module to the providers element:
|
||||
|
||||
<providers>
|
||||
...
|
||||
<provider>module:org.keycloak.examples.hello-rest-example</provider>
|
||||
</providers>
|
||||
|
||||
Then start (or restart) the server. Once started open http://localhost:8080/auth/realms/master/hello and you should see the message _Hello master_.
|
||||
Once started open http://localhost:8080/auth/realms/master/hello and you should see the message _Hello master_.
|
||||
You can also invoke the endpoint for other realms by replacing `master` with the realm name in the above url.
|
||||
|
|
Loading…
Reference in a new issue