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

SpringBootApiGatewayRequestHandler - AWS HTTP GET method support #189

Closed
ghost opened this issue Jul 19, 2018 · 7 comments
Closed

SpringBootApiGatewayRequestHandler - AWS HTTP GET method support #189

ghost opened this issue Jul 19, 2018 · 7 comments

Comments

@ghost
Copy link

ghost commented Jul 19, 2018

When using SpringBootApiGatewayRequestHandler with AWS - HTTP GET method throws exception "Cannot convert event".

This line fails as request body is null.
Object body = deserializeBody(event.getBody());

	protected Object convertEvent(APIGatewayProxyRequestEvent event) {
		Object body = deserializeBody(event.getBody());
		if (functionAcceptsMessage()) {
			return new GenericMessage<>(body, getHeaders(event));
		}
		else {
			return body;
		}
	}
@olegz
Copy link
Contributor

olegz commented Jul 19, 2018

So, you're saying that because of GET you don't have a body. If so what would we use to create Publisher.
Anyway, can you elaborate a bit on what you're trying to do . . .some code etc.

@artembilan
Copy link
Contributor

The queryParams map can be used as a default palyoad.
This is what we do in Spring Integration for the WebFluxInboundEndpoint:

return extractRequestBody(exchange)
		.doOnSubscribe(s -> this.activeCount.incrementAndGet())
		.switchIfEmpty(Mono.just(exchange.getRequest().getQueryParams()))
		.map(body -> new HttpEntity<>(body, exchange.getRequest().getHeaders()))
		.flatMap(entity -> buildMessage(entity, exchange))

Just an idea to consider...

@olegz
Copy link
Contributor

olegz commented Jul 23, 2018

Thanks @artembilan , and yes indeed we need to do something there, yet I am still waiting for @iwejay to communicate what was he trying to accomplish.

@ghost
Copy link
Author

ghost commented Jul 23, 2018

Thank you @olegz and @artembilan
Sorry about the late response and not providing enough details.

I am learning AWS Lambda used along with serverless framework.
I was trying this sample code to expose REST API from AWS Lambda using AWS API Gateway.
https://github.com/iwejay/aws-java-spring-cloud-function-demo

MemberFunctionApplication contains 3 function beans exposed as endpoints over HTTP GET (serverless.yml).

'officers' and 'members' functions are same thing - just tried Publisher and Function with void input.
Both of these methods fails when i do HTTP GET. Below is the log from CloudWatch - which indicates error in body parsing.

Cannot convert event: java.lang.IllegalStateException
	java.lang.IllegalStateException: Cannot convert event
	at org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler.deserializeBody(SpringBootApiGatewayRequestHandler.java:54)
	at org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler.convertEvent(SpringBootApiGatewayRequestHandler.java:36)
	at org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler.convertEvent(SpringBootApiGatewayRequestHandler.java:17)
	at org.springframework.cloud.function.adapter.aws.SpringBootRequestHandler.handleRequest(SpringBootRequestHandler.java:47)
	Caused by: java.lang.NullPointerException
	at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:889)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3004)
	at org.springframework.cloud.function.adapter.aws.SpringBootApiGatewayRequestHandler.deserializeBody(SpringBootApiGatewayRequestHandler.java:51)

Thanks to @artembilan again, got it working as per his suggestion, i tried a simple version of passing the query param to Lambda. Please see AwsApiGatewayGetRequestHandler and MemberFunctionApplication's member method.

Kindly guide and let me know if any further details required.

@ghost
Copy link
Author

ghost commented Jul 23, 2018

Link to original article about Spring Cloud Functions + AWS + Serverless

@pfrank13
Copy link

I've hit the same issue and looked at the upcoming 2.0.0.M3 which appears to have the same bug. Using API Gateway with HTTP GET which results in a null body and ends up with a NPE when trying to be deserialized. I believe @iwejay has provided enough info but I can too if needed, also thanks to @artembilan as well as @iwejay because that workaround worked for me too.

@olegz
Copy link
Contributor

olegz commented May 27, 2021

Given the age of this issue and the amount of new features and improvements that went into AWS adapter I am going to close this issue, but please feel free to raise a new one based on our current support.

@olegz olegz closed this as completed May 27, 2021
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

3 participants