繁体   English   中英

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

[英]REST Client Sub-resources return AbstractMethodError when invoked

编辑:问题是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();
}

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

@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 问题,并使用您的问题的最小重现器,那么无论是修复它还是帮助您,这都会对我有很大帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM