Skip to content

Commit bf88ffd

Browse files
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.lang.String,java.lang.Object>'"
1 parent 8f6795e commit bf88ffd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

wiremock/src/main/java/PatientDemographicsServiceClient.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
import com.auth0.jwt.JWT;
22
import com.auth0.jwt.algorithms.Algorithm;
3+
import com.fasterxml.jackson.core.type.TypeReference;
34
import com.fasterxml.jackson.databind.ObjectMapper;
45
import com.google.common.base.Charsets;
56
import org.apache.hc.client5.http.utils.Base64;
67
import org.json.JSONObject;
78

89
import java.io.IOException;
910
import java.net.HttpURLConnection;
10-
import java.net.URL;
11+
import java.net.URI;
12+
import java.net.URISyntaxException;
1113
import java.security.KeyFactory;
1214
import java.security.interfaces.RSAPrivateKey;
1315
import java.security.spec.PKCS8EncodedKeySpec;
1416
import java.time.Instant;
1517
import java.time.temporal.ChronoUnit;
16-
import java.util.HashMap;
1718
import java.util.Map;
1819
import java.util.UUID;
1920

@@ -37,7 +38,7 @@ public Map<String, Object> patient(String nhsNumber) throws Exception {
3738

3839
String patientData = getPatientData(nhsNumber, accessToken);
3940

40-
return new ObjectMapper().readValue(patientData, HashMap.class);
41+
return new ObjectMapper().readValue(patientData, new TypeReference<>() {});
4142
}
4243

4344
private String generateJwtToken() throws Exception {
@@ -52,16 +53,17 @@ private String generateJwtToken() throws Exception {
5253
.sign(algorithm);
5354
}
5455

55-
private static String getPatientData(String nhsNumber, String accessToken) throws IOException {
56-
var connection = (HttpURLConnection) (new URL("https://int.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/" + nhsNumber)).openConnection();
56+
private static String getPatientData(String nhsNumber, String accessToken) throws IOException, URISyntaxException {
57+
var connection = (HttpURLConnection) new URI("https://int.api.service.nhs.uk/personal-demographics/FHIR/R4/Patient/" + nhsNumber)
58+
.toURL().openConnection();
5759
connection.setRequestMethod("GET");
5860
connection.setRequestProperty("X-Request-Id", UUID.randomUUID().toString());
5961
connection.setRequestProperty("Authorization", "Bearer " + accessToken);
6062
return new String(connection.getInputStream().readAllBytes(), Charsets.UTF_8);
6163
}
6264

63-
private static String getOauthToken(String token) throws IOException {
64-
var connection = (HttpURLConnection) new URL(OAUTH_ENDPOINT).openConnection();
65+
private static String getOauthToken(String token) throws IOException, URISyntaxException {
66+
var connection = (HttpURLConnection) new URI(OAUTH_ENDPOINT).toURL().openConnection();
6567
connection.setRequestMethod("POST");
6668
connection.setDoOutput(true);
6769
connection.setRequestProperty("content-type", "application/x-www-form-urlencoded");

0 commit comments

Comments
 (0)