获取Quarkus Interceptor的请求主体

发布于 2025-01-28 17:31:31 字数 692 浏览 3 评论 0原文

我已经在基于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一城柳絮吹成雪 2025-02-04 17:31:31

使用ContainerRequestFilter为我工作,因为我需要InvocationContext仅用于获取REST API的方法名称,并且可以在ContainerRequestContext中使用。

String methodName = ((PostMatchContainerRequestContext) requestContext).getResourceMethod().getMethod().getName();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文