79114676

Date: 2024-10-22 15:01:33
Score: 0.5
Natty:
Report link

The approach you're using is causing this error because, when using the @PreMatching filter, it is expected that the actions are non-blocking, since the event loop is always used for these operations. The operation of reading the InputStream within the ContainerRequestContext is blocking, and since it is executed in the event loop, the org.jboss.resteasy.reactive.common.core.BlockingNotAllowedException is thrown.

Considering the exception being thrown and the purpose of the filter you mentioned in a previous comment, I believe a possible solution to the problem is as follows:

  1. Remove the @PreMatching annotation from the class.
  2. Use the @ServerRequestFilter annotation directly on the method (without passing attributes, to use the default configuration). This will ensure that the method is called before the request reaches the endpoint, and its operations will be executed in a non-blocking manner (executed in a worker thread).
  3. Remove the implementation of the ContainerRequestFilter interface. This is important because using @ServerRequestFilter in a class that implements this interface causes the method to be executed twice before reaching the endpoint.
package com.example;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.logging.Logger;

import org.jboss.resteasy.reactive.server.ServerRequestFilter;

import com.fasterxml.jackson.databind.ObjectMapper;

import io.vertx.core.http.HttpServerRequest;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.PreMatching;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.ext.Provider;

@Provider
public class TesteFilter {
    private static final Logger LOGGER = Logger.getLogger(TesteFilter.class.getName());

    @Context
    HttpServerRequest request;

    @ServerRequestFilter
    public void doFilter(ContainerRequestContext containerRequestContext) throws IOException {
        LOGGER.info("Intercepting the request in the Filter");

        String body = new String(containerRequestContext.getEntityStream().readAllBytes());
        LOGGER.info("Original request body: " + body);

        ObjectMapper mapper = new ObjectMapper();
        Language language = mapper.readValue(body, Language.class);
        
        String modifiedBody = mapper.writeValueAsString(
                new Language("Modified-" + language.getType(),
                             "Modified-" + language.getName()
                            ));
        LOGGER.info("Modified request body: " + modifiedBody);

        containerRequestContext.setEntityStream(new ByteArrayInputStream(modifiedBody.getBytes()));
    }
}

Here’s the Quarkus documentation covering this topic: Request or response filters - Quarkus Documentation

Lastly, but no less important, you mention that you're using Quarkus version 3.8.6.redhat-00005, which leads me to believe that you already have a subscription to the Red Hat Build of Quarkus. Don’t hesitate to open a support ticket with Red Hat to get help with issues like this.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @PreMatching
  • User mentioned (0): @PreMatching
  • User mentioned (0): @ServerRequestFilter
  • User mentioned (0): @ServerRequestFilter
  • Low reputation (1):
Posted by: IanBMesquita