88
99import com .amazonaws .services .lambda .runtime .Context ;
1010import com .amazonaws .services .lambda .runtime .RequestStreamHandler ;
11+ import com .google .gson .JsonObject ;
12+ import com .google .gson .JsonParser ;
1113
1214import org .apache .logging .log4j .LogManager ;
1315import org .apache .logging .log4j .Logger ;
1416
1517import software .amazon .lambda .powertools .logging .Logging ;
18+ import software .amazon .lambda .powertools .logging .LoggingUtils ;
1619import software .nhs .fhirvalidator .controller .ValidateController ;
1720import software .nhs .fhirvalidator .util .ResourceUtils ;
1821
@@ -25,7 +28,7 @@ public HandlerStream() {
2528 log .info ("Creating the Validator instance for the first time..." );
2629 String manifest_file = System .getenv ("PROFILE_MANIFEST_FILE" );
2730 if (manifest_file == null ) {
28- manifest_file = "nhs_digital .manifest.json" ;
31+ manifest_file = "uk_core .manifest.json" ;
2932 }
3033 log .info (String .format ("Using manifest file : %s" , manifest_file ));
3134
@@ -49,8 +52,22 @@ public void handleRequest(InputStream inputStream, OutputStream outputStream, Co
4952 }
5053 String rawInput = result .toString ();
5154 log .info (rawInput );
52-
53- String validatorResult = validateController .validate (rawInput );
55+ JsonObject jsonPayload = JsonParser .parseString (rawInput ).getAsJsonObject ();
56+ JsonObject headers = jsonPayload .get ("headers" ).getAsJsonObject ();
57+ String xRequestID = headers .get ("x-request-id" ) == null ? "" : headers .get ("x-request-id" ).getAsString ();
58+ LoggingUtils .appendKey ("x-request-id" , xRequestID );
59+ String nhsdCorrelationID = headers .get ("nhsd-correlation-id" ) == null ? "" : headers .get ("nhsd-correlation-id" ).getAsString ();
60+ LoggingUtils .appendKey ("nhsd-correlation-id" , nhsdCorrelationID );
61+ String nhsdRequestID = headers .get ("nhsd-request-id" ) == null ? "" : headers .get ("nhsd-request-id" ).getAsString ();
62+ LoggingUtils .appendKey ("nhsd-request-id" , nhsdRequestID );
63+ String xCorrelationID = headers .get ("x-correlation-id" ) == null ? "" : headers .get ("x-correlation-id" ).getAsString ();
64+ LoggingUtils .appendKey ("x-correlation-id" , xCorrelationID );
65+ String apigwRequestID = headers .get ("apigw-request-id" ) == null ? "" : headers .get ("apigw-request-id" ).getAsString ();
66+ LoggingUtils .appendKey ("apigw-request-id" , apigwRequestID );
67+
68+ log .info ("Calling validate function" );
69+ String validatorResult = validateController .validate (jsonPayload .get ("body" ).toString ());
70+ log .info (validatorResult );
5471
5572 try (PrintWriter writer = new PrintWriter (outputStream )) {
5673 writer .print (validatorResult );
0 commit comments