From bf88ffdd6f27d94567ac47a93d95bb53769edd35 Mon Sep 17 00:00:00 2001 From: MartinWheelerMT <88717465+MartinWheelerMT@users.noreply.github.com> Date: Thu, 21 Nov 2024 10:56:08 +0000 Subject: [PATCH] Code Quality: Replace deprecated constructor call and fix unchecked assignment warning (#1000) Code Quality fix to replace deprecated constructors on `URL(java.lang.String) with the recommended `URI().toURL()` method instead Fix waring with "Warning:(42, 16) Unchecked assignment: 'java.util.HashMap' to 'java.util.Map'" --- .../java/PatientDemographicsServiceClient.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/wiremock/src/main/java/PatientDemographicsServiceClient.java b/wiremock/src/main/java/PatientDemographicsServiceClient.java index 0bfa0b66b..ee83bc991 100644 --- a/wiremock/src/main/java/PatientDemographicsServiceClient.java +++ b/wiremock/src/main/java/PatientDemographicsServiceClient.java @@ -1,5 +1,6 @@ import com.auth0.jwt.JWT; import com.auth0.jwt.algorithms.Algorithm; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.base.Charsets; import org.apache.hc.client5.http.utils.Base64; @@ -7,13 +8,13 @@ import java.io.IOException; import java.net.HttpURLConnection; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.security.KeyFactory; import java.security.interfaces.RSAPrivateKey; import java.security.spec.PKCS8EncodedKeySpec; import java.time.Instant; import java.time.temporal.ChronoUnit; -import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -37,7 +38,7 @@ public Map patient(String nhsNumber) throws Exception { String patientData = getPatientData(nhsNumber, accessToken); - return new ObjectMapper().readValue(patientData, HashMap.class); + return new ObjectMapper().readValue(patientData, new TypeReference<>() {}); } private String generateJwtToken() throws Exception { @@ -52,16 +53,17 @@ private String generateJwtToken() throws Exception { .sign(algorithm); } - private static String getPatientData(String nhsNumber, String accessToken) throws IOException { - var connection = (HttpURLConnection) (new URL("https://int.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/" + nhsNumber)).openConnection(); + private static String getPatientData(String nhsNumber, String accessToken) throws IOException, URISyntaxException { + var connection = (HttpURLConnection) new URI("https://int.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/" + nhsNumber) + .toURL().openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("X-Request-Id", UUID.randomUUID().toString()); connection.setRequestProperty("Authorization", "Bearer " + accessToken); return new String(connection.getInputStream().readAllBytes(), Charsets.UTF_8); } - private static String getOauthToken(String token) throws IOException { - var connection = (HttpURLConnection) new URL(OAUTH_ENDPOINT).openConnection(); + private static String getOauthToken(String token) throws IOException, URISyntaxException { + var connection = (HttpURLConnection) new URI(OAUTH_ENDPOINT).toURL().openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");