nih-gov/www.nlm.nih.gov/vsac/support/usingvsac/SVS-Client-Java.html
2025-02-26 13:17:41 -05:00

377 lines
15 KiB
HTML

<!DOCTYPE html><html lang="en">
<head>
<meta name="title" property="og:title" content="SVS Client Java Example">
<meta name="type" property="og:type" content="website">
<meta name="image" property="og:image" content="https://www.nlm.nih.gov/images/NLMgeneric.jpg">
<meta name="image:alt" property="og:image:alt" content="National Library of Medicine (NLM)">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@NLM_NIH">
<meta name="twitter:title" content="SVS Client Java Example">
<meta name="twitter:image" content="https://www.nlm.nih.gov/images/NLMgeneric.jpg">
<meta name="twitter:image:alt" content ="National Library of Medicine (NLM)">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<link rel="stylesheet" href="/home_assets/v5/css/nlm_main.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,500,500i,700,900" rel="stylesheet">
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" title="The Dublin Core metadata Element Set" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" integrity="sha384-+d0P83n9kaQMCwj8F4RJB66tzIwOKmrdb46+porD/OvrJ+37WqIM7UoBtwHO6Nlg" crossorigin="anonymous">
<title>SVS Client Java Example</title>
<link rel="schema.DC" href="http://purl.org/dc/elements/1.1/" title="The Dublin Core metadata Element Set" />
<meta name="DC.Title" content="SVS Client Java Example" />
<meta name="DC.Subject.Keyword" content="SVS client java API VSAC" />
<meta name="DC.Publisher" content="U.S. National Library of Medicine" />
<meta name="DC.Date.Issued" content="2023-09-07" />
<meta name="DC.Date.Modified" content="2023-09-07" />
<meta name="NLMDC.Date.LastReviewed" content="2023-09-07" />
<meta name="NLM.Contact.Email" content="nlmumlscustserv@mail.nlm.nih.gov" />
<meta name="DC.Type" content="Technical Documentation" />
<meta name="NLM.Permanence.Level" content="Permanence Not Guaranteed" />
<meta name="DC.Rights" content="Public Domain" />
<meta name="DC.Language" content="eng" />
<style>
p.normal {
font-weight: normal;
}
</style>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-MT6MLL');</script>
<!-- End Google Tag Manager -->
</head>
<body>
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-MT6MLL" height="0" width="0" style="display:none;visibility:hidden" title="googletagmanager"></iframe></noscript>
<!-- End Google Tag Manager -->
<a class="sr-only sr-only-focusable" href="#skip" title="Skip the navigation on this page">Skip Navigation Bar</a>
<header class="insertheader">
<div class="container-fluid bg-primary">
<div class="container branding">
<div class="row">
<div class="col-xl-4 col-lg-4 col-md-6 col-sm-6 col-9 pb-md-0 pb-2"> <a href="https://www.nlm.nih.gov/"><img src="//www.nlm.nih.gov/images/NLM_White.png" class="img-fluid" alt="NLM logo"></a> </div>
<div class="col-lg-4 offset-lg-4 col-md-6 col-sm-6 col-xs-12 pt-xl-2 pt-lg-1 pt-md-2">
<form method="get" action="//vsearch.nlm.nih.gov/vivisimo/cgi-bin/query-meta" target="_self" name="searchForm" id="searchForm2" class="form-inline mt-4">
<div class="input-group mb-3">
<input type="text" name="query" placeholder="Search NLM" aria-label="Search" class="form-control col-10 ui-autocomplete-input" id="search2" autocomplete="off">
<input type="hidden" name="v:project" value="nlm-main-website">
<button class="btn btn-outline-secondary" type="submit" aria-label="Search NLM" id="button-addon2"><i class="fas fa-search"></i></button>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="container-fluid bg-secondary">
<div class="container ps-0 ps-lg-3">
<nav class="navbar navbar-expand-lg navbar-light">
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> </button>
<div class="collapse navbar-collapse" id="navbarNavDropdown">
<ul class="navbar-nav">
<li class="nav-item dropdown px-xl-5 pr-lg-2 pr-md-0">
<a class="nav-link dropdown-toggle" href="#" id="products_services" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Products and Services </a>
<div class="dropdown-menu ml-xl-5" aria-labelledby="products_services">
<a class="dropdown-item" href="//eresources.nlm.nih.gov/nlm_eresources/">All Products and Services</a>
<a class="dropdown-item" href="//clinicaltrials.gov/">ClinicalTrials.gov</a>
<a class="dropdown-item" href="//collections.nlm.nih.gov/">Digital Collections</a>
<a class="dropdown-item" href="//catalog.nlm.nih.gov">LocatorPlus Catalog</a>
<a class="dropdown-item" href="//meshb.nlm.nih.gov/search">Medical Subject Headings (MeSH)</a>
<a class="dropdown-item" href="//medlineplus.gov/">MedlinePlus</a>
<a class="dropdown-item" href="//pubmed.ncbi.nlm.nih.gov/">PubMed/MEDLINE</a>
<a class="dropdown-item" href="//uts.nlm.nih.gov/uts/">Unified Medical Language System (UMLS)</a>
</div>
</li>
<li class="nav-item dropdown px-xl-5 px-lg-2 px-md-0">
<a class="nav-link dropdown-toggle" href="#" id="resources" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Resources for You </a>
<div class="dropdown-menu ml-xl-3" aria-labelledby="resources">
<a class="dropdown-item" href="https://www.nlm.nih.gov/portals/researchers.html">For Researchers</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/portals/publishers.html">For Publishers</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/portals/librarians.html">For Librarians</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/training.html">For Educators/Trainers </a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/portals/healthcare.html">For Health care Professionals</a>
<a class="dropdown-item" href="//www.nlm.nih.gov/portals/public.html">For the Public</a>
</div>
</li>
<li class="nav-item dropdown px-xl-5 px-lg-2 px-md-0">
<a class="nav-link dropdown-toggle" href="#" id="explore" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Explore NLM </a>
<div class="dropdown-menu" aria-labelledby="explore">
<a class="dropdown-item" href="https://www.nlm.nih.gov/about/index.html">About the Library</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/about/visitor.html">Visit the Library</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/hmd/index.html">History of Medicine</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/about/org.html">NLM by Organization</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/news/newsandevents.html">News, Events, and Updates</a>
</div>
</li>
<li class="nav-item dropdown pl-xl-5 pl-lg-2 px-md-0">
<a class="nav-link dropdown-toggle" href="#" id="grants_research" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Grants and Research </a>
<div class="dropdown-menu" aria-labelledby="grants_research">
<a class="dropdown-item" href="https://www.nlm.nih.gov/ep/index.html">NLM Extramural Programs</a>
<a class="dropdown-item" href="https://www.nlm.nih.gov/research/index.html">NLM Intramural Research Program </a>
<a class="dropdown-item" href="https://www.ncbi.nlm.nih.gov/">National Center for Biotechnology Information </a>
<a class="dropdown-item" href="//lhncbc.nlm.nih.gov/">Lister Hill National Center for Biomedical Communications</a>
</div>
</li>
</ul>
</div>
</nav>
</div>
</div>
</header>
<!-- Begin Div Header Template -->
<!--Start Branding Bar-->
<div class="container-fluid bg-gray a44">
<div id="barbranding">
<div class="container">
<div class="row bg-gray text-white pt-3 pb-2">
<div class="col breadcrumb-brand">
<div class="floating-s">
<h4 class="text-white"> VSAC Support Center</h4>
</div>
<div class="floating-e">
<ul class="ps-0">
<li class="list-inline-item"><a class="text-white" href="/vsac/support/index.html" title="VSAC Support Center Home"><strong>VSAC Support Center Home</strong></a>&nbsp;&nbsp;</li>
</ul></div> <!-- 1 -->
</div> <!-- 2 -->
</div> <!-- 3 --></div><div class="clearfix"></div></div>
</div> <!-- 4 -->
<!--Start BreadCrumb-->
<div id="breadcrumb-div" class="container-fluid">
<div class="container"> <!-- 1 -->
<nav aria-label="breadcrumb">
<ol class="breadcrumb mb-0 mt-2">
<li class="breadcrumb-item"><a href="/index.html" title="National Library of Medicine home page">Home</a></li>
<li class="breadcrumb-item"><a href="/vsac/support/index.html">VSAC Support Center Home</a></li>
</ol>
</nav>
<!-- End BreadCrumb -->
</div> <!-- 5 -->
<!-- End Div Header Template -->
</div> <!-- 7 -->
<main>
<!--Main Body-->
<div id="main-body" class="nlm-blue container">
<a name="skip" id="skipnav"></a>
<div id="body">
<h1>SVS Client Java Example</h1>
<h1>VSAC SVS API Client Java Example</h1>
<p>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.</p>
<pre>
import java.io.IOException;
import java.net.URI;
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 = "https://vsac.nlm.nih.gov/vsac/svs/";
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.setURI(uri);
httpGet.setHeader(HttpHeaders.AUTHORIZATION, basicAuthHeader);
HttpResponse response = client.execute(httpGet);
String responseString = EntityUtils.toString(response.getEntity());
System.out.println(responseString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
</pre>
</div> <!--body-->
<p><small>Last Reviewed: September 7, 2023</small></p>
</div> <!-- End body div -->
</main>
<footer class="bg-primary text-white insertfooter">
<div class="container-fluid">
<div class="container pt-5">
<div class="row mt-3">
<div class="col-md-3 col-sm-6 col-6">
<p><a href="https://www.nlm.nih.gov/socialmedia/index.html" class="text-white">Connect with NLM</a></p>
<ul class="list-inline social_media">
<li class="list-inline-item"><a title="External link: please review our privacy policy." href="https://twitter.com/NLM_NIH"><img src="//www.nlm.nih.gov/images/Twitter_W.svg" class="img-fluid" alt="Twitter"></a></li>
<li class="list-inline-item"><a title="External link: please review our privacy policy." href="https://www.facebook.com/nationallibraryofmedicine"><img src="//www.nlm.nih.gov/images/Facebook_W.svg" class="img-fluid" alt="Facebook"></a></li>
<li class="list-inline-item"><a title="External link: please review our privacy policy." href="https://www.youtube.com/user/NLMNIH"><img src="//www.nlm.nih.gov/images/YouTube_W.svg" class="img-fluid" alt="You Tube"></a></li>
</ul>
</div>
<div class="col-md-3 col-sm-6 col-6">
<p class="address_footer text-white"> National Library of Medicine <br>
<a href="https://www.google.com/maps/place/8600+Rockville+Pike,+Bethesda,+MD+20894/@38.9959508,-77.101021,17z/data=!3m1!4b1!4m5!3m4!1s0x89b7c95e25765ddb:0x19156f88b27635b8!8m2!3d38.9959508!4d-77.0988323" class="text-white"> 8600 Rockville Pike <br>
Bethesda, MD 20894 </a></p>
</div>
<div class="col-md-3 col-sm-6 col-6">
<p><a href="https://www.nlm.nih.gov/web_policies.html" class="text-white"> Web Policies </a><br>
<a href="https://www.nih.gov/institutes-nih/nih-office-director/office-communications-public-liaison/freedom-information-act-office" class="text-white"> FOIA </a><br><a href="https://www.hhs.gov/vulnerability-disclosure-policy/index.html" class="text-white">HHS Vulnerability Disclosure</a></p>
</div>
<div class="col-md-3 col-sm-6 col-6">
<p><a class="supportLink text-white" href="//support.nlm.nih.gov?from="> NLM Support Center </a> <br>
<a href="https://www.nlm.nih.gov/accessibility.html" class="text-white"> Accessibility </a><br>
<a href="https://www.nlm.nih.gov/careers/careers.html" class="text-white"> Careers </a></p>
</div>
</div>
<div class="row">
<div class="col-lg-12">
<p class="mt-2 text-center text-white"> <a class="text-white" href="//www.nlm.nih.gov/">NLM</a> | <a class="text-white" href="https://www.nih.gov/">NIH</a> | <a class="text-white" href="https://www.hhs.gov/">HHS</a> | <a class="text-white" href="https://www.usa.gov/">USA.gov</a></p>
</div>
</div>
</div>
</div>
</footer>
<script src="//assets.nlm.nih.gov/jquery/jquery-latest.min.js"></script>
<script src="//assets.nlm.nih.gov/jquery/jquery-migrate-latest.min.js"></script>
<script src="/home_assets/v5/js/bootstrap.bundle.min.js"></script>
<script src="/scripts/nlm.js"></script>
<script src="/scripts/nlm_autocomplete.js"></script>
</body>
</html>