micronaut-core
micronaut-core copied to clipboard
Unable to retrive a JSON request body as Byte[] or String in Graalvm build
Expected Behavior
We are creating an endpoint where we need to receive raw String / byte[] verify signature () and then convert it into JSON. This whole process works find on normal instance but fails when running on GRAALVM build.
@Post
@Secured("isAnonymous()")
public Mono<HttpResponse<?>> webhook(HttpRequest<?> request, @Body Publisher<byte[]> body) {
System.out.println("Inside registration webhook call.");
Flux<byte[]> byteFlux = Flux.from(body);
Mono<String> bodyMono = byteFlux.reduce("", (s1, s2) -> s1 + new String(s2));
return bodyMono.publishOn(Schedulers.boundedElastic()).map(bodyString -> {
try {
Stripe.apiKey = stripeApiKey;
String endpointSecret = stripeWebhookSecret;
String sigHeader = request.getHeaders().get("Stripe-Signature");
if (sigHeader == null || endpointSecret == null || bodyString == null) {
System.out.println("⚠️ Invalid signatures of incoming webhook.");
return HttpResponse.status(HttpStatus.BAD_REQUEST);
}
System.out.println("⚠️ Webhook Secret being used : " + endpointSecret);
// Verify signatures for incoming webhook
if (!verifySignature(endpointSecret, sigHeader, bodyString)) {
return HttpResponse.badRequest().body("Invalid signature");
}
com.marvin.model.stripe.Event event = jsonMapper.readValue(bodyString, Argument.of(com.marvin.model.stripe.Event.class));
System.out.println("event details raw " + event.getData().getObject());
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS, true);
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
System.out.println("EVENT TYPE" + event.getType());
switch (event.getType()) {
..............
}
return HttpResponse.status(HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
System.out.println("⚠️ Webhook error " + e.getMessage());
return HttpResponse.status(HttpStatus.BAD_REQUEST);
}
});
Actual Behaviour
The fails on micronaut graalvm AWS lambda build with following error
08:54:55.087 [main] ERROR i.m.http.server.RouteExecutor - Unexpected error occurred: Error decoding JSON stream for type [T]: Cannot deserialize value of type `byte` from Object value (token `JsonToken.START_OBJECT`)
at [Source: (byte[])"{
Steps To Reproduce
No response
Environment Information
- Ubuntu
- JDK 11
Example Application
No response
Version
3.9.5
Please make a reproducer, this is not enough info to figure it out. Also please test on micronaut 4