Skip to content

Commit

Permalink
Fixing NullpointerException in case of non defined statusCode (#497)
Browse files Browse the repository at this point in the history
pdating AwsProxyHttpServletResponseWriter.java

Fix provided for #497 

This is to resolve NullPointerException when HttpStatusCode is not present in default enum Response.StatusType
  • Loading branch information
anmolk6 authored Dec 14, 2022
1 parent f170312 commit 2c03868
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import com.amazonaws.serverless.proxy.ResponseWriter;
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.amazonaws.serverless.proxy.internal.testutils.Timer;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.model.Headers;
import com.amazonaws.serverless.proxy.model.RequestSource;
import com.amazonaws.services.lambda.runtime.Context;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import java.util.Base64;
import java.util.HashMap;
Expand Down Expand Up @@ -74,8 +74,11 @@ public AwsProxyResponse writeResponse(AwsHttpServletResponse containerResponse,

awsProxyResponse.setStatusCode(containerResponse.getStatus());

if (containerResponse.getAwsProxyRequest() != null && containerResponse.getAwsProxyRequest().getRequestSource() == RequestSource.ALB) {
awsProxyResponse.setStatusDescription(containerResponse.getStatus() + " " + Response.Status.fromStatusCode(containerResponse.getStatus()).getReasonPhrase());
Status responseStatus = Response.Status.fromStatusCode(containerResponse.getStatus());

if (containerResponse.getAwsProxyRequest() != null && containerResponse.getAwsProxyRequest().getRequestSource() == RequestSource.ALB
&& responseStatus != null) {
awsProxyResponse.setStatusDescription(containerResponse.getStatus() + " " + responseStatus.getReasonPhrase());
}

Timer.stop("SERVLET_RESPONSE_WRITE");
Expand Down

0 comments on commit 2c03868

Please sign in to comment.