Skip to content

Commit

Permalink
Code Quality: Replace deprecated constructor call and fix unchecked a…
Browse files Browse the repository at this point in the history
…ssignment 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.lang.String,java.lang.Object>'"
  • Loading branch information
MartinWheelerMT authored Nov 21, 2024
1 parent 8f6795e commit bf88ffd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions wiremock/src/main/java/PatientDemographicsServiceClient.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
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;
import org.json.JSONObject;

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;

Expand All @@ -37,7 +38,7 @@ public Map<String, Object> 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 {
Expand All @@ -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");
Expand Down

0 comments on commit bf88ffd

Please sign in to comment.