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

NPE on ServletContainer when using Spring Boot with Jersey #345

Open
nytins opened this issue May 8, 2020 · 3 comments
Open

NPE on ServletContainer when using Spring Boot with Jersey #345

nytins opened this issue May 8, 2020 · 3 comments
Assignees

Comments

@nytins
Copy link

nytins commented May 8, 2020

  • Framework version: 1.5
  • Implementations: Spring Boot

Scenario

Trying to run a Spring Boot with Jersey api

Expected behavior

Returns successful response

Actual behavior

Returns 502 Bad Gateway error

Steps to reproduce

  1. Deploy the lambda
  2. Invoke the API

Full log output

c.a.s.p.internal.LambdaContainerHandler : Error while handling request
java.lang.NullPointerException: null
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:365) ~[task/:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:318) ~[task/:na]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:205) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainManager$ServletExecutionFilter.doFilter(FilterChainManager.java:356) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:90) ~[task/:na]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[task/:na]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:90) ~[task/:na]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[task/:na]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:90) ~[task/:na]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[task/:na]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:90) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:156) ~[task/:na]
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.handleRequest(SpringBootLambdaContainerHandler.java:180) ~[task/:na]
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.handleRequest(SpringBootLambdaContainerHandler.java:53) ~[task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:211) [task/:na]
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:254) [task/:na]
at com.capitalone.examples.aws.alb.lambda.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:30) [task/:na]
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:909) [LambdaSandboxJava-1.0.jar:na]
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:341) [LambdaSandboxJava-1.0.jar:na]
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:63) [LambdaSandboxJava-1.0.jar:na]
at java.lang.Class.forName0(Native Method) [na:1.8.0_201]
at java.lang.Class.forName(Class.java:348) [na:1.8.0_201]
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:119) [LambdaJavaRTEntry-1.0.jar:na]
@sapessi
Copy link
Collaborator

sapessi commented May 12, 2020

Hi @nytins - I have not tried to run a JAX-RS application inside SpringBoot. Do you have some sample code I can test with?

@sapessi sapessi added this to the Release 1.5.1 milestone Jul 10, 2020
@sapessi sapessi self-assigned this Jul 10, 2020
@sapessi sapessi removed this from the Release 1.5.1 milestone Jul 15, 2020
@Lucas3oo
Copy link

Lucas3oo commented Dec 5, 2020

Hi @sapessi

I really want to use Jersey for JAX-RS but within Spring boot too.

You can in any Spring boot setup depend on spring jersey starter jar.
Check this link https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-jersey

I have a small sample which is a bit old here: https://github.com/Lucas3oo/jersey-spring

@deki
Copy link
Collaborator

deki commented Jan 5, 2022

Hi,
I was able to reproduce the issue by following https://docs.spring.io/spring-boot/docs/current/reference/html/web.html#web.servlet.jersey and applying it to the Spring Boot 2 Petstore.

aws-serverless-java-container-jersey isn't used in this scenario and that's why Jersey fails with an NPE (WebComponent isn't initialized as org.glassfish.jersey.servlet.ServletContainer.init was never called).

I think to make it work we need to combine the functionalities of aws-serverless-java-container-springboot2 and aws-serverless-java-container-jersey.

deki added a commit to deki/aws-serverless-java-container that referenced this issue Jan 5, 2022
deki added a commit to deki/aws-serverless-java-container that referenced this issue Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants