'Get request body in Quarkus Interceptor
I have written an interceptor in Quarkus based application.
@AccessPolicy //custom annotation
@Interceptor
public class PolicyInterceptor {
@AroundInvoke
Object authorize(InvocationContext context) throws Exception {
HttpServerRequest request = ResteasyProviderFactory.getInstance().getContextData(HttpServerRequest.class);
String tenantId = request.getHeader("tenant-id");
//business logic here which needs request body
return context.proceed();
}
There are some rest APIs which are annotated with @AccessPolicy and this interceptor is properly intercepting them. I am able to get header value from the request (request.getHeader("tenant-id")).
Somehow body is not available in the HttpServerRequest object.
PS: I can't use ContainerRequestFilter as I need InvocationContext for the business logic. Please suggest if there is any other way which gives me both request body and invocation context.
Solution 1:[1]
Using ContainerRequestFilter
worked for me as I needed InvocationContext
only to get the method name of the Rest API and it was available in the ContainerRequestContext.
String methodName = ((PostMatchContainerRequestContext) requestContext).getResourceMethod().getMethod().getName();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ubercool |