一言以蔽之:您使用的球衣服务器暴露REST API,如下面的例子:
3210
您使用的球衣,客户端使用REST API的
public static String callRestAPI(String[] args) {
Invocation.Builder builder = ClientBuilder
.newClient()
.target("http://localhost/hello/world");
Response response = builder.method("GET");
String result = response.readEntity(String.class);
return result;
//will return "Hello world!" with our previous example deployed on localhost
}
而泽西灰熊只是使用泽西灰熊服务器。
UPDATE
我的意思是,我们需要的球衣,客户每一次,当我们需要调用REST API被人曝光。
我的球衣客户端使用示例假定您的本地主机上部署了第一个示例。看第一实施例的说明,在路径/你好/世界方法导致的@Path类的和@Path,应与HTTP GET请求被调用(参见@GET注释)。
所以我们创建REST客户端与目标
Invocation.Builder builder = ClientBuilder
.newClient()
.target("http://localhost/hello/world");
则称此目标的HTTP GET请求
Response response = builder.method("GET");
那么我们就知道(距离的helloWorld方法的签名),该API响应包含一个实体可以将其反序列化为String的实例。因此,我们将其读入“结果”变量
String result = response.readEntity(String.class);
您应该提供目标反序列化类作为readEntity方法的响应参数。
另外,REST API仅返回字符串并不常见。相反,他们返回JSON或XML。 在这种情况下,您可以使用JAXB来读取实体,Jersey完美地使用它。请检查this part of documentation for XML support和this for JSON。
非常感谢您的回复.....如果您可以详细说明泽西客户端“消耗”其余API,这将会很有帮助。 – RamSri
不客气。查看更新。 – mkrakhin