Java CXF Rest客户端-默认情况下传递HTTP查询参数

Java CXF Rest客户端-默认情况下传递HTTP查询参数,java,rest,client,cxf,Java,Rest,Client,Cxf,我正在使用ApacheCXF编写一个基于代理的Rest客户端,我希望传递一些查询参数,而不必在代理接口中的“搜索”方法中传递它们。我尝试使用@DefaultValue,但是你仍然需要定义一个方法参数,我必须在所有地方传递相同的精确值。有没有办法告诉CXF始终传递具有相同值的查询参数?这样我就可以从代理方法中删除一些不必要的参数 @GET @Path("/{version}/{accountId}/search") @Produces(MediaType.APPLICATI

我正在使用ApacheCXF编写一个基于代理的Rest客户端,我希望传递一些查询参数,而不必在代理接口中的“搜索”方法中传递它们。我尝试使用@DefaultValue,但是你仍然需要定义一个方法参数,我必须在所有地方传递相同的精确值。有没有办法告诉CXF始终传递具有相同值的查询参数?这样我就可以从代理方法中删除一些不必要的参数

    @GET
    @Path("/{version}/{accountId}/search")
    @Produces(MediaType.APPLICATION_JSON)
    public String search(@PathParam("version") String version,
                         @PathParam("accountId") String accountId,
                         @DefaultValue("")@QueryParam("q") String queryString,
                         @DefaultValue("")@QueryParam("category") String category,
                         @DefaultValue("1")@QueryParam("page") int page,
                         @DefaultValue("50")@QueryParam("limit") int limit,
                         @DefaultValue("all")@QueryParam("response_detail") String responseDetail);

你为什么不尝试另一种方法呢。创建一个对象
SearchParameters
,它将只是一个普通的pojo:

public class SearchParameters {
     private String version;
     private String accountId;
     // Other fields

     public static SearchParameters(HttpServletRequest request) {
        // Here you use the getParameterMap of the `request` object to get
        // the query parameters. Look here: http://stackoverflow.com/questions/6847192/httpservletrequest-get-query-string-parameters-no-form-data

        // Everything that was not passed in the parameters
        // just init with default value as you wish.
     }

     // Getters and setters here
}
现在将
search
定义更改为如下所示:

@GET
@Path("/{version}/{accountId}/search")
@Produces(MediaType.APPLICATION_JSON)
public String search(@PathParam("version") String version,
                     @PathParam("accountId") String accountId,
                     @Context HttpServletRequest request);

search
实现中,只需使用
request
SearchParameters
调用静态生成器,就可以了。

为什么不尝试另一种方法呢。创建一个对象
SearchParameters
,它将只是一个普通的pojo:

public class SearchParameters {
     private String version;
     private String accountId;
     // Other fields

     public static SearchParameters(HttpServletRequest request) {
        // Here you use the getParameterMap of the `request` object to get
        // the query parameters. Look here: http://stackoverflow.com/questions/6847192/httpservletrequest-get-query-string-parameters-no-form-data

        // Everything that was not passed in the parameters
        // just init with default value as you wish.
     }

     // Getters and setters here
}
现在将
search
定义更改为如下所示:

@GET
@Path("/{version}/{accountId}/search")
@Produces(MediaType.APPLICATION_JSON)
public String search(@PathParam("version") String version,
                     @PathParam("accountId") String accountId,
                     @Context HttpServletRequest request);

search
实现中,只需使用
request
SearchParameters
调用静态生成器,就可以了。

对不起,我还没有机会尝试它。优先顺序改变:)我会让你知道,当我回到这个。谢谢……对不起,我还没有机会试一下。优先顺序改变:)我会让你知道,当我回到这个。非常感谢。