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

AwsServletContext violates Servlet Spec by throwing UnsupportedOperationException #448

Closed
Koella1337 opened this issue Feb 10, 2022 · 2 comments
Milestone

Comments

@Koella1337
Copy link

Koella1337 commented Feb 10, 2022

To help us debug your issue fill in the basic information below using the options provided

Serverless Java Container version: 1.6

Implementations: Core

Framework version: SpringBoot 2 v1.7-SNAPSHOT

Frontend service: HTTP API

Deployment method: SAM

Scenario

I'm trying to instrument an AWS Lambda function with a Java agent containing a Servlet instrumentation. In the instrumentation of Filter#init(FilterConfig), the agent calls getServletContext() (via reflection) on the FilterConfig, which returns a com.amazonaws.serverless.proxy.internal.servlet.AwsServletContext object. Then, again via reflection, the agent calls getServletContextName().

Expected behavior

getServletContextName() returns a name or null as per the Servlet spec:
https://javaee.github.io/javaee-spec/javadocs/javax/servlet/ServletContext.html#getServletContextName--

Actual behavior

getServletContextName() throws an UnsupportedOperationException (wrapped in an InvocationTargetException due to reflection).

Steps to reproduce

  1. Instantiate an AwsServletContext object.
  2. Call getServletContextName() on it.

Log output

Not the full logs since they're not relevant, but here's the InvocationTargetException i got when discovering this issue:

2022-02-04 13:51:12.139 UTC [00000001] [ServletIntrospection] Exception in introspection method "registerFilter". java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.base/java.lang.reflect.Method.invoke(Unknown Source)
at agent.introspection.util.classvalue.MethodClassValue.invoke(MethodClassValue.java:71)
at agent.introspection.servlet.ServletIntrospection.getServletContextName(ServletIntrospection.java:382)
at agent.introspection.servlet.ServletIntrospection.registerFilter(ServletIntrospection.java:178)
at agent.introspection.servlet.ServletIntrospectionWrapper.registerFilter(ServletIntrospectionWrapper.java:188)
at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java)
at com.amazonaws.serverless.proxy.internal.servlet.FilterHolder.init(FilterHolder.java:89)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:86)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at com.amazonaws.serverless.proxy.internal.servlet.FilterChainHolder.doFilter(FilterChainHolder.java:90)
at com.amazonaws.serverless.proxy.internal.servlet.AwsLambdaServletContainerHandler.doFilter(AwsLambdaServletContainerHandler.java:156)
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.handleRequest(SpringBootLambdaContainerHandler.java:180)
at com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler.handleRequest(SpringBootLambdaContainerHandler.java:53)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:211)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:254)
at <censored>
at <censored>
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at lambdainternal.HandlerInfo.fromString(HandlerInfo.java:33)
at lambdainternal.AWSLambda.findUserMethods(AWSLambda.java:109)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:230)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:199)
at lambdainternal.AWSLambda.main(AWSLambda.java:193)
Caused by: java.lang.UnsupportedOperationException
at com.amazonaws.serverless.proxy.internal.servlet.AwsServletContext.getServletContextName(AwsServletContext.java:314)
... 28 more
@deki
Copy link
Collaborator

deki commented Feb 10, 2022

Thanks for reporting this. I'm afraid there a several places where this library doesn't comply with the Spec as we are not offering a full servlet container.
However in this case returning null should be fine.

@deki deki added this to the Release 1.7 milestone Feb 10, 2022
@deki
Copy link
Collaborator

deki commented Feb 14, 2022

Fixed, will be part of next release.

@deki deki closed this as completed Feb 14, 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

2 participants