Getting Started with Visa APIs in Spring Boot

Including how to set up Two-Way SSL authentication

Jenny Xin
3 min readJun 25, 2020

The following tutorial goes over how to set up Two-Way SSL authentication by sending a simple API request to

Configure a Java Key Store

1. Make sure you download the 4 necessary files

  • Private key (can only be downloaded once during the creation of a Visa Developer project)
  • Project Certificate (a)
  • VDP Certificate (b)
  • DigiCert Certificate (c)

2. Follow these steps to generate a JKS file

Remember the password you will create!


Set up a Spring project

1. Initialize a project

Go to and set up the project including the Spring Web dependency

2. Create a class to store incoming data

Create a class to contain the data

package com.example.demo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class Response {
private String message;
public Response() {}
public String getMessage() {
return message;
public void setMessage(String message) {
this.message = message;
public String toString() {
return "Message=" + message;

3. Update main application to fetch data

Add the .jks file and authentication credentials. Remember to update the keystore path and password, as well as user id and password!

package com.example.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.util.ResourceUtils;
public class DemoApplication {
private static final Logger log = LoggerFactory.getLogger(DemoApplication.class); public static void main(String[] args) {, args);
public RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {
SSLContext sslContext = SSLContextBuilder
.loadKeyMaterial(ResourceUtils.getFile("src/main/resources/keyAndCertBundle.jks"), "password".toCharArray(), "password".toCharArray())
.loadTrustMaterial(ResourceUtils.getFile("src/main/resources/keyAndCertBundle.jks"), "password".toCharArray())
HttpClient client = HttpClients.custom()
return builder
.requestFactory(() -> new HttpComponentsClientHttpRequestFactory(client))
.basicAuthentication("INSERT_USER_ID", "INSERT_PASSWORD")
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
Response res = restTemplate.getForObject("", Response.class);;

4. Add dependency in pom.xml

Required to create an HttpClient in the RestTemplate builder


5. Run the application

If authentication is successful, running ./mvnw spring-boot:run should print to the console