RESTful Web 服务代理类

发布于 2025-01-05 04:35:03 字数 1320 浏览 1 评论 0原文

我编写了一个 Jersey 客户端应用程序,它与两个 Web 服务交互,一个是 REST,另一个是 SOAP。我使用 REST 服务提供的员工数据通过 SOAP 服务创建新用户。

REST 服务是一个返回 Employee 实体的 JAX-RS (Jersey) 应用程序:

@Entity
@Table(name = "EMPLOYEE_TABLE")
@XmlRootElement
public class Employee implements Serializable {
  ...
}

我没有显式地为实体类创建架构定义。

GET 请求返回 Employee 实体的表示形式:

GET /employees/100

<Employee id='100' providerId='3345'>
  <Link type="application/xml" href="/employees/100" rel="self"/>
  <Name>Doe, Dr. John</Name>
  <Departments>
    <Department id='10'><Name>Emergency Medicine</Name></Department>
    <Department id='56'><Name>Behavioral Medicine</Name></Department>
  </Departments>
</Employee>

SOAP 服务(BusinessObjects Enterprise Web 服务 SDK)提供 Java 客户端来简化其使用。

虽然我可以解析 Employee 实体的 XML 表示并将其分配给 User 类的适当设置器,但在我的 Jersey 客户端应用程序中创建 Employee 代理类(带有适当的注释)可能会更容易。

问题:

  1. JAX-RS(特别是在我的例子中,Jersey)是否有公开实体模式定义(XSD 格式)的机制? WADL 文档不包含此类信息。
  2. 虽然我可以手动创建一个模仿 Employee 资源类的 POJO 类表示形式,但我可能应该使用“工具”。我对此有何选择?
  3. 随着时间的推移,我可能需要向 Employee 实体添加其他元素。这是否意味着需要创建新版本的 RESTful 服务?
  4. 假设 Jersey 可以配置为自动生成和公开架构定义,并且对 Employee 的更改将更改架构定义,那么 Employee 实体是否应该实现一个接口来防止未经授权的更改?

I've written a Jersey-client application that interacts with two web services, one that is REST, the other that is SOAP. I use the employee data supplied by the REST service to create an new User with the SOAP service.

The REST service is a JAX-RS (Jersey) application that returns an Employee entity:

@Entity
@Table(name = "EMPLOYEE_TABLE")
@XmlRootElement
public class Employee implements Serializable {
  ...
}

I have not explicitly created a schema definition for the entity class.

A GET request returns a representation of the Employee entity:

GET /employees/100

<Employee id='100' providerId='3345'>
  <Link type="application/xml" href="/employees/100" rel="self"/>
  <Name>Doe, Dr. John</Name>
  <Departments>
    <Department id='10'><Name>Emergency Medicine</Name></Department>
    <Department id='56'><Name>Behavioral Medicine</Name></Department>
  </Departments>
</Employee>

The SOAP service (BusinessObjects Enterprise web-services SDK) provides a Java client to simplify its usage.

While I could parse the XML-representation of the Employee entity and assign it to the appropriate setters of the User class, it would probably be easier to create an Employee proxy class (with the appropriate annotations) in my Jersey client application.

Questions:

  1. Does JAX-RS (specifically Jersey, in my case) have a mechanism to expose an entity's schema definition (XSD format)? The WADL document doesn't include this type of information.
  2. While I could manually create a POJO-class representation that mimics the Employee resource class, I should probably be using a 'tool'. What are my options for this?
  3. As time progresses, I may need to add additional elements to the Employee entity. Does this mean that a new version of the RESTful services needs to be created?
  4. Assuming that Jersey can be configured to automatically generate and expose a schema definition, and that changes to the Employee would then alter the schema definition, should the Employee entity implement an interface to prevent unauthorized changes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖树树初阳… 2025-01-12 04:35:03

关于问题 1,如果您的 XSD 部署在您的 Web 应用程序中,您只需在浏览器中导航到它即可。例如,在我的 web 应用程序中,我有一个包含 XSD 的 /xsd 文件夹。当应用程序运行时,我可以将浏览器指向 http://localhost:8080//xsd/.xsd 并查看 XSD。

Concerning question 1, if your XSD is deployed in your webapp you can just navigate to it in a browser. For example, in my webapp I have an /xsd folder containing my XSD. When the app is running I can point my browser to http://localhost:8080/<app_name>/xsd/<xsd_name>.xsd and see the XSD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文