diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java index cfe79e773..5ca4918aa 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/misc/VSACImporter.java @@ -54,8 +54,7 @@ public class VSACImporter extends OIDBasedValueSetImporter { Map errs = new HashMap<>(); FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac"); - fhirToolingClient.setUsername("apikey"); - fhirToolingClient.setPassword(apiKey); + fhirToolingClient.setTimeoutNormal(30000); fhirToolingClient.setTimeoutExpand(30000); diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/ClientUtils.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/ClientUtils.java index 52059fd74..35b3c70f7 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/ClientUtils.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/ClientUtils.java @@ -33,12 +33,10 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URLConnection; -import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -47,7 +45,6 @@ import java.util.concurrent.TimeUnit; import lombok.Getter; import lombok.Setter; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; @@ -93,13 +90,7 @@ public class ClientUtils { @Setter private int timeout = 5000; - @Getter - @Setter - private String username; - @Getter - @Setter - private String password; @Setter @Getter @@ -213,18 +204,6 @@ public class ClientUtils { return unmarshalReference(response, resourceFormat); } - private Iterable getAuthHeaders() { - if (password != null) { - try { - byte[] b = Base64.encodeBase64((username + ":" + password).getBytes("ASCII")); - String b64 = new String(b, StandardCharsets.US_ASCII); - return Arrays.asList(new HTTPHeader[]{new HTTPHeader("Authorization", "Basic " + b64)}); - } catch (UnsupportedEncodingException e) { - } - } - return Collections.emptyList(); - } - public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { if (FhirSettings.isProhibitNetworkAccess()) { throw new FHIRException("Network Access is prohibited in this context"); @@ -318,9 +297,6 @@ public class ClientUtils { Iterable resourceFormatHeaders = getResourceFormatHeaders(httpRequest, format); resourceFormatHeaders.forEach(configuredHeaders::add); - Iterable authHeaders = getAuthHeaders(); - authHeaders.forEach(configuredHeaders::add); - if (headers != null) { headers.forEach(configuredHeaders::add); } diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java index 7460d806c..eafabce2c 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java @@ -110,20 +110,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { initialize(baseServiceUrl); } - public FHIRToolingClient(String baseServiceUrl, String userAgent, String username, String password) - throws URISyntaxException { - preferredResourceFormat = ResourceFormat.RESOURCE_XML; - utils = getClientUtils(); - utils.setUserAgent(userAgent); - utils.setUsername(username); - utils.setPassword(password); - initialize(baseServiceUrl); - } - - - - - public void initialize(String baseServiceUrl) throws URISyntaxException { base = baseServiceUrl; resourceAddress = new ResourceAddress(baseServiceUrl); @@ -592,22 +578,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { utils.setTimeout(timeout); } - public String getUsername() { - return utils.getUsername(); - } - - public void setUsername(String username) { - utils.setUsername(username); - } - - public String getPassword() { - return utils.getPassword(); - } - - public void setPassword(String password) { - utils.setPassword(password); - } - public Parameters getTerminologyCapabilities() { return (Parameters) utils .issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), withVer(getPreferredResourceFormat(), "1.0"), timeoutNormal) diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java index 90c319d71..8e4706409 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java @@ -6,6 +6,7 @@ import java.net.URISyntaxException; import java.util.*; import lombok.Getter; +import lombok.Setter; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.CapabilityStatement; import org.hl7.fhir.dstu3.model.CodeSystem; @@ -68,13 +69,16 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { private CapabilityStatement capabilities; private Client client = new Client(); private List headers = new ArrayList<>(); - private String username; - private String password; + @Setter + @Getter private String userAgent; private EnumSet allowedVersions; + @Setter @Getter private String acceptLanguage; + @Setter private String contentLanguage; + @Getter private int useCount; //Pass endpoint for client - URI @@ -534,21 +538,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { return result == null ? null : (ConceptMap) result.getPayload(); } - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } public long getTimeout() { return client.getTimeout(); @@ -579,15 +568,9 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { headers.forEach(this.headers::add); } - //FIXME should be in ManagedWebAccess? private Iterable generateHeaders(boolean hasBody) { - List headers = new ArrayList<>(); - // Add basic auth header if it exists - if (basicAuthHeaderExists()) { - headers.add(getAuthorizationHeader()); - } // Add any other headers - headers.addAll(this.headers); + List headers = new ArrayList<>(this.headers); if (!Utilities.noString(userAgent)) { headers.add(new HTTPHeader("User-Agent",userAgent)); } @@ -603,40 +586,11 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { return headers; } - public boolean basicAuthHeaderExists() { - return (username != null) && (password != null); - } - - public HTTPHeader getAuthorizationHeader() { - String usernamePassword = username + ":" + password; - String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes()); - return new HTTPHeader("Authorization", "Basic " + base64usernamePassword); - } - - public String getUserAgent() { - return userAgent; - } - - public void setUserAgent(String userAgent) { - this.userAgent = userAgent; - } - public String getServerVersion() { checkCapabilities(); return capabilities == null ? null : capabilities.getSoftware().getVersion(); } - public void setAcceptLanguage(String lang) { - this.acceptLanguage = lang; - } - public void setContentLanguage(String lang) { - this.contentLanguage = lang; - } - - public int getUseCount() { - return useCount; - } - private void recordUse() { useCount++; } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java index 5649cf23f..89bd16f2c 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java @@ -76,10 +76,7 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { @Setter private Client client = new Client(); private List headers = new ArrayList<>(); - @Getter @Setter - private String username; - @Getter @Setter - private String password; + @Getter @Setter private String userAgent; @Setter @@ -544,13 +541,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { //FIXME should be in ManagedWebAccess? private Iterable generateHeaders(boolean hasBody) { - List headers = new ArrayList<>(); - // Add basic auth header if it exists - if (basicAuthHeaderExists()) { - headers.add(getAuthorizationHeader()); - } // Add any other headers - headers.addAll(this.headers); + List headers = new ArrayList<>(this.headers); if (!Utilities.noString(userAgent)) { headers.add(new HTTPHeader("User-Agent",userAgent)); } @@ -563,21 +555,9 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { headers.add(new HTTPHeader("Content-Language",contentLanguage)); } - headers.add(new HTTPHeader("Host", "cts.nlm.nih.gov")); - return headers; } - public boolean basicAuthHeaderExists() { - return (username != null) && (password != null); - } - - public HTTPHeader getAuthorizationHeader() { - String usernamePassword = username + ":" + password; - String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes()); - return new HTTPHeader("Authorization", "Basic " + base64usernamePassword); - } - public String getServerVersion() { checkCapabilities(); return capabilities == null ? null : capabilities.getSoftware().getVersion(); diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java index 9c247bf9d..4a9fdd588 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java @@ -38,7 +38,6 @@ import org.hl7.fhir.r4b.model.*; import org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.r4b.utils.client.network.ByteUtils; import org.hl7.fhir.r4b.utils.client.network.Client; -import org.hl7.fhir.r4b.utils.client.network.ClientHeaders; import org.hl7.fhir.r4b.utils.client.network.ResourceRequest; import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.ToolingClientLogger; @@ -46,7 +45,6 @@ import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.http.HTTPHeader; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.util.*; @@ -96,13 +94,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{ @Setter private Client client = new Client(); private List headers = new ArrayList<>(); - @Getter - @Setter - private String username; - - @Getter - @Setter - private String password; @Setter @Getter @@ -537,13 +528,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{ } private Iterable generateHeaders(boolean hasBody) { - List headers = new ArrayList<>(); - // Add basic auth header if it exists - if (basicAuthHeaderExists()) { - headers.add(getAuthorizationHeader()); - } // Add any other headers - headers.addAll(this.headers); + List headers = new ArrayList<>(this.headers); if (!Utilities.noString(userAgent)) { headers.add(new HTTPHeader("User-Agent",userAgent)); } @@ -559,16 +545,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient{ return headers; } - public boolean basicAuthHeaderExists() { - return (username != null) && (password != null); - } - - public HTTPHeader getAuthorizationHeader() { - String usernamePassword = username + ":" + password; - String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes()); - return new HTTPHeader("Authorization", "Basic " + base64usernamePassword); - } - public String getServerVersion() { return capabilities == null ? null : capabilities.getSoftware().getVersion(); } diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java index 696cd56cd..6db89655a 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java @@ -100,12 +100,7 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { @Setter private Client client = new Client(); private List headers = new ArrayList<>(); - @Getter - @Setter - private String username; - @Getter - @Setter - private String password; + @Setter @Getter private String userAgent; @@ -602,13 +597,8 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { //FIXME should be in ManagedWebAccess? private Iterable generateHeaders(boolean hasBody) { - List headers = new ArrayList<>(); - // Add basic auth header if it exists - if (basicAuthHeaderExists()) { - headers.add(getAuthorizationHeader()); - } // Add any other headers - headers.addAll(this.headers); + List headers = new ArrayList<>(this.headers); if (!Utilities.noString(userAgent)) { headers.add(new HTTPHeader("User-Agent",userAgent)); } @@ -624,16 +614,6 @@ public class FHIRToolingClient extends FHIRBaseToolingClient { return headers; } - public boolean basicAuthHeaderExists() { - return (username != null) && (password != null); - } - - public HTTPHeader getAuthorizationHeader() { - String usernamePassword = username + ":" + password; - String base64usernamePassword = Base64.getEncoder().encodeToString(usernamePassword.getBytes()); - return new HTTPHeader("Authorization", "Basic " + base64usernamePassword); - } - public String getServerVersion() { if (capabilities == null) { try { diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java index 91776bf27..a2e0a529a 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccess.java @@ -76,8 +76,6 @@ public class ManagedWebAccess { @Getter private static IFhirWebAccessor fhirWebAccessor; - - @Getter private static String userAgent; private static List serverAuthDetails; diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilderBase.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilderBase.java index f21f41bea..68b89033d 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilderBase.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilderBase.java @@ -51,4 +51,22 @@ public abstract class ManagedWebAccessBuilderBase