简体   繁体   English

REST Web服务如何工作

[英]how does REST web service work

I have a rest web service as below: 我有一个休息网络服务如下:

@GET
@Path("/getPersonDetails/{personId}/{validDate}")
@Produces("application/xml")
  public PersonDetail getPersonDetails(@PathParam("personId") final String personId,@PathParam("validDate") String validDate) {

    PersonDetail p = new PersonDetail;

    //all the processing to set data into object p

    return p;
}

When called from the browser with appropriate parameters, this service is returning the object as an xml as expected. 当使用适当的参数从浏览器调用时,此服务将按预期将对象作为xml返回。

However, how does it work internally ? 但是,它如何在内部工作?

From where does the tags in the xml get set ? 从哪里开始设置xml中的标签?

Is it from 是来自

1) the names of the local variables inside the service method 1)服务方法中局部变量的名称

2) the names of class properties in the class 2)类中类属性的名称

3) the name of the class itself 3)类本身的名称

What happens between the method returning the object and it appearing on browser as XML ? 返回对象的方法与作为XML出现在浏览器上的方法之间会发生什么?

Thanks for reading! 谢谢阅读!

The XML structure is generated by the Java Architecture for XML Binding . XML结构由Java Architecture for XML Binding生成 It creates XML tags based on class fields. 它根据类字段创建XML标记。 Of course, this process can be customised. 当然,这个过程可以定制。 See Lars Vogels tutorial on JAXB for an example of how to achieve this. 有关如何实现此目的的示例,请参阅JAXB上的 Lars Vogels 教程

After the getPersonDetails() method returns, the JAX-RS runtime invokes the JAXB Marshaller turns the return value of the method into an XML structure, which gets written back to your web browser. 返回getPersonDetails()方法后,JAX-RS运行时调用JAXB Marshaller将方法的返回值转换为XML结构,然后将其写回Web浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM