11package com .networknt .aws .lambda .handler .middleware .router ;
22
3+ import com .amazonaws .services .lambda .runtime .events .APIGatewayProxyRequestEvent ;
34import com .amazonaws .services .lambda .runtime .events .APIGatewayProxyResponseEvent ;
45import com .networknt .aws .lambda .LightLambdaExchange ;
56import com .networknt .aws .lambda .handler .Handler ;
@@ -63,11 +64,13 @@ public Status execute(LightLambdaExchange exchange) {
6364 return this .successMiddlewareStatus ();
6465 } else {
6566 if (!exchange .hasFailedState ()) {
67+ // get the finalized request to trigger the state change for the request complete.
68+ APIGatewayProxyRequestEvent requestEvent = exchange .getFinalizedRequest (false );
6669 /* invoke http service */
6770 String serviceId = serviceIdOptional .get ();
68- var originalPath = exchange . getRequest () .getPath ();
71+ var originalPath = requestEvent .getPath ();
6972 var targetPath = originalPath ;
70- var method = exchange . getRequest () .getHttpMethod ().toLowerCase ();
73+ var method = requestEvent .getHttpMethod ().toLowerCase ();
7174 LOG .debug ("Request path: {} -- Request method: {} -- Start time: {}" , originalPath , method , System .currentTimeMillis ());
7275 // lookup the host from the serviceId
7376 String host = cluster .serviceToUrl (protocol , serviceId , null , null );
@@ -89,8 +92,8 @@ public Status execute(LightLambdaExchange exchange) {
8992 if ("get" .equalsIgnoreCase (method ) || "delete" .equalsIgnoreCase (method )) {
9093 HttpClientRequest request = new HttpClientRequest ();
9194 try {
92- HttpRequest .Builder builder = request .initBuilder (host + targetPath , HttpMethod .valueOf (exchange . getRequest () .getHttpMethod ()));
93- exchange . getRequest () .getHeaders ().forEach (builder ::header );
95+ HttpRequest .Builder builder = request .initBuilder (host + targetPath , HttpMethod .valueOf (requestEvent .getHttpMethod ()));
96+ requestEvent .getHeaders ().forEach (builder ::header );
9497 builder .timeout (Duration .ofMillis (CONFIG .getMaxRequestTime ()));
9598 HttpResponse <String > response = (HttpResponse <String >) request .send (builder , HttpResponse .BodyHandlers .ofString ());
9699 APIGatewayProxyResponseEvent res = new APIGatewayProxyResponseEvent ()
@@ -113,8 +116,8 @@ public Status execute(LightLambdaExchange exchange) {
113116 } else if ("post" .equalsIgnoreCase (method ) || "put" .equalsIgnoreCase (method ) || "patch" .equalsIgnoreCase (method )) {
114117 HttpClientRequest request = new HttpClientRequest ();
115118 try {
116- HttpRequest .Builder builder = request .initBuilder (host + targetPath , HttpMethod .valueOf (exchange . getRequest (). getHttpMethod ()), Optional .of (exchange . getRequest () .getBody ()));
117- exchange . getRequest () .getHeaders ().forEach (builder ::header );
119+ HttpRequest .Builder builder = request .initBuilder (host + targetPath , HttpMethod .valueOf (requestEvent . getHttpMethod ()), Optional .of (requestEvent .getBody ()));
120+ requestEvent .getHeaders ().forEach (builder ::header );
118121 builder .timeout (Duration .ofMillis (CONFIG .getMaxRequestTime ()));
119122 HttpResponse <String > response = (HttpResponse <String >) request .send (builder , HttpResponse .BodyHandlers .ofString ());
120123 APIGatewayProxyResponseEvent res = new APIGatewayProxyResponseEvent ()
0 commit comments