Thursday, 27 December 2018

struts2 vs rest webservices


Rest Web application
·         Modern web framework
·         Presentation and business logic separation
·         Code not tied to HTTP
Problem: Confusing URIs with struts2
·         GET http://localhost/spaces/addspacenotification.action? key=AJOBS
·         GET http://localhost/spaces/addspacenotification.action? key=AJOBS
·         GET http://localhost/spaces/addspacenotification.action? key=AJOBS
·         GET http://localhost/spaces/addspacenotification.action? key=AJOBS
Problem: Poor caching with struts2
·         HTTP traffic laws broken:
·         GET - Could be anything, including deletes and updates
·         POST - Also could be anything, even regular page views
·         PUT - Not used
·         DELETE - Not used
Struts 2 features:
·         Configurable MVC components, which are stored in struts.xml file. If you want to change anything, you have do it in the xml file.
·         POJO based actions. Struts 2 action class is Plain Old Java Object, which prevents developers to implement any interface or inherit any class.
·         Support for Ajax, which is used to make asynchronous request. It only sends needed field data rather than providing unnecessary information, which at the end improves the performance.
·         Support for integration with Hibernate, Spring, Tiles and so on.
·         Whether you want to use JSP, freemarker, velocity or anything else, you can use different kinds of result types in Struts 2.
·         You can also leverage from various tags like UI tags, Data tags, control tags and more.
·         Brings ample support for theme and template. Struts 2 supports three different kinds of themes including xhtml, simple and css_xhtml.
·         Limited documentation is available for Struts 2. In addition to this, new users find it difficultly to understand its concepts due to poorly managed documentation by Apache.
·          



REST services features:

Rest is an architectural style, which provides direction for building distributed and loosely coupled services, Rest is not linked to any particular platform or technology – It’s an idea to develop services to function similar to the web.
·         Client-server based architecture: Client/server architecture is a computing model in which the server hosts, delivers and manages most of the resources and services to be consumed by the client. This type of architecture has one or more client computers connected to a central server over a network or internet connection. This system shares computing resources.
·         Stateless: This is the most important characteristic of a REST service. A REST HTTP request consists of all the data needed by the server to understand and give back the response. Once a request is served, the server doesn't remember if the request has arrived after a while. So the operation will be a stateless one.
·         Cacheable: Many developers think a technology stack is blocking their web application or API. But in reality, their architecture is the reason. The database can be a potential tuning piece in a web application. In order to scale an application well, we need to cache content and deliver it as a response. If the cache is not valid, it is our responsibility to bust it. REST services should be properly cached for scaling.
·         Multiple layered systems: The REST API can be served from multiple servers. One server can request the other, and so forth. So when a request comes from the client, request and response can be passed between many servers to finally supply a response back to the client. This easily implementable multi-layered system is always a good strategy for keeping the web application loosely coupled.
·         Representation of resources: The REST API provides the uniform interface to talk to. It uses a Uniform Resource Identifier (URI) to map the resources (data). It also has the advantage of requesting a specific data format as the response. The Internet Media Type (MIME type) can tell the server that the requested resource is of that particular type.
·         Implementation freedom: REST is just a mechanism to define your web services. It is an architectural style that can be implemented in multiple ways. Because of this flexibility, you can create REST services in the way you wish to. Until it follows the principles of REST, your server has the freedom to choose the platform or technology. Thoughtful caching is essential for the REST services to scale.
Solution: Humane URIs
·         GET http://localhost/spaces/addspacenotification.action? key=AJOBS
Solution: One API for all




Securing RESTful Web Services
·         DIGEST Authentication
·         Client CERT Authentication
·         OAUTH2 API Keys
·         JWT
·         OWASP
Conclusion:

Rest web services Decouple from view technology and easy to maintain and development whare as Struts2 is a stable and on the other hand Spring MVC/Rest is robust, perfect for application development.

Architecture

Font end use Angular Js

Angular architecture



1 comment:

  1. Very Good Post! Thank you so much for sharing this good post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
    Visit us: Java Online Training Hyderabad
    Visit us: Java Training

    ReplyDelete