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

Unable to retrive a JSON request body as Byte[] or String in Graalvm build #10715

Open
cprashantgupta opened this issue Apr 15, 2024 · 1 comment

Comments

@cprashantgupta
Copy link

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

@yawkat
Copy link
Member

yawkat commented Apr 23, 2024

Please make a reproducer, this is not enough info to figure it out. Also please test on micronaut 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants