Skip Navigation Bar
NLM logo

SVS Client Java Example

VSAC SVS API Client Java Example

This Java example is for Java developers to use and modify when they wish to make a VSAC SVS API call from within their program.

import java.util.Base64;

import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpHeaders;

public class SvsClient {

	public static void main(String[] args) throws IOException {

		String svsServerBase = "";
		String username = "";
		String password = "d4c9d78b-83dc-499e-ae27-947cc00fb438"; // Assign an API key to password

		HttpClient client = HttpClientBuilder.create().build();

		try {
			String valueToEncode = username + ":" + password;
		    String basicAuthHeader =  "Basic " + Base64.getEncoder().encodeToString(valueToEncode.getBytes());		
			String testUrl = svsServerBase + "RetrieveMultipleValueSets";

			HttpGet httpGet = new HttpGet(testUrl);
			URI uri = new URIBuilder(httpGet.getURI()).addParameter("id", "2.16.840.1.113762.1.4.1029.256").build(); // VSAC OID example
			httpGet.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader);

			HttpResponse response = client.execute(httpGet);
			String responseString = EntityUtils.toString(response.getEntity());

		} catch (Exception e) {

Last Reviewed: September 7, 2023