Java JerseyClient webResource的问题

Java JerseyClient webResource的问题,java,jersey-client,Java,Jersey Client,我是新手。我有一个REST服务,如下所示: @GET @PATH("/{id}/headerinfo") @Produces({ JSON, XML}) public Response getRequestHEADER(@PathParam("id") long id) { Request result = em.find(Request.class, id); ... return Response.ok(entity).build(); 这是我的电话,它给我带来了问题:

我是新手。我有一个REST服务,如下所示:

@GET
@PATH("/{id}/headerinfo")
@Produces({ JSON, XML})
public Response getRequestHEADER(@PathParam("id") long id) {
    Request result = em.find(Request.class, id);

    ...

return Response.ok(entity).build();
这是我的电话,它给我带来了问题:

@Path("") //what should go here?
public class AaRestCall
    public static String subTrackNum (String trackNum) throws IOException {
        try {
            Client client = Client.create();

            WebResource webResource = client.
            resource("https://url/rest/request/" +   trackNum);

            ClientResponse response = webResource.
            accept("application/json").get(ClientResponse.class);

            String output = response.getEntity(String.class);

            return output;
        }
        catch some stuff here

}
我有几个问题:

1) @Path参数中有什么内容

2) webResource给我一个错误,当作为webResource.accept调用时无法解决。我不清楚为什么


3) 任何额外的提示都将不胜感激,因为这是我第一次调用REST,也是第一次使用jersey。

装饰类的路径参数将是基本uri,例如
@path(“/”)
,然后类内的方法将是/例如
@path(“test”)之后特定uri的路径参数

虽然这是一篇老文章,但我想对一些观点发表评论

1) @Path参数中有什么内容

据我所知,下面一个是你的服务器端,我的意思是服务

然而第二个是你的客户方

因此,您不需要添加

路径(“”)

由于使用客户端请求调用的API具有自己的模式url,例如/service/list,因此客户端使用此服务,这意味着不需要任何路径,除非您不开发一种适配器来提供两个API之间的集成。(这是一个有点不可能的概念,不要坚持太多)

2) webResource给了我一个错误,当 作为webResource.accept调用。我不清楚为什么

基本上是webResource.accept(…)的功能。添加可接受的响应媒体类型,如json、xml、文件等。因此,您应该对此进行详细描述

3) 任何额外的提示将不胜感激,因为这是我的第一次休息 打电话,第一次使用球衣


您可以检查一个用于REST的框架,该框架是

请参考pathparam示例:据我所知,如果uri是www.google.com/somevariable,那么路径将是:@Path(“www.google.com/”)?
@GET
@PATH("/{id}/headerinfo")
@Produces({ JSON, XML})
public Response getRequestHEADER(@PathParam("id") long id) {
    Request result = em.find(Request.class, id);

    ...

return Response.ok(entity).build();
@Path("") //what should go here?
public class AaRestCall
    public static String subTrackNum (String trackNum) throws IOException {
        try {
            Client client = Client.create();

            WebResource webResource = client.
            resource("https://url/rest/request/" +   trackNum);

            ClientResponse response = webResource.
            accept("application/json").get(ClientResponse.class);

            String output = response.getEntity(String.class);

            return output;
        }
        catch some stuff here

}