REST 客户端子资源在调用时返回 AbstractMethodError

问题描述

编辑:问题是 quarkus-rest-client-reactive,请参阅我的回答。

根据我对 Quarkus 中可用的 MicroProfile REST 客户端的理解,我应该能够在我的 REST 客户端界面中定义子资源,这将允许我像这样在彼此下嵌套资源。

package org.acme.example

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

@RegisterRestClient
@Path("/api/foo")
public interface FoosService {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    Uni<List<Foo>> getAll();

    @Path("/{id}")
    FooService foo(@PathParam("id") String id);
}

public interface FooService {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    Uni<Foo> toRepresentation();
}

但是,当我在代码中注入和调用客户端接口时,它会在 AbstractMethodError 调用中抛出一个 client.foo("bar").toRepresentation()

@Path("/bar")
public class BarResource {
    @RestClient
    FoosResource client;

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public Foo getBar() {
        return client.foo("bar").toRepresentation();
    }
}

我对此的所有研究似乎都表明这是可能的,但是 Quarkus 没有显示客户端子资源的具体示例。

解决方法

我在原帖中没有提到的一点是,我正在为 REST 客户端使用 Reactive 扩展,这似乎导致了问题。

使用同步扩展可以让代理正确构建子资源代理。可能需要为响应式版本设置更多配置才能使用子资源。

,

子资源通常与 Quarkus Rest Client Reactive 一起使用。 您可以查看我们在 Quarkus 代码库中的测试示例(一个问题是它很可能使用了比您需要的更多的功能):https://github.com/quarkusio/quarkus/blob/2.1.0.Final/extensions/resteasy-reactive/rest-client-reactive/deployment/src/test/java/io/quarkus/rest/client/reactive/subresource/SubResourceTest.java#L28

我没有发现您的代码示例有任何特别错误。如果您能在 https://github.com/quarkusio/quarkus/issues 中创建一个 GitHub 问题,并使用最少的问题重现器,那么无论是修复它还是帮助您,这都会对我有很大帮助。