Resteasy,如何初始化@Context Uriinfo参数以用于代理客户端调用



我的Resteasy端点接口是这样声明的:

@Path("/entity")
public interface EntitySearchEndpoint {
...
    @GET
    @Path("/search")
    @Produces(MediaType.APPLICATION_JSON)
    public Response search(@Context UriInfo ui);
...
}

现在我使用接口创建了代理客户端

ResteasyClient reClient = new ResteasyClientBuilder().build();
ResteasyWebTarget webTarget = reClient.target(URI.create("http://example.com"));
EntitySearchEndpoint entitySearchEndpoint = ncspAPIWebTarget.proxy(EntitySearchEndpoint.class);

现在我可以使用

来调用服务
UriInfo ui = ???
Response response = entitySearchEndpoint.search(ui);

我的问题是如何创建Uriinfo实例以仅包含所需的查询参数?
可能使用 @Context UriInfo作为参数不正确,什么是正确的方法?
Queryparam名称列表不限制,任何名称都可以...

如果我理解您想要的正确的内容,您的API可以看起来像这样:

@Path("/entity")
public interface EntitySearchEndpoint {
...
    @GET
    @Path("/search/{searchQuery}")
    @Produces(MediaType.APPLICATION_JSON)
    public Response search(@PathParam("searchQuery") String searchQuery);
...
}

,您的客户只会用字符串调用它:

Response response = entitySearchEndpoint.search("test string");

最新更新