Announcement Announcement Module
Collapse
No announcement yet.
REST = MVC...really? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • REST = MVC...really?

    Hi,

    This post is for both Spring MVC & Spring Web Services actually.

    I'm a little confused by many posts I found on the Spring Forums while trying to figure whether REST will be part of Spring Web Services or not.
    As Arjen (http://jira.springframework.org/browse/SPR-4419) and others mentioned, it's now part of Spring MVC, in Spring Framework 3.0 M2. I got it.
    The reasons however are still obscure to me and I can't seem to find a direct (and logical) answer/explanation.

    Arjen (and team) made sure Spring Web Services are SOAP agnostic...yet no REST support (or anything else...is that correct?)
    Are we supposed to grab Spring MVC + Spring WS (or Spring WS + any JAX-RS Impl. + Code to hook them up) to provide WSDL and REST support for say the same web services?

    Isn't REST more about web services anyway?
    Here is another way to put it. Which one makes more sense:
    1. Use Spring MVC in my web service project to provide REST support
    2. Use Spring WS in my web site project to provide REST services

    Spring WS also has some nifty security features (based on Spring Sec.) that would be awesome to leverage for REST or at least have something close and somewhat homogeneous.

    Spring WS is really awesome. It would be a shame to have it only as "Spring WSDL/SOAP"
    I hope someone can shine some light on the matter.

    Thanks for your help,
    Luc.

  • #2
    I suggest you read Arjen's blog about the subject.

    Comment


    • #3
      Thanks Tareq.
      That's a great post to use REST with Spring 3.0 indeed.
      However, it doesn't really say "why" it's in MVC. It sounds like it's because it was technically easier or more suitable.

      Here is another way to approach it: in the Spring WS documentation, would it be ok to say "If you want to provide REST web services, go check Spring MVC".
      Sounds messy to me...

      There isn't anything wrong with MVC and I guess Spring WS follows some kind of MVC approach. But then, everything following an MVC approach should not be in Spring MVC, should it?

      Comment


      • #4
        REST implementation in Spring MVC leaves Spring WS "out on a limb"

        Hi there, yes i share your confusions with the current lack of web services support for REST, the (only) way it could really make sense in MVC, (apart from ease of implementation from the spring side) is if this Spring-MVC is intended to provide the 'base' means of implementing RESTful URLs (e.g. for the Application Domain) which is then built-on for the subsequent follow-on Spring-WS (2.0 ?) release which would leverage this in the WS-I WSDL Context (e.g. for the Enterprise domain).

        Does anyone have any insight into if this is just fanciful, or in any way related to future REST support in the Spring Web Services context ?

        Comment


        • #5
          Hello

          It's an interesting dilemma. In my case, I just think that "RESTful web services" are just sophisticated version of some controllers responding to requests with URLs conforming to some conventions. It's more like plain old (...) CGI. It's like "HTTP web services".

          And Spring-WS is about "SOAP/WSDL web services".

          Easy distinction, easy explanation why REST fits more to (core) Spring MVC.

          regards
          Grzegorz Grzybek

          Comment


          • #6
            REST & Web Services are not mutually exclusive ...

            Hi, easy yes, but REST is essentially a set of abstract conventions - technology agnostic - that can of course be implemented many ways...

            From the Spring perspective SpringSource have pitched REST as a feature of the web application as MVC but not Spring-WS - essentially constraining REST to the application level rather than the enterprise level. I remain errr... hopeful ? that any forthcoming Spring-WS release will support RESTful contracts in the (web service) standards-based integration domain. The MVC & Spring servlet based architectures are very similiar so i would think one would leverage the other ?

            How do find out details and dates of an upcoming Spring-WS release ?

            Comment


            • #7
              Is Spring MVC still the only way to implement REST services? It seems we still have to involve ModelAndView. Shouldn't REST support be part of Spring-WS or better yet Spring-RS?

              NB: I am now using the RESTEasy integration with Spring and it is working out very well. I get the benefits of running with Spring and a _real_ JAX-RS implementation in RESTEasy.
              Last edited by pastafarian; Oct 22nd, 2010, 10:42 AM.

              Comment


              • #8
                I recommend to use restlet framework with spring.

                Comment


                • #9
                  MVC is too narrow a domain for REST

                  This discussion covers exactly my own doubts. I have been using Spring MVC to implement several REST services, and deploy those on Jetty, which is very lightweight. Everything works like a charm and Spring makes it really easy to configure the controllers to handle exactly the URI patterns I need. No complaints on that front.

                  But this whole thing ties me up to the servlet world. What if I want to expose those same REST services in order to react to a message I received over JMS? I will have to write an MDB (or use some sort of EAI system such as Camel or Spring Integration) to receive the message and then invoke the REST service over HTTP (for example, using RestTemplate). You must admit this is rather convoluted and inefficient.

                  Wouldn't it make more sense to decouple the whole REST controller architecture from the servlet architecture, so that I could deploy my controllers (or whatever you want to call them) into an MDB, Camel or Spring Integration, and call their functionality directly?

                  Better yet: why can't I write this kind of REST services in Spring WS and benefit from the myriad other capabilities in that framework (such as security)?

                  In short: how can I write a REST service with Spring that is not tied to MVC (but can be also used as an MVC controller), that is 100% SPRINGful (new term there) and can be easily integrated into Camel or Spring Integration?
                  Last edited by gonzus; May 26th, 2011, 01:48 PM. Reason: Added title

                  Comment


                  • #10
                    @gonzus

                    Hi

                    I think you mix different problems here. Rest is tied not to MVC directly, but rather to HTTP. MVC is the best (IMO) HTTP requests handling pattern. The HTTP nature of REST may be expressed in 4 words: GET, POST, UPDATE and DELETE.

                    You want to create some "REST Services" and be able to use them below MVC/HTTP or MDB/JMS/AMQP? There's simple solution - use Java interfaces and their implementation and invoke them as @ServiceActivators in Spring-Integration using HTTP or JMS inbound adapters!

                    There's no such thing as "REST Service" without REST (HTTP) Verbs. Think at different level - at Service Level - whole invocation layer is cleanly implemented in Spring Integration!

                    Also - you've mentioned that Spring-WS gives you security. No, it doesn't. SOAP gives you security (with WS-Security or XML-Security), HTTP gives you security (with HTTPS), JMS gives you security (e.g. with proprietary configuration of ActiveMQ or IBM MQ Series). Spring-WS leverages these mechanism with the help of Spring-Security! "REST Services" with JMS instead of HTTP won't give you HTTPS, X.509 certificates verification or WS-Security!

                    The beauty of Spring is that there's library (framework) for everything. I understand that the most visible (and probably only) confusion is whether REST should be in SpringMVC or SpringWS. My answer is - SpringMVC

                    regards
                    Grzegorz Grzybek

                    Comment


                    • #11
                      Hello Grzegorz,

                      Thanks for your well reasoned answer, it provides a lot of food for my thoughts.

                      Originally posted by Grzegorz Grzybek View Post
                      I think you mix different problems here. Rest is tied not to MVC directly, but rather to HTTP. MVC is the best (IMO) HTTP requests handling pattern. The HTTP nature of REST may be expressed in 4 words: GET, POST, UPDATE and DELETE.
                      Fair enough.

                      Originally posted by Grzegorz Grzybek View Post
                      You want to create some "REST Services" and be able to use them below MVC/HTTP or MDB/JMS/AMQP? There's simple solution - use Java interfaces and their implementation and invoke them as @ServiceActivators in Spring-Integration using HTTP or JMS inbound adapters!
                      Here is the bottom of the matter, and I think you have helped me identify it: what makes me uncomfortable about REST in Spring MVC is that it is tied to the servlet model (via the DispatcherServlet). Let me give you a concrete example.

                      One of the systems I am responsible for is an integration hub that has grown little by little. It started by monitoring certain directories and moving files from one place to another as soon as they appeared, using FTP. Then we moved from plain FTP to a more secure alternative (SFTP or FTPS, I can never remember which one). Then we added JMS integration in order to be able to talk to MQSeries queues. And so on. This was all done with Apache Camel and works very nicely.

                      Down comes the requirement: we want to be able to add a couple of web services into this integration architecture, so that some of the files (records, actually) and messages that circulate around can be specified to call certain services in order to execute business logic along the way. What's that you say? SOAP could be too big a gun to kill this beast? And you propose to go with REST? Fine, we don't care. In fact, we are not sure what you mean by SOAP and REST...

                      Now, in this scenario, and having built some web apps with Spring MVC in the past, I think it would be really great to have the capability to use all the Spring MVC REST goodies at the tip of my hands, with the only difference that this will not be a web app but a service, to be integrated into my bus.

                      How do I go about decoupling DispatcherServlet from Spring MVC and using Spring MVC in my Apache Camel endpoint?

                      Mind you, I know about Spring Integration (but not a lot); at this point I would not consider adding it to my stack, simply because I see no point in having two integration technologies in the same system.

                      Again, I really appreciate your comments, they are very insightful. Thanks and regards.

                      Comment


                      • #12
                        @gonzus

                        I've suggested SpringIntegration because it's Spring Forum. But if you use Apache Camel - great - you have perfect EIP system

                        I don't know Camel, but I know it's built around the same concept of pipes&filters (and adapters/gateways). So a quick look gave me this: http://camel.apache.org/restlet.html. Use that endpoint which may add another gateway to your system

                        regards
                        Grzegorz Grzybek

                        Comment

                        Working...
                        X