2017-05-26 60 views
0

我使用RestEasy的打電話給我回添加標題PARAM與

所以我用一個界面來配置我的電話

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

,並呼籲像這樣RestEasy的客戶:

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

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"); 

而且你可以在configuracaoClient.findConfiguracao(value)通話添加db_teste值。