如何使用 Jetty 客户端 API 发送 JAXB 编组对象作为参数?
...实际上,我正在寻找 REST 样式的 EJB 或 SOAP 替换;)
这使我能够从服务器接收 JAXB 编组对象
客户端
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");
}
}
以下是如何发送 JAXB 编组对象的示例。 ..
...当它是唯一(未命名)参数时。
我什至不知道这种行为是否有效。有一点不能这样工作:当客户端使用 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
}
}
...practically I'm looking for a REST-style EJB-or-SOAP-replacement ;)
This enables me to receive an JAXB-marshalled object from server
Client side
WebResource r = client.resource("http://localhost:9999/resource1");
SomeObject in = r.post(SomeObject.class);
Server side
@Path("/")
public static final class TestResource {
@Path("resource1")
@POST
public SomeObject resource1() {
return new SomeObject("Object1");
}
}
Here's an example how to send a JAXB-marshalled object...
...when it's the only (unnamed) parameter.
I don't even know if this behavior is intended to work. One thing doesn't work this way: when the client uses client.addFilter(new GZIPContentEncodingFilter())
, the server doesn't understand the request, even when all other (usual) gzipped requests are fine.
Client side
WebResource r = client.resource("http://localhost:9999/resource2");
SomeObject out = new SomeObject("no name");
SomeObject in = r.post(SomeObject.class, out /*!!!*/);
Server side
@Path("/")
public static final class TestResource {
@Path("resource2")
@POST
public SomeObject resource2(SomeObject o) {
o.setName("NEW NAME!"); // "modify" object
return o; // send back
}
}
Again, this behavior seems not consistent or even not intended to work. Why else should the gzip content encoding filter fail here? Can anyone comment on this?
But how can I send such an object as a request parameter?
Client side
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
Server side
@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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论