我将 Resteasy 与 Quarkus (io.quarkus.quarkus-resteasy
) 结合使用。
我有一个在 Controller 上声明了参数的路径。
@RequestScoped
@Path("/v1/domain/{domain}/resource")
public class MyRestController {
@POST
@Consumes(APPLICATION_JSON)
public Response create(Entity entity) {
// here I create a new entity...
}
@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response get(@PathParam("id") String id) {
// get and return the entity...
}
}
我想从此 Controller 外部检索 domain
路径参数,例如在标有 @Dependent
的提供程序中,或在处理传入请求的任何拦截器中.
@Dependent
public class DomainProvider {
@Produces
@RequestScoped
public Domain domain() {
// retrieve the path param here !
}
}
我没有找到这样做的方法,也没有找到相关的文档。
我都试过了:
- 使用
@Inject
注入(inject)io.vertx.ext.web.RoutingContext
并访问routingContext.pathParams()
- 使用
ResteasyProviderFactor
恢复请求上下文数据
在这两种情况下,都没有路径参数:请求路径被解析为一个简单的字符串,其中包含客户端用来联系我的网络服务的实际 URL。
编辑:
作为解决方法,在我的 DomainProvider
类中,我使用 routingContext
检索调用的 URL 和正则表达式来解析它并提取域。
最佳答案
没有标准的方法可以做到这一点。
您需要将参数从 JAX-RS 资源向下传递到任何需要它的代码段
关于java - 使用 Quarkus 和 Resteasy 从主 Controller 外部访问路径参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67091769/