简体   繁体   English

RESTful和J2EE

[英]RESTful and J2EE

I have developed a web application with Java EE, which connects to a DB. 我用Java EE开发了一个Web应用程序,该应用程序连接到数据库。 The app is deployed on Tomcat 8. The app is divided in three layers: db layer, business layer, and presentation layer. 该应用程序部署在Tomcat 8上。该应用程序分为三层:数据库层,业务层和表示层。 Now I need to develop a RESTful API that will use the business layer and will provide most of the functions that the presentation layer provides. 现在,我需要开发一个RESTful API,它将使用业务层并提供表示层提供的大多数功能。 Clients will have two options to choose from: open a browser, connect to the APP and use it or consume the RESTful web services from their own software. 客户端将有两个选项可供选择:打开浏览器,连接到APP并使用它或通过其自己的软件使用RESTful Web服务。

My question is: should I deploy the RESTful API on the same server where the APP is deployed or separately? 我的问题是:我应该将RESTful API部署在APP部署所在的同一服务器上还是单独部署? What are your suggestions? 您有什么建议? And, what kind of authentication would you suggest for the REST web services? 而且,您建议对REST Web服务进行哪种身份验证?

Thanks! 谢谢!

It is a rather broad question and the short answer is it depends . 这是一个相当广泛的问题,简短的答案取决于它

Functionnally, you have three parts here: 功能上,您可以分为三个部分:

  • the presentation layer 表示层
  • the API interface API接口
  • the back office : business and db layers behind the 2 first ones 后台 :在前两个后面的业务和数据库层

Common technical architectures are: 常见的技术架构是:

  • one app for the API and business and db layers, one app for the web layer using the API 一个应用程序用于API以及业务和数据库层,一个应用程序用于使用API​​的网络层
  • everything (API, Web and business) on the same application. 同一应用程序上的所有内容(API,Web和业务)。

The former offer a better separation and can be interesting for heavy loaded applications, or if you plan to move to a javascript interface (AngularJS ofr example), the latter will be simpler to implement. 前者提供了更好的分离效果,对于繁重的应用程序可能会很有趣,或者如果您打算转移到javascript接口(AngularJS ofr示例),后者将更易于实现。

For the authentication, it is simpler to pass the credentials along with each request for an API, but you should considere managing it outside the application itself through filters and/or AOP concepts. 对于身份验证,将凭据与对API的每个请求一起传递比较容易,但是您应该考虑通过过滤器和/或AOP概念在应用程序外部对其进行管理。 Spring Security is an example of how this is possible and gives a very loose coupling between the business code and the authentication and authorization ones. Spring Security是实现此目标的一个示例,它在业务代码与身份验证和授权之间提供了非常松散的耦合。 You can then choose and change your authentication methods with little impact on the core of the application. 然后,您可以选择和更改身份验证方法,而对应用程序的核心影响很小。

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

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