Skip to main content
Version: v1.0.x

Java Jersey REST APIs

As an API developer, use this guide to onboard your Java Jersey REST API service into the Zowe API Mediation Layer. This article outlines a step-by-step process to make your API service available in the API Mediation Layer.

The following procedure is an overview of steps to onboard a Java Jersey REST API application with the API Mediation Layer.

Follow these steps:

  1. Get enablers from the Artifactory

  2. Externalize parameters

  3. Download Apache Tomcat and enable SSL

  4. Run your service

Get enablers from the Artifactory#

The first step to onboard a Java Jersey REST API into the Zowe ecosystem is to get enabler annotations from the Artifactory. Enablers prepare your service for discovery and for the retrieval of Swagger documentation.

You can use either Gradle or Maven build automation systems.

Gradle guide#

Use the following procedure if you use Gradle as your build automation system.

Tip: To migrate from Maven to Gradle, go to your project directory and run gradle init. This converts the Maven build to a Gradle build by generating a setting.gradle file and a build.gradle file.

Follow these steps:

  1. Create a file in the root of your project.

  2. In the file, set the following URL of the repository and customize the values of your credentials to access the repository.

    # Repository URL for getting the enabler-jersey artifact (`integration-enabler-java`)

    This file specifies the URL for the repository of the Artifactory. The enabler-jersey artifact is downloaded from this repository.

  3. Add the following Gradle code block to the build.gradle file:

    ext.mavenRepository = {
    maven {
    url artifactoryMavenSnapshotRepo
    repositories mavenRepositories

    The ext object declares the mavenRepository property. This property is used as the project repository.

  4. In the same build.gradle file, add the following code to the dependencies code block to add the enabler-jersey artifact as a dependency of your project:

    compile(group: '', name: 'mfaas-integration-enabler-java', version: '0.2.0')
  5. In your project directory, run the gradle build command to build your project.

Maven guide#

Use the following procedure if you use Maven as your build automation system.

Tip: To migrate from Gradle to Maven, go to your project directory and run gradle install. This command automatically generates a pom-default.xml inside the build/poms subfolder where all of the dependencies are contained.

Follow these steps:

  1. Add the following xml tags within the newly created pom.xml file:


    This file specifies the URL for the repository of the Artifactory where you download the enabler-jersey artifact.

  2. In the same file, copy the following xml tags to add the enabler-jersey artifact as a dependency of your project:

  3. Create a settings.xml file and copy the following xml code block which defines the credentials for the Artifactory:

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns=""
  4. Copy the settings.xml file inside ${user.home}/.m2/ directory.

  5. In the directory of your project, run the mvn package command to build the project.

Externalize parameters#

In order to externalize parameters, you have to create a ServletContextListener. To create your own ServletContextListener, register a ServletContextListener and enable it to read all the properties defined inside the .yml file.

Follow these steps:

  1. Define parameters that you want to externalize in a .yml file. Ensure that this file is placed in the WEB-INF folder located in the module of your service. Check the class inside package in the integration-enabler-java to see the mapped parameters and make sure that the yml file follows the correct structure. The following example shows the structure of the 'yml' file:

    verifySslCertificatesOfServices: true
    protocol: TLSv1.2
    keyAlias: localhost
    keyPassword: password
    keyStore: ../keystore/localhost/localhost.keystore.p12
    keyStorePassword: password
    keyStoreType: PKCS12
    trustStore: ../keystore/localhost/localhost.truststore.p12
    trustStorePassword: password
    trustStoreType: PKCS12
    - gatewayUrl:
    - gatewayUrl:
    - gatewayUrl:
    - gatewayUrl:
  2. Before the web application is started (Tomcat), create a ServletContextListener to run the defined code.

    import javax.servlet.ServletContextEvent;
    import javax.servlet.ServletContextListener;
    public class ApiDiscoveryListener implements ServletContextListener {
    private ApiMediationClient apiMediationClient;
    public void contextInitialized(ServletContextEvent sce) {
    apiMediationClient = new ApiMediationClientImpl();
    String configurationFile = "/service-configuration.yml";
    ApiMediationServiceConfig config = new ApiMediationServiceConfigReader(configurationFile).readConfiguration();
    public void contextDestroyed(ServletContextEvent sce) {
  3. Register the listener. Use one of the following two options:

    • Add the @WebListener annotation to the servlet.

    • Reference the listener by adding the following code block to the deployment descriptor web.xml.



Download Apache Tomcat and enable SSL#

To run Helloworld Jersey, requires the nstallation of Apache Tomcat. As the service uses HTTPS, configure Tomcat to use SSL/TLS protocol.

Follow these steps:

  1. Download Apache Tomcat 8.0.39 and install it.

  2. Build Helloworld Jersey through IntelliJ or by running gradlew helloworld-jersey:build in the terminal.

  3. Enable HTTPS for Apache Tomcat. There are few additional steps to enable HTTPS for Apache Tomcat.

    a) Go to the apache-tomcat-8.0.39-windows-x64\conf directory

    Note: (the full path depends on where you decided to install Tomcat)

    b) Open the server.xml file with a text editor as Administrator and add the following xml block:

    <Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
    maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    Be also sure to comment the HTTP connector which uses the same port.

    c) Navigate to the WEB-INF/ located in helloworld-jersey module and add the following xml block to the web.xml file. This should be added right below the <servlet-mapping> tag:

    <web-resource-name>Protected resource</web-resource-name>

Run your service#

After you externalize the parameters to make them readable through Tomcat and enable SSL, you are ready to run your service in the APIM Ecosystem.

Note: The following procedure uses localhost testing.

Follow these steps:

  1. Run the following services to onboard your application:

    Tip: For more information about how to run the API Mediation Layer locally, see Running the API Mediation Layer on Local Machine.

    • Gateway Service
    • Discovery Service
    • API Catalog Service
  2. Run gradlew tomcatRun with these additional parameters:"<your-project-directory>\api-layer\keystore\localhost\localhost.truststore.p12""password". If you need some more information about SSL configuration status while deploying, use this parameter

    Tip: Wait for the services to be ready. This process may take a few minutes.

  3. Navigate to following URL:


    Enter eureka as a username and password as a password and check if the service is registered to the discovery service.

    Go to the following URL to reach the API Catalog through the Gateway (port 10010) and check if the API documentation of the service is retrieved:


    You successfully onboarded your Java Jersey application if see your service running and can access the API documentation.