简体   繁体   English

REST的Java Web服务架构

[英]Java web service architecture with REST

I am designing a Java web application that will be deployed to the Wildfly or Tomcat (not decided yet). 我正在设计一个Java Web应用程序,该应用程序将部署到Wildfly或Tomcat(尚未确定)。

Basically it's about the offline java application that needs a REST interface for communication (to accept JSON data). 基本上,它是关于需要一个REST接口进行通信(以接受JSON数据)的脱机java应用程序。 The idea is that application runs all the time and processes the requests stored in redis cache (where the received JSON data is stored). 这个想法是应用程序始终运行并处理存储在redis缓存(存储接收到的JSON数据)中的请求。

I used the Spring MVC framework for a web site in the past but I don't need the MVC pattern for the REST interface. 过去,我将Spring MVC框架用于网站,但我不需要REST接口的MVC模式。

Is there a way you can point me to for using a Spring framework (or some other Java framework) to add the capability to recieve a POST requests to the existing offline application ? 有没有一种方法可以指向我使用Spring框架(或某些其他Java框架) 来向现有脱机应用程序添加接收POST请求的功能 Or it will be better to just write the REST service that will use the same cache as the existing application? 还是只编写将使用与现有应用程序相同的缓存的REST服务会更好?

To illustrate my question I am attaching the simplified diagram of the architecture I am looking for: 为了说明我的问题,我附上我正在寻找的体系结构的简化图:

现有的应用程序和扩展

As soon as you speak of receiving a POST request, you are automatically referring to a HTTP server. 谈到收到 POST请求,您将自动引用HTTP服务器。

The question is just whether that server is running as a service, or on-demand. 问题只是该服务器是作为服务运行还是按需运行。

Is there a way you can point me to for using a Spring framework (or some other Java framework) to add the capability to recieve a POST requests to the existing offline application? 有没有一种方法可以指向我使用Spring框架(或其他Java框架)来向现有脱机应用程序添加接收POST请求的功能?

Not without introducing some sort of HTTP container, no. 并非没有引入某种HTTP容器,不。

Or it will be better to just write the REST service that will use the same cache as the existing application? 还是只编写将使用与现有应用程序相同的缓存的REST服务会更好?

Yes, exactly. 对,就是这样。 And as another mentioned, personally I'd stick with Spring MVC. 正如另一个提到的那样,我个人会坚持使用Spring MVC。 But Jersey should also work very well for you for your usecase. 但是Jersey对于您的用例也应该非常适合您。

I think you should use any light ESB, like Camel, Mule or Spring Integration. 我认为您应该使用任何轻型ESB,例如Camel,Mule或Spring Integration。 If you have already worked with Spring probably the latter will be the easiest for you. 如果您已经使用过Spring,那么后者可能对您来说最简单。

The purpose of this kind of apps is to facilitate the task of communicating anything with anything (on this case, an HTTP endpoint with your offline app). 这种应用程序的目的是简化与任何事物进行通信的任务(在这种情况下,是与您的离线应用程序进行HTTP终结点通信)。

Take a look at this: 看看这个:

https://www.google.ie/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=spring%20integration%20http-inbound https://www.google.ie/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=spring%20integration%20http-inbound

You can use Spring MVC for that. 您可以为此使用Spring MVC。

The M odel are your domain classes, the V iew is JSON in this case, and the C ontrollers handle the requests to perform logic operations, business as usual. M odel是您的域类,在这种情况下, V iew是JSON,而C ontroller照常处理请求以执行逻辑操作。

You can also take advantage of Spring's @RestController annotation to quickly create your endpoints, like in this java example: 您还可以利用Spring的@RestController批注来快速创建端点,例如以下Java示例:

@RestController
public class MovieController {

    @Autowired
    private MovieRepository movieRepository;

    @RequestMapping(value = "/movies/{search}", method = RequestMethod.GET)
    public List<Movie> findMovies(@PathVariable String search) {
        return movieRepository.findByName(search);
    }

    @RequestMapping(value = "/movies", method = RequestMethod.POST)
    public void postMovie(@RequestBody Movie movie) {
        movieRepository.save(movie);
    }

}

Answers from Andres, ESala and kervin pointed me to the right direction but the solution I found most suitable was: Andres,ESala和kervin的回答为我指明了正确的方向,但我发现最合适的解决方案是:

  • implementation of REST services using Spring MVC and 使用Spring MVC和REST实现REST服务
  • transformation of the main process from the existing application to the Spring scheduled task . 将主要流程从现有应用程序转换为Spring计划任务

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

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