将对象发送到 Restful 服务
我正在使用restEasy(jboss的Restful实现)ejb3.0,Jboss5.1.1 AS
我做了接受简单对象的restful服务。
这是在服务器端:
@POST
@Path("testObjects")
@Consumes("application/xml")
@Produces("text/plain")
public String testObjects(GrandSun sun)
{
System.out.println(sun.toString());
return "success";
}
这是我在服务器端声明的对象:
package com.mirs.wma.web.data;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class GrandSun
{
int m = 1;
int g = 2;
}
我通过发送 xml 字符串的restfull 客户端测试它,它工作正常。
<?xml version="1.0" encoding="UTF-8"?>
<grandSun>
<m>111</m>
<g>22</g>
</grandSun>
我正在寻找的是一个安静的客户端,它将能够发送整个对象(按原样),而不需要我手动转换为 xml 格式。
是否有任何选项可以通过注释来完成此操作?
我只需要在客户端注释该对象并将其按原样发送到restful 服务?
谢谢, 射线。
谢谢, 射线。
I am using restEasy(Restful implementation for jboss) ejb3.0, Jboss5.1.1 AS
I did restful service which accepting simple object.
this is at the server side:
@POST
@Path("testObjects")
@Consumes("application/xml")
@Produces("text/plain")
public String testObjects(GrandSun sun)
{
System.out.println(sun.toString());
return "success";
}
this is the object which I have declared at the server side:
package com.mirs.wma.web.data;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class GrandSun
{
int m = 1;
int g = 2;
}
I test it via restfull client which sending xml string and it works fine.
<?xml version="1.0" encoding="UTF-8"?>
<grandSun>
<m>111</m>
<g>22</g>
</grandSun>
What I am looking for is a restful client which will be able to send the whole object (as is) without needing me to convert manually to xml format.
Is there any option to do it via annotation?
I will just need to annotate the object at the client side and send it as is to the restful service?
thanks,
ray.
thanks,
ray.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 RestEasy 自己的客户端,连同 JAXB marshaller (我更喜欢 Jackson,但 jettison 有货我认为与 RestEasy 一起)。虽然在服务器端对 POJO 进行解组,但客户端负责对 POJO 进行编组。
希望这能给您一些提示。
Using RestEasy own client, along with a JAXB marshaller (I prefer Jackson but jettison comes stock with RestEasy I think). While on the server side POJOs are unmarshalled, the client side is responsible for marshalling the POJO.
Hope this gives you a few hints.
大多数 IDE 都可以从 WSDL 生成 WebService 客户端存根。这将提供将对象自动转换为 XML 请求并反序列化结果所需的基础设施。
如果做不到这一点,请查看 wsdl2java。它将为您生成存根。
Most IDEs can generate a WebService client-stub from a WSDL. This will provide the infrastructure needed to convert objects automatically into XML requests and deserialize the result.
Failing that, check out wsdl2java. It will generate the stubs for you.