From b33de12e499fc461f18d0edde34755a96711da64 Mon Sep 17 00:00:00 2001 From: dotasek Date: Thu, 24 Oct 2024 13:57:51 -0400 Subject: [PATCH] WIP move accept to parameter --- .../TerminologyCacheManager.java | 2 +- .../TerminologyCacheManager.java | 2 +- .../fhir/utilities/http/ManagedWebAccess.java | 8 ++-- .../http/ManagedWebAccessBuilder.java | 43 +++++++++---------- .../http/ManagedWebAccessBuilderBase.java | 8 +--- .../utilities/http/ManagedWebAccessUtils.java | 17 ++++++++ .../hl7/fhir/utilities/npm/PackageClient.java | 4 +- 7 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessUtils.java diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java index 68b94ed83..c717f4347 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/terminologies/TerminologyCacheManager.java @@ -158,7 +158,7 @@ public class TerminologyCacheManager { HTTPResult res = ManagedWebAccess.builder() .withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1)) - .withAccept("application/zip").put(url, bs.toByteArray(), null); + .put(url, bs.toByteArray(), null, "application/zip"); if (res.getCode() >= 300) { System.out.println("sending cache failed: " + res.getCode()); } else { diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java index 3e63ac0a8..b58751dbe 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/TerminologyCacheManager.java @@ -158,7 +158,7 @@ public class TerminologyCacheManager { System.out.println("Sending tx-cache to "+url+" ("+Utilities.describeSize(bs.toByteArray().length)+")"); HTTPResult res = ManagedWebAccess.builder() .withBasicAuth(token.substring(0, token.indexOf(':')), token.substring(token.indexOf(':') + 1)) - .withAccept("application/zip").put(url, bs.toByteArray(), null); + .put(url, bs.toByteArray(), null, "application/zip"); if (res.getCode() >= 300) { System.out.println("sending cache failed: "+res.getCode()); 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 2e2023e3f..981ec2943 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 @@ -126,19 +126,19 @@ public class ManagedWebAccess { } public static HTTPResult get(String url, String accept) throws IOException { - return builder().withAccept(accept).get(url); + return builder().get(url, accept); } public static HTTPResult post(String url, byte[] content, String contentType, String accept) throws IOException { - return builder().withAccept(accept).post(url, content, contentType); + return builder().post(url, content, contentType, accept); } public static HTTPResult put(String url, byte[] content, String contentType, String accept) throws IOException { - return builder().withAccept(accept).put(url, content, contentType); + return builder().put(url, content, contentType, accept); } - public static Response httpCall(Request.Builder httpRequest) throws IOException { + public static Response httpCall(FhirRequest httpRequest) throws IOException { return fhirBuilder().httpCall(httpRequest); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilder.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilder.java index a695e0007..b25a91ff8 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilder.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/http/ManagedWebAccessBuilder.java @@ -20,10 +20,6 @@ public class ManagedWebAccessBuilder extends ManagedWebAccessBuilderBase serverAuthDetails) { super(userAgent, serverAuthDetails); } - - public ManagedWebAccessBuilder withAccept(String accept) { - return super.withAccept(accept); - } private Map newHeaders() { Map headers = new HashMap(); @@ -51,7 +47,8 @@ public class ManagedWebAccessBuilder extends ManagedWebAccessBuilderBase serverAuthDetails; @Getter @@ -35,11 +34,6 @@ public abstract class ManagedWebAccessBuilderBase serverAuthDetails) { + if (serverAuthDetails != null) { + for (ServerDetailsPOJO t : serverAuthDetails) { + if (url.startsWith(t.getUrl())) { + return t; + } + } + } + return null; + } +} diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java index 4bf827356..111b6f2fd 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/npm/PackageClient.java @@ -176,13 +176,13 @@ public class PackageClient { } private InputStream fetchUrl(String source, String accept) throws IOException { - ManagedWebAccessBuilder client = ManagedWebAccess.builder().withAccept(accept); + ManagedWebAccessBuilder client = ManagedWebAccess.builder(); if (server.getAuthenticationMode() == HTTPAuthenticationMode.TOKEN) { client.withToken(server.getToken()); } else if (server.getAuthenticationMode() == HTTPAuthenticationMode.BASIC) { client.withBasicAuth(server.getUsername(), server.getPassword()); } - HTTPResult res = client.get(source); + HTTPResult res = client.get(source, accept); res.checkThrowException(); return new ByteArrayInputStream(res.getContent()); }