Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jersey lambda fn has null outputstream #230

Closed
jessefarinacci opened this issue Jan 18, 2019 · 2 comments
Closed

jersey lambda fn has null outputstream #230

jessefarinacci opened this issue Jan 18, 2019 · 2 comments

Comments

@jessefarinacci
Copy link

jessefarinacci commented Jan 18, 2019

  • Framework version: com.amazonaws.serverless:aws-serverless-java-container-jersey:jar:1.3:compile

Scenario

public class StreamLambdaHandler implements RequestStreamHandler {

    private static final Logger LOG = LoggerFactory.getLogger(StreamLambdaHandler.class);
    private static final String DEFAULT_PACKAGES = "org";
    private final ResourceConfig application;
    private final JerseyLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;

    public StreamLambdaHandler() {
        this(DEFAULT_PACKAGES);
    }

    public StreamLambdaHandler(String packages) {
        super();
        application = new ResourceConfig().packages(packages).register(JacksonFeature.class);
        handler = JerseyLambdaContainerHandler.getAwsProxyHandler(application);
    }

    @Override
    public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
        LOG.info("APPLICATION: " + application);
        LOG.info("HANDLER:     " + handler);
        LOG.info("INPUT:       " + inputStream);
        LOG.info("OUTPUT:      " + outputStream);
        LOG.info("CONTEXT:     " + context);

        handler.proxyStream(inputStream, outputStream, context);
    }
}

Expected behavior

OUTPUT: some non-null value

Actual behavior

OUTPUT:

Steps to reproduce

Full log output

[main] INFO com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Starting Lambda Container Handler
START RequestId: 771df6a0-de9b-4766-9ad8-78c338708264 Version: $LATEST
[main] INFO org.buffalo.coders.aws.lambda.common.StreamLambdaHandler - APPLICATION: org.glassfish.jersey.server.ResourceConfig@4426bff1
[main] INFO org.buffalo.coders.aws.lambda.common.StreamLambdaHandler - HANDLER: com.amazonaws.serverless.proxy.jersey.JerseyLambdaContainerHandler@3c7c886c
[main] INFO org.buffalo.coders.aws.lambda.common.StreamLambdaHandler - INPUT: lambdainternal.util.NativeMemoryAsInputStream@55493582
[main] INFO org.buffalo.coders.aws.lambda.common.StreamLambdaHandler - OUTPUT:
[main] INFO org.buffalo.coders.aws.lambda.common.StreamLambdaHandler - CONTEXT: lambdainternal.api.LambdaContext@1a20270e
[main] ERROR com.amazonaws.serverless.proxy.internal.LambdaContainerHandler - Error while handling request
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293)
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104)
[main] ERROR com.amazonaws.serverless.proxy.AwsProxyExceptionHandler - Called exception handler for:
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209)
at org.buffalo.coders.aws.lambda.common.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293)
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104)
java.lang.NullPointerException
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:48)
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:28)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:174)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:209)
at org.buffalo.coders.aws.lambda.common.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:81)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293)
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104)
END RequestId: 771df6a0-de9b-4766-9ad8-78c338708264
REPORT RequestId: 771df6a0-de9b-4766-9ad8-78c338708264  Duration: 58.83 ms      Billed Duration: 100 ms Memory Size: 1024 MB    Max Memory Used: 87 MB
@sapessi
Copy link
Collaborator

sapessi commented Feb 12, 2019

Hey @jessefarinacci, where are you invoking the Lambda function from? Looks like a NPE when trying to put the ALB context in the request. Normally, I would expect the requestContext to be not null even if the request did not come from ALB. This is similar to #237 where the event is triggered by an unsupported event source (CloudWatch).

@sapessi
Copy link
Collaborator

sapessi commented Feb 26, 2019

Closing since version 1.3.1 is out.

@sapessi sapessi closed this as completed Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants