# Implementing Use Cases
source: https://developer.mastercard.com/commercial-event-notifications/documentation/use_cases/implement-use-case/index.md

### Implementing the Use Cases {#implementing-the-use-cases}

You can build your own application to implement these use cases using the [OpenAPI Generator](https://openapi-generator.tech/) and the OpenAPI Specification (OAS3) file for Commercial Event Notifications, available
on the [API Reference](https://developer.mastercard.com/commercial-event-notifications/documentation/parameters/index.md) page (see the "Open Specification" link).

OpenAPI Generator provides generators and library templates for supporting multiple languages and frameworks. For more details of how to do this, see these
[detailed instructions](https://developer.mastercard.com/platform/documentation/security-and-authentication/generating-and-configuring-a-mastercard-api-client/),
which use another Mastercard API as an example. You can apply the same steps to the Commercial Event Notifications API.

Mastercard also provides a Commercial Event Notifications reference application written in Java and a [tutorial](https://developer.mastercard.com/commercial-event-notifications/documentation/reference_application_tutorial/index.md), which enables you to download, configure,
build and run the application and execute the use cases described here. The reference application uses the OpenAPI Generator and the OAS3 file as described above.

To assist your implementation work, the use case details in the following pages include Java code snippets to implement each use case.

### Before You Start {#before-you-start}

Before executing any API calls, you need to configure your application with your OAuth credentials and with the URL of the Commercial Event Notifications Sandbox environment.
You then initialize the API client as shown below before making the individual API calls.

The following Java code shows these steps.

```java
// credential information from the Mastercard developers
String consumerKey = "<Your Consumer Key>";
String signingKeyAlias = "keyalias";
String signingKeyPassword = "keystorepassword";
String signingKeyPkcs12FilePath = "<path to the keystorefile>";


// Load the signer key provided by the OAuth1 Signer lib
PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyPkcs12FilePath, signingKeyAlias, signingKeyPassword);


//Initialize the API Client
ApiClient client = new ApiClient();
client.setBasePath(" https://sandbox.api.mastercard.com/commercial-event-notifications");
List<Interceptor> interceptors = client.getHttpClient().networkInterceptors();
interceptors.add(new ForceJsonResponseInterceptor()); // Without this, the gateway would return an XML response
interceptors.add(new OkHttp2OAuth1Interceptor(consumerKey, signingKey));

/**
 * Add "Format=JSON" to the request for the service/gateway to return a JSON response.
 */
private static class ForceJsonResponseInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request originalRequest = chain.request();
        String withJsonFormatUrl = withJsonFormat(originalRequest.uri().toString());
        Request newRequest = originalRequest.newBuilder().url(withJsonFormatUrl).build();
        return chain.proceed(newRequest);
    }
    private String withJsonFormat(String uri) {
        StringBuilder newUri = new StringBuilder(uri);
        newUri.append(uri.contains("?") ? "&" : "?");
        newUri.append("Format=JSON");
        return newUri.toString();
    }
}
```

