|
|
|
@ -36,6 +36,10 @@ public class BirthAndDeathDetailsService { |
|
|
|
this.restTemplate = builder.build(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Object> fetchBirthCertificate(String dob, String sex, String regno, String childName, String fatherName, String motherName) throws Exception { |
|
|
|
Map<String, String> params = new LinkedHashMap(); // keep order |
|
|
|
params.put("regno", regno != null ? regno : ""); |
|
|
|
@ -62,9 +66,13 @@ public class BirthAndDeathDetailsService { |
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
ResponseEntity<String> response = restTemplate.exchange(BirthCertificateapiUrl, HttpMethod.GET, entity, String.class); |
|
|
|
|
|
|
|
//System.out.println("✅ API Raw Response: " + response.getBody()); |
|
|
|
String rawJson = response.getBody(); |
|
|
|
String cleanJson = sanitizeJsonResponse(rawJson); |
|
|
|
|
|
|
|
|
|
|
|
return mapper.readValue(response.getBody(), new TypeReference<Map<String, Object>>() {}); |
|
|
|
//System.out.println("✅ API Raw Response: " + cleanJson); |
|
|
|
|
|
|
|
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -101,10 +109,25 @@ public class BirthAndDeathDetailsService { |
|
|
|
ResponseEntity<String> response = restTemplate.exchange(DeathCertificateapiUrl, HttpMethod.GET, entity, String.class); |
|
|
|
|
|
|
|
//System.out.println("✅ API Raw Response: " + response.getBody()); |
|
|
|
String rawJson = response.getBody(); |
|
|
|
String cleanJson = sanitizeJsonResponse(rawJson); |
|
|
|
|
|
|
|
return mapper.readValue(response.getBody(), new TypeReference<Map<String, Object>>() {}); |
|
|
|
return mapper.readValue(cleanJson, new TypeReference<Map<String, Object>>() {}); |
|
|
|
} |
|
|
|
|
|
|
|
private String sanitizeJsonResponse(String rawJson) { |
|
|
|
if (rawJson == null) return ""; |
|
|
|
|
|
|
|
// Remove illegal control characters (but keep line breaks if needed) |
|
|
|
return rawJson |
|
|
|
.replaceAll("[\\p{Cntrl}&&[^\r\n\t]]", "") // Remove non-printable control characters (except tabs/newlines) |
|
|
|
.replaceAll("\t", "") // Remove tab characters explicitly (common cause of error) |
|
|
|
.replaceAll("\\s*:\\s*\n\\s*\"", ":\"") // Fix broken key-value splits |
|
|
|
.replaceAll("\r", "") // Remove carriage return if any |
|
|
|
.replaceAll("\n", ""); // Optionally remove newlines if JSON is malformed across lines |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|