How to run Java Sample Code for MLE

Highlighted
Visa Employee

How to run Java Sample Code for MLE

In this “How-to” guide, we will show you how to test MLE (Message Level Encryption) enabled APIs using Java.

 

Important Links:

Enable MLE

 

The first step is to enable MLE for the API(s) you are interested in.

 

Login to your Visa Developer Dashboard and go to your project, you should see something like this:

 

2020-11-11_09-45-12.png

 

Enable the APIs for which MLE needs to be active in VDP by toggling the API for which MLE needs to be enforced.

 

In this tutorial, we are going to enable MLE for Funds Transfer API And Query API:

 

2020-11-11_09-46-41.png

 

Get the credentials

On the left side navigation menu of your project, click on “Credentials”.

 

2020-11-11_11-25-10.png

 

Next step we will create a Key-ID by clicking on the Generate Key-ID button.

 

2020-11-11_11-29-02.png

 

Copy the Key-ID for your reference.

The Key-ID looks this: 41d9f2a1-xxxx-4xxx-b40c-a0480c2xxxxx

 

2020-11-11_11-30-49.png

 

The next step is to add a CSR. Click on the link "Add CSR" .   

 

You are prompt to submit a Certificate Signing Request. 

 

2020-11-11_11-32-46.png

 

We have the option to Generate a CSR for me (default) or submit your own. In this example, we will use the Generate a CSR for me (default) and click Confirm button.

 

After submitting the request, you will be prompt to download the Certificate/Copy Private Key. 

 

 

2020-11-11_11-34-26.png

 

After you have downloaded the private key, check the box "I confirm that I've downloaded my certificate key" and click continue. You will see the Status change to "Active".

 

Expand the Key-ID and you will see the Server Encryption Certificate and Client Encryption Certificate. Download both certificates.

2020-11-11_11-36-33.png

To be able to make an API call with MLE, you need to have the following

  • Server Encryption Certificate
  • Key-ID
  • Certificate Private Key

 

How to run Java Sample Code for MLE

 

Step 1 - Create a java maven project

 

You will need to create a maven project and import it to your IDE.

 

 

 

mvn archetype:generate -DgroupId=com.visa -DartifactId=mle-example -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false

 

 

 

Please refer to the below link for creating a java project in maven:

https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

 

Step 2 - Add the following dependencies to your maven pom project.

 

  • Bouncy Castle Library

 

 

<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcpkix-jdk15on</artifactId>
    <version>1.66</version>
</dependency>

 

 

 

  • Nimbus Jose Library

 

 

<dependency>
    <groupId>com.nimbusds</groupId>
    <artifactId>nimbus-jose-jwt</artifactId>
    <version>9.1.2</version>
</dependency>

 

 

 

  • FasterXML Library (Optional) 

 

 

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.11.1</version>
</dependency>

 

 

 

Step 3 - Download the attached PushFundsAndQueryAPIWithMLE.txt file

 

  • Download the PushFundsAndQueryAPIWithMLE.txt and change the extension from .txt to .java
  • Copy it in the src folder of your project

 

Open the Java Class PushFundsAndQueryAPIWithMLE on your IDE and set the below parameters with your own credentials

 

KEYSTORE_PATH = "<YOUR KEYSTORE PATH>";

KEYSTORE_PASSWORD = "<YOUR KEYSTORE PASSWORD>";

 

USER_ID = "<YOUR USER ID>";

PASSWORD = "<YOUR PASSWORD>";

 

MLE_CLIENT_PRIVATE_KEY_PATH = "<YOUR MLE CLIENT PRIVATE KEY PATH>";

MLE_SERVER_PUBLIC_CERTIFICATE_PATH = "<YOUR MLE SERVER PUBLIC CERTIFICATE PATH>";

KEY_ID = "<YOUR KEY ID>";

 

Please refer to the article HelloWorld.java - How to run Java Sample Code using the Hello World API and Mutual SSL of how to create a Java KeyStore.

 

Step 4 - Compile Your Code 

 

  • Simple right click and run 'PushFundsAndQueryAPIWithMLE.main()'.  The IDE will start compiling your code and execute the code.

 

Want more? Join the Visa Developer Community to get alerts on the latest tutorials, guides, and new developer resources. Stay tuned for more in the series.