使用Resteasy客户端添加标头参数

时间:2017-05-26 14:05:47

标签: resteasy

我使用Resteasy给我回电话

所以我使用界面配置我的电话

@Path("/api/private/configuracao")
public interface ConfiguracaoClient {
    @GET
    @Path("/")
    @Consumes("application/json")
    @HeaderParam(value = "db_teste")
    public ConfiguracaoVO findConfiguracao();
}

并且这样打电话:

public class ConfiguracaoClientImpl {
    ResteasyClient client;
    ConfiguracaoClient configuracaoClient;
    public ConfiguracaoClientImpl() {
        client = new ResteasyClientBuilder().build();
        ResteasyWebTarget target = client.target("http://localhost:8181/");
        target.request().header("public","db_teste");
        configuracaoClient = target.proxy(ConfiguracaoClient.class);

    }

    public ConfiguracaoVO findConfiguracao(){
        return configuracaoClient.findConfiguracao();
    }
}

如何在标题中添加参数? TKS

1 个答案:

答案 0 :(得分:1)

db_teste应该是查询参数而不是标题参数。正确的语法如下:

@Path("/api/private/configuracao")
public interface ConfiguracaoClient {
    @GET
    @Path("/")
    @Consumes("application/json")
    public ConfiguracaoVO findConfiguracao(@QueryParam("db_teste") String dbTest);
}

ConfiguracaoClientImpl

中删除此行
target.request().header("public","db_teste");

您可以在db_teste来电中添加configuracaoClient.findConfiguracao(value)的值。