获取Quarkus Interceptor的请求主体
我已经在基于Quarkus的应用程序中写了一个拦截器。
@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();
}
有一些带有@AccessPolicy注释的REST API,该拦截器正常拦截它们。 我可以从请求中获取标题值(request.getheader(“ tenant-id”))。
httpserverrequest对象中的身体不可用。
PS:我无法使用ContainerRequestFilter,因为我需要InvocationContext用于业务逻辑。请建议是否有其他方法可以使我的请求身体和调用上下文。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
ContainerRequestFilter
为我工作,因为我需要InvocationContext
仅用于获取REST API的方法名称,并且可以在ContainerRequestContext中使用。Using
ContainerRequestFilter
worked for me as I neededInvocationContext
only to get the method name of the Rest API and it was available in the ContainerRequestContext.