Skip to content

AWSTypesMessageConverter will throw an exception when triggered by web-adapter #1313

@Hzuni

Description

@Hzuni

Describe the bug

This is with using spring-cloud-functions 4.3.0

When I define a bean such as the following

import com.amazonaws.lambda.runtime.events.SQSEvent;

@Bean 
public Consumer<Message<SQSEvent>> sqsListener() {

  return (sqsEvent) -> {
    // some implementation
  }

}

and try to test this code using the functions-web-adapter. A ClassCastException gets thrown from here https://github.com/spring-cloud/spring-cloud-function/blob/main/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSTypesMessageConverter.java#L88

The controller from the web-adapter seems to be setting the body of the GenericMessage (org.springframework.messaging.support) to a String and then at line 88 the exception has a message set of

"class java.lang.String cannot be cast to close [B (java.lang.String and [B are in module java.base of loader bootstrap)"

And I think the current code makes sense when ONLY using the aws-adapter since this

https://github.com/spring-cloud/spring-cloud-function/blob/main/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java#L100

will set a byte[]. So I'm partially unsure if the way I'm testing is supposed to be supported. But when using the web-adapter to locally POST to my Cosnsumer, something is picking up the AWSTypesMessageConverter bean and running its converter code likely just because its on the classpath.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions