Java RESTful Services

This feature enables support for Java API for RESTful Web Services v2.1. JAX-RS annotations can be used to define web service clients and endpoints that comply with the REST architectural style. Endpoints are accessed through a common interface that is based on the HTTP standard methods.

Enabling this feature

To enable the Java RESTful Services 2.1 feature, add the following element declaration into your server.xml file, inside the featureManager element:



Access security details with a context object

In JAX-RS applications, you can use annotations to add dependency injections of context objects that access information from HTTP requests. Context objects can provide information that is associated with the application such as the specific HTTP request or response, or the application environment. In the following example, the @Context annotation injects the SecurityContext context object in the Java API that provides access to security details, such as user credentials:

SecurityContext sec;

public Set<String> getGroups() {
       Set<String> groups = null;
       Principal user = sec.getUserPrincipal();
       if (user instanceof JsonWebToken) {
                JsonWebToken jwt = (JsonWebToken) user;
                groups= = jwt.getGroups();
       return groups;

To access security details, the SecurityContext context object uses the sec.getUserPrincipal() method that determines the identity of the user that makes the HTTP request. The if statement specifies the JSONWebToken claims that identify the user.

Inject the MicroProfile JWT interface to access application resources

You can inject interfaces in JAX-RS applications to access resources, such as user details. In the following example, the @Inject annotation injects the JsonWebToken interface in the Java API to obtain the jwtPrincipal object that contains details from the MicroProfile JWT that identifies the user:

public class JwtEndpoint {
       private JsonWebToken jwtPrincipal;
       public String getInjectedJWT() {
          return  this.jwtPrincipal.getName();

Feature configuration elements

Features that this feature enables

Supported Java versions

  • JavaSE-1.8

  • JavaSE-11.0

  • JavaSE-15.0

Developing a feature that depends on this feature

If you are developing a feature that depends on this feature, include the following item in the Subsystem-Content header in your feature manifest file.; type="osgi.subsystem.feature"