Skip to content

Commit

Permalink
fix samples
Browse files Browse the repository at this point in the history
  • Loading branch information
mbfreder committed Jun 11, 2023
1 parent 1f36923 commit 8430ff4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -536,4 +536,5 @@ private Headers headersMapToMultiValue(Map<String, String> headers) {
}
return h;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler;
import com.amazonaws.serverless.proxy.internal.testutils.Timer;
import com.amazonaws.serverless.proxy.jersey.JerseyLambdaContainerHandler;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;

import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
Expand All @@ -29,7 +29,7 @@ public class StreamLambdaHandler implements RequestStreamHandler {
.property(ServerProperties.MOXY_JSON_FEATURE_DISABLE,true)
.packages("com.amazonaws.serverless.sample.jersey")
.register(JacksonFeature.class);
private static final JerseyLambdaContainerHandler<APIGatewayProxyRequestEvent, AwsProxyResponse> handler
private static final JerseyLambdaContainerHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> handler
= JerseyLambdaContainerHandler.getAwsProxyHandler(jerseyApplication);

public StreamLambdaHandler() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;

import jakarta.servlet.DispatcherType;
import jakarta.servlet.FilterRegistration;
Expand All @@ -20,7 +21,7 @@


public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringLambdaContainerHandler<APIGatewayProxyRequestEvent, AwsProxyResponse> handler;
private static SpringLambdaContainerHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> handler;
static {
try {
handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


import com.amazonaws.serverless.proxy.RequestReader;
import com.amazonaws.serverless.proxy.model.AwsProxyRequestContext;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -41,26 +42,31 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
if (apiGwContext == null) {
log.warn("API Gateway context is null");
filterChain.doFilter(servletRequest, servletResponse);
return;
}
if (!AwsProxyRequestContext.class.isAssignableFrom(apiGwContext.getClass())) {
if (!APIGatewayV2HTTPEvent.RequestContext.class.isAssignableFrom(apiGwContext.getClass())) {
log.warn("API Gateway context object is not of valid type");
filterChain.doFilter(servletRequest, servletResponse);
}

AwsProxyRequestContext ctx = (AwsProxyRequestContext)apiGwContext;
if (ctx.getIdentity() == null) {
APIGatewayV2HTTPEvent.RequestContext.CognitoIdentity cognito = (APIGatewayV2HTTPEvent.RequestContext.CognitoIdentity)
((AwsHttpServletRequest)servletRequest).getRequest()
.getRequestContext()
.getAuthorizer()
.getIam()
.getCognitoIdentity();
if (cognito == null) {
log.warn("Identity context is null");
filterChain.doFilter(servletRequest, servletResponse);
}
String cognitoIdentityId = ctx.getIdentity().getCognitoIdentityId();
String cognitoIdentityId = cognito.getIdentityId();
if (cognitoIdentityId == null || "".equals(cognitoIdentityId.trim())) {
log.warn("Cognito identity id in request is null");
}
servletRequest.setAttribute(COGNITO_IDENTITY_ATTRIBUTE, cognitoIdentityId);
filterChain.doFilter(servletRequest, servletResponse);
}


@Override
public void destroy() {
// nothing to do in destroy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@


import com.amazonaws.serverless.proxy.RequestReader;
import com.amazonaws.serverless.proxy.model.AwsProxyRequestContext;
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -49,7 +50,7 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
}

APIGatewayV2HTTPEvent.RequestContext.CognitoIdentity cognito = (APIGatewayV2HTTPEvent.RequestContext.CognitoIdentity)
servletRequest.getRequest()
((AwsHttpServletRequest)servletRequest).getRequest()
.getRequestContext()
.getAuthorizer()
.getIam()
Expand Down

0 comments on commit 8430ff4

Please sign in to comment.