......实际上我正在寻找一种REST风格的EJB或SOAP替代品;)
WebResource r = client.resource("http://localhost:9999/resource1");
SomeObject in = r.post(SomeObject.class);
@Path("/")
public static final class TestResource {
@Path("resource1")
@POST
public SomeObject resource1() {
return new SomeObject("Object1");
}
}
...当它是唯一(未命名)参数时。
我甚至不知道这种行为是否有意。有一件事不起作用:当客户端使用client.addFilter(new GZIPContentEncodingFilter())
时,服务器不理解请求,即使所有其他(通常)gzip压缩请求都没问题。
WebResource r = client.resource("http://localhost:9999/resource2");
SomeObject out = new SomeObject("no name");
SomeObject in = r.post(SomeObject.class, out /*!!!*/);
@Path("/")
public static final class TestResource {
@Path("resource2")
@POST
public SomeObject resource2(SomeObject o) {
o.setName("NEW NAME!"); // "modify" object
return o; // send back
}
}
同样,这种行为似乎不一致,甚至无意。为什么gzip内容编码过滤器在这里失败呢? 有人可以对此发表评论吗?
WebResource r = client.resource("http://localhost:9999/resource3");
SomeObject out = new SomeObject("no name"); // this would be the sent param
r. /* some magic method to add a JAXB-marshalled object as parameter */ (out);
SomeObject in = r.post(SomeObject.class); // this receives the "modified" object
@Path("/")
public static final class TestResource {
@Path("resource3") // ??? have something to happen to the URI?
@POST
// which kinds of Param? Path? Query? Form? Matrix? Something else?
public SomeObject resource3(@PathParam("a") SomeObject o) {
o.setName("NEW NAME!"); // "modify" object
return o; // send back
}
}