简体   繁体   English

RESTfull Web服务和客户端设计

[英]RESTfull web service and client design

Tech Stack : Java 1.6, JPA (Hibernate 3), Spring 3, Oracle 11g, JAX-RS (RESTEasy), Freemarker, Spring Webflow, jQuery, JBoss5 技术堆栈 :Java 1.6,JPA(Hibernate 3),Spring 3,Oracle 11g,JAX-RS(RESTEasy),Freemarker,Spring Webflow,jQuery,JBoss5

Hello, 你好,

Currently I am working on a project where we have two set of functionalities : 目前,我正在一个项目中,我们有两个功能集

  1. To publish a set of web services (RESTful) for external clients to consume. 发布一组Web服务(RESTful)供外部客户端使用。
  2. To create a set of screens (around 10) which basically allows Admin functions to be performed eg create MI reports, set up new data, configuration and view past data. 要创建一组屏幕(大约10个) ,基本上可以执行管理功能,例如创建MI报告,设置新数据,配置和查看过去的数据。

My approach is to: 我的方法是:

  1. To create a service layer 创建服务层
  2. Webflow and Freemarker templates invoking methods on this service layer. Webflow和Freemarker模板在此服务层上调用方法。

  3. And create another layer of components for REST (@Path), again using the same service layer. 并再次使用同一服务层,为REST创建另一层组件(@Path)。

Now in a design meeting someone suggested the following: 现在在设计会议中有人提出以下建议:

  1. Seperate the layers in to seperate modules (as in maven) 分隔层以分隔模块(如在Maven中)
  2. Create a module each for: 为以下各创建一个模块:

    a2. a2。 RESTful services (with service layer and javax.ws.rs.Produces) RESTful服务(带有服务层和javax.ws.rs.Produces)

    b2. b2。 Screens with a service layer invloking the services published in module a2. 具有服务层的屏幕将调用模块a2中发布的服务。 This will use org.apache.commons.httpclient. 这将使用org.apache.commons.httpclient。 HttpClient to invloke the a2 services. HttpClient调用a2服务。

I am not sure if I can really see the benefits or if this is the correct approach. 我不确定我是否真的能看到好处,还是这是正确的方法。 I think maybe I don't undestand the suggested approach. 我认为也许我不理解建议的方法。

Can some one please elaborate as to which approach is better and why? 能否请您详细说明哪种方法更好,为什么呢?

Thanks, adi 谢谢,阿迪

IMHO, this is not necessary to use the HttpClient and everything to access the service layer. 恕我直言,这不需要使用HttpClient和其他任何东西来访问服务层。

This mechanism will produce a huge and useless CPU overhead (serialize / fake the http transport / deserialize the message) to communicate between 2 layers that are very close (in the same war). 这种机制将产生巨大无用的 CPU开销(序列化/伪造http传输/反序列化消息),以在非常接近的2层之间进行通信(在同一战争中)。

If you are sure the administration screens and the REST services will always be deployed together, use direct communication, stay pragmatic. 如果您确定管理屏幕和REST服务将始终部署在一起,请使用直接通信,保持务实。

You should keep one maven project. 您应该保留一个Maven项目。 There is no need to create a complex project for 10 screens and 5 REST services. 无需为10个屏幕和5个REST服务创建一个复杂的项目。 Keep it simple. 把事情简单化。

Create a service layer that handles the business + bo. 创建一个处理业务+ bo的服务层。 Create a transport layer with 2 separate implementations: 创建具有2个单独实现的传输层:

  • one for the REST services directly calling the java classes from the service layer 一种用于REST服务,直接从服务层调用Java类
  • one for the administration, also directly calling the java classes from the service layer 一个用于管理,也直接从服务层调用Java类

If you really want to create maven module, - create one module that bundles the business services classes in a jar - create two modules that bundles the transports implementation in 2 separate jars - create one module that bundles the business services.jar, the two transport implementation.jar and their dependencies in a war 如果您确实要创建Maven模块,请执行以下操作:-创建一个将jar中的业务服务类捆绑在一起的模块-创建两个将Transports实现的捆绑在一起的模块放在2个单独的jar中-创建一个将Business Services.jar捆绑在一起的模块Implementation.jar及其在战争中的依赖关系

HIH HIH

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

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